Modify Hupu Forum Post List Reply Display

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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