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 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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