Reddit submission votes

Restores the old upvote/downvote count for submissions.

  1. // ==UserScript==
  2. // @name Reddit submission votes
  3. // @namespace Redditvotes
  4. // @include *reddit.com*
  5. // @exclude *adzerk.net*
  6. // @version 1
  7. // @grant none
  8. // @description Restores the old upvote/downvote count for submissions.
  9. // ==/UserScript==
  10.  
  11. var votepoints = $(".linkinfo > .score > .number").text();
  12. var likepercent = $(".linkinfo > .score").text();
  13. var url = $(location).attr('href');
  14. var votepoints2 = +votepoints.replace(',', '')
  15.  
  16. //alert(url + ", " + votepoints + ", " + likepercent);
  17.  
  18. var percentstring = likepercent.substr(likepercent.indexOf("(") + 1);
  19.  
  20. var percent = percentstring.substr(0, percentstring.indexOf("%"));
  21.  
  22. var downpercent = 100 - percent;
  23.  
  24. var totalvotes = (votepoints2 / (percent - downpercent)) * 100;
  25.  
  26. var upvotes = Math.round((totalvotes / 100) * percent);
  27.  
  28. var downvotes = Math.round((totalvotes / 100) * downpercent);
  29.  
  30. //alert("percent: " + percent + ", downpercent " + downpercent + ", totalvotes: " + totalvotes + ", upvotes: " + upvotes + ", downvotes: " + downvotes);
  31.  
  32. $.fn.digits = function(){
  33. return this.each(function(){
  34. $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
  35. })
  36. }
  37.  
  38. $("head").append("<style>.linkinfo .upvotes {color: orangered; font-size: 80%;} .linkinfo .downvotes {color: #5F99CF; font-size: 80%;}</style>");
  39. if (votepoints2 > 0) {
  40. $(".linkinfo > .score").replaceWith("<div class=\"score\"><span class=\"number\">" + votepoints + "</span><span class=\"word\"> points</span> (" + percent + "% like it)</div><span class=\"upvotes\"><span class=\"number\">" + upvotes + "</span><span class=\"word\"> upvotes</span></span> <span class=\"downvotes\"><span class=\"number\">" + downvotes + "</span><span class=\"word\"> downvotes</span></span>");
  41. } else {
  42. $(".linkinfo > .score").replaceWith("<div class=\"score\"><span class=\"number\">" + votepoints + "</span><span class=\"word\"> points</span> (" + percent + "% like it)</div><span class=\"upvotes\"><span class=\"number\">?</span><span class=\"word\"> upvotes</span></span> <span class=\"downvotes\"><span class=\"number\">?</span><span class=\"word\"> downvotes</span></span>");
  43. }
  44.  
  45. $(".number").digits();