Hacker News Points & Comments Highlighter

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Hacker News Points & Comments Highlighter
// @namespace    http://tampermonkey.net/
// @icon         https://news.ycombinator.com/favicon.ico
// @version      0.1.1
// @description  Highlight points and comments on Hacker News with different colors based on their values
// @author       RoCry
// @match        https://news.ycombinator.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Color functions
    function getPointsColor(points) {
        if (points >= 500) return '#FF4500';      // Bright red-orange
        if (points >= 250) return '#FF6B21';      // Orange
        if (points >= 100) return '#FF8C42';      // Light orange
        if (points >= 50)  return '#FFA563';      // Pale orange
        return '#FFB584';                         // Very pale orange
    }

    function getCommentsColor(comments) {
        if (comments >= 300) return '#1E88E5';    // Bright blue
        if (comments >= 200) return '#42A5F5';    // Blue
        if (comments >= 100) return '#64B5F6';    // Light blue
        if (comments >= 50)  return '#90CAF9';    // Pale blue
        return '#BBDEFB';                         // Very pale blue
    }

    // Highlight points
    document.querySelectorAll('.score').forEach(score => {
        const points = parseInt(score.innerText);
        if (!isNaN(points)) {
            score.style.color = getPointsColor(points);
            score.style.fontWeight = 'bold';
        }
    });

    // Highlight comments
    document.querySelectorAll('a').forEach(link => {
        if (link.href.includes('item?id=') && link.innerText.includes('comment')) {
            const comments = parseInt(link.innerText);
            if (!isNaN(comments)) {
                link.style.color = getCommentsColor(comments);
                link.style.fontWeight = 'bold';
            }
        }
    });
})();