🏠 Home 

HN scores highlighter

Highlights scores with different colors


Install this script?
  1. // ==UserScript==
  2. // @name HN scores highlighter
  3. // @namespace http://elamperti.com/
  4. // @version 0.1
  5. // @description Highlights scores with different colors
  6. // @author Enrico Lamperti
  7. // @match https://news.ycombinator.com/
  8. // @match https://news.ycombinator.com/news*
  9. // @grant none
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. 'use strict';
  13. var thresholds = [
  14. 20,
  15. 70,
  16. 200,
  17. 500,
  18. 800
  19. ];
  20. var defaultColor = '#CCCCCC';
  21. var colors = [
  22. '#666666', // 20
  23. '#BD9910', // 70
  24. '#EA7C07', // 200
  25. '#FF0000', // 500
  26. '#0000FF', // 800
  27. ];
  28. function parseScore(elem) {
  29. return parseInt(elem.innerHTML.split(" ")[0]);
  30. };
  31. function getColorForScore(score) {
  32. var color = defaultColor;
  33. for (var i=0; i < thresholds.length; i++) {
  34. if (score >= thresholds[i]) {
  35. color = colors[i];
  36. }
  37. }
  38. return color;
  39. }
  40. var items = document.querySelectorAll(".score");
  41. for (var i=0; i < items.length; i++) {
  42. items[i].style.fontWeight = 'bold';
  43. items[i].style.color= getColorForScore(parseScore(items[i]));
  44. }