Reddit - normalize link score

Normalize link scores according to subreddit subscriber base

  1. // ==UserScript==
  2. // @name Reddit - normalize link score
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.0
  5. // @description Normalize link scores according to subreddit subscriber base
  6. // @author Cáno
  7. // @match https://www.reddit.com/r/*+*/*
  8. // @grant none
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js
  11. // ==/UserScript==
  12.  
  13. (function($) {
  14. 'use strict';
  15.  
  16. var thresholds = {
  17. "PHP": 18,
  18. "AmateurRoomPorn": 90,
  19. "starcraft": 120,
  20. "EmmaWatson": 60,
  21. "ProgrammerHumor": 90
  22. };
  23.  
  24. var threshold = 0;
  25.  
  26. for (var key in thresholds) {
  27. if (thresholds.hasOwnProperty(key)) {
  28. if(window.location.href.indexOf(key) > -1) {
  29. threshold = thresholds[key];
  30. }
  31. }
  32. }
  33.  
  34. $( document ).ready(function () {
  35. var subs = [];
  36.  
  37. $('.subscription-box a.title').each(function() {
  38. subs.push($(this).attr('href'));
  39. });
  40.  
  41. var sum = 0;
  42. var num = 0;
  43.  
  44. var promises = [];
  45.  
  46. console.log(subs);
  47.  
  48. $.each(subs, function() {
  49. var ajax = $.ajax({
  50. url: this + "about.json"
  51. });
  52.  
  53. promises.push(ajax);
  54. });
  55.  
  56. console.log(promises);
  57.  
  58. Promise.all(promises)
  59. .then(responseList => {
  60. console.log(responseList);
  61. var results = [];
  62. $.each(responseList, function () {
  63. var response = this;
  64. var el = $('.score.unvoted');
  65. el.each(function() {
  66. var txt = $(this).parent().parent().find('.entry.unvoted .tagline > a:last-child').text();
  67. if (txt === response.data.display_name_prefixed) {
  68. var result = $(this).attr('title') / response.data.subscribers * 100000;
  69. result = Math.round(result * 10) / 10;
  70. var parent = $(this).parent().parent();
  71. if (!result) {
  72. result = 0.0;
  73. }
  74.  
  75. num++;
  76. sum += result;
  77. results.push(result);
  78. parent.attr('data-score', result);
  79.  
  80. if (result < threshold) {
  81. parent.css('opacity', 0.5).css('filter', 'grayscale(100%)');
  82. $(this).html(result);
  83. } else {
  84. $(this).html(result);
  85. }
  86. }
  87. });
  88. });
  89. // console.log(sum/num);
  90. results = results.sort(function (a, b) { return a - b; }).reverse();
  91. $.each(results, function() {
  92. // console.log(this);
  93. var things = $(".thing[data-score='" + this + "']");
  94. things.each(function() {
  95. var clear = $(this).next();
  96. $(this).insertBefore('#siteTable .nav-buttons');
  97. clear.insertBefore('#siteTable .nav-buttons');
  98. });
  99. });
  100. }).catch(e => {
  101. //console.log(e);
  102. });
  103. })();
  104. })(jQuery);