Hacker News Points & Comments Highlighter

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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';
            }
        }
    });
})();