Hacker News Highlight Number of Comments

Highlight the number of comments on each post on Hacker News by making the number bold and a darker color than the surrounding text

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hacker News Highlight Number of Comments
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Highlight the number of comments on each post on Hacker News by making the number bold and a darker color than the surrounding text
// @license      GPL v3.0
// @author       xdpirate
// @match        https://news.ycombinator.com/
// @match        https://news.ycombinator.com/?p*
// @match        https://news.ycombinator.com/news*
// @match        https://news.ycombinator.com/best*
// @match        https://news.ycombinator.com/newest*
// @match        https://news.ycombinator.com/front*
// @match        https://news.ycombinator.com/ask*
// @match        https://news.ycombinator.com/show*
// @icon         https://www.google.com/s2/favicons?domain=ycombinator.com
// @grant        none
// ==/UserScript==

let commentLinks = document.querySelectorAll("td.subtext > span.subline > a[href^=\"item?id\"");
for(let i = 0; i < commentLinks.length; i++) {
    let commentMatch = commentLinks[i].innerHTML.match(/^([0-9]+)/g);
    if(commentMatch) {
        let numComments = commentMatch[0];
        let plural = "";

        if(numComments > 1) {
            plural = "s";
        }

        commentLinks[i].innerHTML = `<span style="font-weight: bold; color: #666;">${numComments}</span> comment${plural}`;
    }
}