Hacker News Threshold

Allows you to highlight threads on Hacker News which have a number of points greater than a specified threshold

As of 2014-09-17. See the latest version.

  1. // ==UserScript==
  2. // @name Hacker News Threshold
  3. // @namespace HackerNewsThreshold
  4. // @description Allows you to highlight threads on Hacker News which have a number of points greater than a specified threshold
  5. // @include *://news.ycombinator.com/*
  6. // @version 0.1
  7. // ==/UserScript==
  8. var init = function() {
  9. function addThreshold(){
  10. $("head").append("<style>.hnth{background: #FFFB93 !important;}.hnterr{background:#FF0000;color:#fff;}</style>");
  11.  
  12. function highlightThreads(threshold){
  13. var $hnfti = $("#hnfti");
  14. if(!isNaN(threshold)){
  15. $hnfti.removeClass("hnterr");
  16. $(".hnth").removeClass("hnth");
  17. $("span[id^='score_']").filter(function(){
  18. var m = $(this).html().match(/[0-9]+/g);
  19.  
  20. if(m){
  21. return parseInt(threshold) <= parseInt(m[0]);
  22. }
  23. else{
  24. return false;
  25. }
  26. })
  27. .closest("tr").prev().addClass("hnth");
  28. }
  29. else{
  30. $(".hnth").removeClass("hnth");
  31. $hnfti.addClass("hnterr");
  32. }
  33. }
  34.  
  35. $("#hnfti").live("keyup", function(){
  36. highlightThreads($(this).val());
  37. });
  38.  
  39. var startthreshold = 100;
  40.  
  41. $($(".pagetop")[0]).append(" | Threshold: <input type='text' id='hnfti' value='"+startthreshold+"' />");
  42.  
  43. highlightThreads(startthreshold);
  44. };
  45.  
  46. (function(fn) {
  47. var script = document.createElement('script');
  48. script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js';
  49. script.addEventListener('load', function() {
  50. var script = document.createElement('script');
  51. script.textContent = 'jQuery.noConflict();(function($){(' + fn.toString() + ')();})(jQuery);';
  52. document.body.appendChild(script);
  53. }, false);
  54. document.body.appendChild(script);
  55. })(init);