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. } else {
  23. return false;
  24. }
  25. }).closest("tr").prev().addClass("hnth");
  26. } else {
  27. $(".hnth").removeClass("hnth");
  28. $hnfti.addClass("hnterr");
  29. }
  30. }
  31.  
  32. $("#hnfti").live("keyup",
  33. function() {
  34. highlightThreads($(this).val());
  35. });
  36.  
  37. var startthreshold = 100;
  38.  
  39. $($(".pagetop")[0]).append(" | Threshold: <input type='text' id='hnfti' value='" + startthreshold + "' />");
  40.  
  41. highlightThreads(startthreshold);
  42. }
  43.  
  44. (function(fn) {
  45. var script = document.createElement('script');
  46. script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js';
  47. script.addEventListener('load',
  48. function() {
  49. var script = document.createElement('script');
  50. script.textContent = 'jQuery.noConflict();(function($){(' + fn.toString() + ')();})(jQuery);';
  51. document.body.appendChild(script);
  52. },
  53. false);
  54. document.body.appendChild(script);
  55. })(init);