Hacker News Points & Comments Highlighter

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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';
            }
        }
    });
})();