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.1
// @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() {
        // 获取帖子列表的容器元素
        var postListContainer = document.querySelector('.bbs-sl-web-post');
        if (!postListContainer) {
            console.error('Post list container not found!');
            return;
        }

        // 获取所有的帖子条目
        var postItems = postListContainer.querySelectorAll('li.bbs-sl-web-post-body');

        postItems.forEach(function(postItem) {
            // 获取“回复/浏览”元素
            var replyBrowseElem = postItem.querySelector('.post-datum');
            if (!replyBrowseElem) {
                console.error('Reply/browse element not found in post item!', postItem);
                return;
            }

            // 获取回复数和浏览数(假设格式是“回复数 / 浏览数”)
            var replyBrowseText = replyBrowseElem.textContent.trim();
            var replyCountMatch = replyBrowseText.match(/^(\d+)\s*\//);
            if (!replyCountMatch) {
                console.error('Failed to parse reply count from text:', replyBrowseText);
                return;
            }

            var replyCount = parseInt(replyCountMatch[1], 10);

            // 创建新的“回复”元素
            var newReplyElem = document.createElement('div');
            newReplyElem.textContent = '回复: ' + replyCount;
            newReplyElem.className = 'custom-reply-count'; // 添加类名以便后续样式调整

            // 根据回复数设置样式
            if (replyCount > 100) {
                newReplyElem.style.fontSize = '1.2em'; // 加大字号
            }
            if (replyCount > 150) {
                newReplyElem.style.fontWeight = 'bold'; // 加粗显示
            }

            // 将新元素插入到标题前(需要找到标题的父容器)
            var postTitleContainer = postItem.querySelector('.post-title').parentNode;
            if (postTitleContainer) {
                postTitleContainer.insertBefore(newReplyElem, postTitleContainer.querySelector('.post-title'));
            } else {
                console.error('Post title container not found in post item!', postItem);
            }
        });
    });
})();