Greasy Fork

Greasy Fork is available in English.

Modify Hupu Forum Post List Reply Display

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

目前为 2024-12-26 提交的版本,查看 最新版本

// ==UserScript==
// @name         Modify Hupu Forum Post List Reply Display
// @namespace    http://tampermonkey.net/
// @version      0.2
// @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');

        postItems.forEach(item => {
            // 获取回复/浏览元素
            const datumElem = item.querySelector('.post-datum');
            if (!datumElem) return;

            // 提取回复数和浏览数
            const datumText = datumElem.textContent.trim();
            const parts = datumText.split(/\s*\/\s*/);
            if (parts.length < 2) return;

            const replyCount = parseInt(parts[0], 10);
            if (isNaN(replyCount)) return;

            // 获取标题链接元素
            const titleLink = item.querySelector('.post-title a.p-title');
            if (!titleLink) return;

            // 创建回复数span
            const replySpan = document.createElement('span');
            replySpan.textContent = `[${replyCount}]   `;
            replySpan.style.marginRight = '5px';

            // 根据回复数调整样式
            if (replyCount > 150) {
                replySpan.style.fontWeight = 'bold';
                replySpan.style.fontSize = '1.2em';
            } else if (replyCount > 80) {
                replySpan.style.fontSize = '1.1em';
            }

            // 插入回复数到标题前
            titleLink.parentNode.insertBefore(replySpan, titleLink);
        });
    });
})();