Guest User

Untitled

a guest
Apr 20th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @description    Highlights comments for Reddit stories based on comment points
  3. // @grant          none
  4. // @match          *://*.reddit.com/*/comments/*
  5. // @name           Reddit Comment Highlighter (Chrome)
  6. // @namespace      http://userscripts.org/scripts/show/120788
  7. // @require        http://code.jquery.com/jquery-latest.min.js
  8. // @version        1.51
  9. // ==/UserScript==
  10.  
  11. /*
  12.     Author: Kilo G
  13.     Updated version of Erik Wannebo's script (http://userscripts.org/scripts/show/84313)
  14.  
  15.  
  16.     Version 1.5
  17.     Added @grant header
  18.     Updated @match header
  19.  
  20.     Version 1.4
  21.     Added HTTPS match
  22.     Updated to use external jQuery
  23.  
  24.     Version 1.3
  25.     Added Reddit Blue color and made it the default
  26.     Updated jQuery to v2.0.2
  27.  
  28.     Version 1.2
  29.     Updated jQuery to v1.7.2
  30. */
  31.  
  32.  
  33. var ChangeFontSize = true; // false is not implemented..
  34.  
  35.  
  36.  
  37. var redditbluethresholds = {.75: '#edf5fc',
  38.         .9: '#d9eafa',
  39.         .95: '#c8e0f7',
  40.         .98: '#b5d5f5'
  41. }
  42.  
  43. var bluethresholds = {.75: '#ddddff',
  44.         .9: '#ccccff',
  45.         .95: '#bbbbff',
  46.         .98: '#aaaaff'
  47. }
  48.  
  49. var greenthresholds = {.75: '#ddf8dd',
  50.         .9: '#bbf8bb',
  51.         .95: '#aaf8aa',
  52.         .98: '#99f899'
  53. }
  54.  
  55. var yellowthresholds = {.75: '#f8f8dd',
  56.         .9: '#f8f8bb',
  57.         .95: '#f8f8aa',
  58.         .98: '#f8f899'
  59. }
  60.  
  61. var prevFontFactor = "";
  62. var fontFactor = 2;
  63. var highlightColor = "redditblue";
  64.  
  65. function highlightComments()
  66. {
  67.     var thresholds = redditbluethresholds;
  68.     if (highlightColor == "blue") thresholds = bluethresholds;
  69.     if (highlightColor == "green") thresholds = greenthresholds;
  70.     if (highlightColor == "yellow") thresholds = yellowthresholds;
  71.     var arRecs = new Array();
  72.     $(".nestedlisting .entry .score.unvoted").each(function()
  73.     {
  74.         var recs = $(this).text().split(' ')[0];
  75.         arRecs.push(parseInt(recs));
  76.     });
  77.     arRecs.sort(function(a, b)
  78.     {
  79.         return a - b;
  80.     });
  81.     $(".nestedlisting .entry .score.unvoted").each(function()
  82.     {
  83.         var recs = $(this).text().split(' ')[0];
  84.         var numrecs = parseInt(recs);
  85.         var newbgcolor = '';
  86.         var newfontsize = 13;
  87.         for (t in thresholds)
  88.             if (numrecs >= arRecs[Math.floor(arRecs.length * t)])
  89.             {
  90.                 newbgcolor = thresholds[t];
  91.                 newfontsize += fontFactor;
  92.             }
  93.             else
  94.             {
  95.                 break;
  96.             }
  97.         if (newbgcolor != '')
  98.         {
  99.             $(this).parents("div.entry").css(
  100.             {
  101.                 backgroundColor: newbgcolor,
  102.                 '-moz-border-radius': '7px',
  103.                 'webkit-border-radius': '7px',
  104.                 'padding': '2px 2px 2px 6px',
  105.                 'border': 'solid black 1px'
  106.             });
  107.             if (fontFactor > 0 || prevFontFactor != "")
  108.             {
  109.                 $(this).parents("div.entry").find(".md").css(
  110.                 {
  111.                     fontSize: newfontsize
  112.                 });
  113.                 $(this).parents('.tagline').css(
  114.                 {
  115.                     fontSize: newfontsize,
  116.                     color: 'black'
  117.                 });
  118.                 $(this).css(
  119.                 {
  120.                     fontSize: newfontsize,
  121.                     color: 'black'
  122.                 });
  123.             }
  124.         }
  125.     });
  126.     //drawHighlightColorSelect();
  127.     //drawFontFactorSelect();
  128. }
  129.  
  130. function changeHighlightColor()
  131. {
  132.     highlightColor = $('#colorselect').val();
  133.     GM_setValue("reddithighlightcommentcolor", highlightColor);
  134.     highlightComments();
  135. }
  136.  
  137. function changeFontFactor()
  138. {
  139.     prevFontFactor = fontFactor;
  140.     fontFactor = parseInt($('#fontfactorselect').val());
  141.     GM_setValue("reddithighlightcommentfontfactor", fontFactor);
  142.     highlightComments();
  143. }
  144.  
  145. function drawHighlightColorSelect()
  146. {
  147.     var colorselect = null;
  148.     $('#colorselect').remove();
  149.     $('#colorselectlabel').remove();
  150.     var selecthtml = "<label id='colorselectlabel' for='colorselect'>Highlight Color:</label><select id='colorselect'>";
  151.     selecthtml += "<option value='redditblue' " + (highlightColor == 'redditblue' ? "selected" : "") + ">reddit blue</option>";
  152.     selecthtml += "<option value='blue' " + (highlightColor == 'blue' ? "selected" : "") + ">blue</option>";
  153.     selecthtml += "<option value='green' " + (highlightColor == 'green' ? "selected" : "") + ">green</option>";
  154.     selecthtml += "<option value='yellow' " + (highlightColor == 'yellow' ? "selected" : "") + ">yellow</option>";
  155.     selecthtml += "</select>";
  156.     colorselect = $(selecthtml).change(function()
  157.     {
  158.         changeHighlightColor()
  159.     });
  160.  
  161.     $('.menuarea').append(colorselect);
  162. }
  163.  
  164. function drawFontFactorSelect()
  165. {
  166.     var fontfactorselect = null;
  167.     $('#fontfactorselect').remove();
  168.     $('#fontfactorselectlabel').remove();
  169.  
  170.     var selecthtml = "<label id='fontfactorselectlabel' for='fontfactorselect'>Font Adjustment:</label><select id='fontfactorselect'>";
  171.     selecthtml += "<option value='0' " + (fontFactor == 0 ? "selected" : "") + ">0</option>";
  172.     selecthtml += "<option value='1' " + (fontFactor == 1 ? "selected" : "") + ">1</option>";
  173.     selecthtml += "<option value='2' " + (fontFactor == 2 ? "selected" : "") + ">2</option>";
  174.     selecthtml += "<option value='3' " + (fontFactor == 3 ? "selected" : "") + ">3</option>";
  175.     selecthtml += "</select>";
  176.     fontfactorselect = $(selecthtml).change(function()
  177.     {
  178.         changeFontFactor()
  179.     });
  180.     $('.menuarea').append(fontfactorselect);
  181. }
  182.  
  183. $.noConflict();
  184. $(function ()
  185. {
  186.     highlightComments();
  187. });
Add Comment
Please, Sign In to add comment