Hacker News Points & Comments Highlighter

Highlight points and comments on Hacker News with different colors based on their values

  1. // ==UserScript==
  2. // @name Hacker News Points & Comments Highlighter
  3. // @namespace http://tampermonkey.net/
  4. // @icon https://news.ycombinator.com/favicon.ico
  5. // @version 0.1.1
  6. // @description Highlight points and comments on Hacker News with different colors based on their values
  7. // @author RoCry
  8. // @match https://news.ycombinator.com/*
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Color functions
  17. function getPointsColor(points) {
  18. if (points >= 500) return '#FF4500'; // Bright red-orange
  19. if (points >= 250) return '#FF6B21'; // Orange
  20. if (points >= 100) return '#FF8C42'; // Light orange
  21. if (points >= 50) return '#FFA563'; // Pale orange
  22. return '#FFB584'; // Very pale orange
  23. }
  24.  
  25. function getCommentsColor(comments) {
  26. if (comments >= 300) return '#1E88E5'; // Bright blue
  27. if (comments >= 200) return '#42A5F5'; // Blue
  28. if (comments >= 100) return '#64B5F6'; // Light blue
  29. if (comments >= 50) return '#90CAF9'; // Pale blue
  30. return '#BBDEFB'; // Very pale blue
  31. }
  32.  
  33. // Highlight points
  34. document.querySelectorAll('.score').forEach(score => {
  35. const points = parseInt(score.innerText);
  36. if (!isNaN(points)) {
  37. score.style.color = getPointsColor(points);
  38. score.style.fontWeight = 'bold';
  39. }
  40. });
  41.  
  42. // Highlight comments
  43. document.querySelectorAll('a').forEach(link => {
  44. if (link.href.includes('item?id=') && link.innerText.includes('comment')) {
  45. const comments = parseInt(link.innerText);
  46. if (!isNaN(comments)) {
  47. link.style.color = getCommentsColor(comments);
  48. link.style.fontWeight = 'bold';
  49. }
  50. }
  51. });
  52. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址