Modify Hupu Forum Post List Reply Display

Add reply count before post title on Hupu forum post list, styled based on count.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Modify Hupu Forum Post List Reply Display
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Add reply count before post title on Hupu forum post list, styled based on count.
// @author       ieagles
// @license      LGPL
// @match        https://bbs.hupu.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        const postItems = document.querySelectorAll('.bbs-sl-web-post-body .post-datum');

        postItems.forEach(function(item) {
            const replyViewText = item.textContent.trim();
            if (replyViewText) {
                const match = replyViewText.match(/^(\d+)\s*\/\s*(\d+)$/);
                if (match) {
                    const replyCount = parseInt(match[1], 10);
                    const titleElement = item.closest('.bbs-sl-web-post-body')
                                            .querySelector('.post-title a');

                    if (titleElement) {
                        const replySpan = document.createElement('span');
                        replySpan.innerHTML = `[${replyCount}]  `; // 使用  

                        if (replyCount > 139) {
                            replySpan.style.color = 'red';
                            replySpan.style.fontWeight = 'bold';
                            replySpan.style.fontSize = '1.2em';
                        } else if (replyCount > 79) {
                            replySpan.style.fontWeight = 'bold';
                            replySpan.style.fontSize = '1.1em';
                        } else {
                            replySpan.style.fontSize = '1em';
                        }

                        titleElement.parentNode.insertBefore(replySpan, titleElement);
                    }
                }
            }
        });
    });
})();