diff --git a/js/common.js b/js/common.js index 9f2f7aa..620f5d3 100644 --- a/js/common.js +++ b/js/common.js @@ -500,7 +500,7 @@ RedditAPI.prototype.voteUpPost = function (e) { listItem.setAttribute('data-score', scoreWas + 2); oldCache.posts[fullName].data.score = scoreWas + 2; scoreElem.innerHTML = scoreWas + 2; - scoreElem.setAttribute('title', chrome.i18n.getMessage('score', [(upsWas + 2).toString(), (downsWas - 1).toString()])); + scoreElem.setAttribute('title', chrome.i18n.getMessage('score', [(upsWas + 1).toString(), (downsWas - 1).toString()])); listItem.setAttribute('data-ups', upsWas + 1); oldCache.posts[fullName].data.ups = upsWas + 1; @@ -546,18 +546,50 @@ RedditAPI.prototype.voteUpPost = function (e) { * @method */ RedditAPI.prototype.voteDownPost = function (e) { - var listItem, fullName, url, reqUrl, oldCache, voteWas, formData; + var listItem, fullName, url, reqUrl, oldCache, voteWas, scoreWas, upsWas, downsWas, scoreElem, formData; function success () { if (voteWas === '1') { + listItem.setAttribute('data-dir','-1'); oldCache.posts[fullName].data.likes = false; + + listItem.setAttribute('data-score', scoreWas - 2); + oldCache.posts[fullName].data.score = scoreWas - 2; + scoreElem.innerHTML = scoreWas - 2; + scoreElem.setAttribute('title', chrome.i18n.getMessage('score', [(upsWas - 1).toString(), (downsWas + 2).toString()])); + + listItem.setAttribute('data-ups', upsWas - 1); + oldCache.posts[fullName].data.ups = upsWas - 1; + + listItem.setAttribute('data-downs', downsWas + 1); + oldCache.posts[fullName].data.downs = downsWas + 1; + } else if (voteWas === '0') { + listItem.setAttribute('data-dir','-1'); oldCache.posts[fullName].data.likes = false; + + listItem.setAttribute('data-score', scoreWas - 1); + oldCache.posts[fullName].data.score = scoreWas - 1; + scoreElem.innerHTML = scoreWas - 1; + scoreElem.setAttribute('title', chrome.i18n.getMessage('score', [upsWas.toString(), (downsWas + 1).toString()])); + + listItem.setAttribute('data-downs', downsWas + 1); + oldCache.posts[fullName].data.downs = downsWas + 1; + } else if (voteWas === '-1') { listItem.setAttribute('data-dir','0'); oldCache.posts[fullName].data.likes = null; + + listItem.setAttribute('data-score', scoreWas + 1); + oldCache.posts[fullName].data.score = scoreWas + 1; + scoreElem.innerHTML = scoreWas + 1; + scoreElem.setAttribute('title', chrome.i18n.getMessage('score', [upsWas.toString(), (downsWas - 1).toString()])); + + listItem.setAttribute('data-downs', downsWas - 1); + oldCache.posts[fullName].data.downs = downsWas - 1; + } cache.set(url, oldCache); @@ -566,6 +598,10 @@ RedditAPI.prototype.voteDownPost = function (e) { listItem = e.srcElement.parentNode.parentNode; fullName = listItem.id; voteWas = listItem.getAttribute('data-dir'); + scoreWas = listItem.getAttribute('data-score'); + upsWas = listItem.getAttribute('data-ups'); + downsWas = listItem.getAttribute('data-downs'); + scoreElem = listItem.getElementById('count_' + listItem.id); url = listItem.parentNode.getAttribute('data-url'); reqUrl = 'http://' + this.domain + '/api/vote?app=mh'; oldCache = cache.get(url);