关于对热门回复的优化/调整建议

因为一些高楼爬起来比较花时间,但又想看看最近发生了些什么,于是就想着能不能对帖子回复进行筛选只显示点赞数/互动数较高的回复

论坛现在已有的热门回复功能只能显示整个帖子点赞数/互动数最多的一百个帖子,对于个别几千层的楼来说不太够用

我一开始是想着让ai写个自动筛的油猴脚本,跟gemini对话了几轮也能用了,但看console会时不时有503,可能是因为刷新新回复太频繁了对网站后端有点压力?
不知道论坛这边有没有办法对热门回复的数量进行调整,或者增加一个仅显示整个帖子内点赞数/互动数高于一定量的回复的功能

gemini写的脚本我也先贴这吧
// ==UserScript==
// @name         bb.zlb.ink 帖子筛选器
// @namespace    bbzlb
// @version      4.0
// @description  依据点赞数筛选帖子回复
// @author       gemini 2.5 pro
// @match        https://bb.zlb.ink/t/topic/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // --- 全局状态变量 ---
    let isFilterActive = false;
    let currentThreshold = 5;

    // --- 核心处理逻辑:根据点赞数决定是否隐藏单个帖子 ---
    function processPost(post, threshold) {
        // 使用 data-post-number 属性来识别帖子,"1" 代表楼主
        const postNumber = post.getAttribute('data-post-number');
        if (postNumber === '1') {
            post.style.display = ''; // 永远显示楼主的帖子
            return;
        }

        const reactionsCounter = post.querySelector('.reactions-counter');
        let likeCount = 0;
        if (reactionsCounter && reactionsCounter.textContent) {
            likeCount = parseInt(reactionsCounter.textContent.trim(), 10) || 0;
        }

        if (likeCount < threshold) {
            post.style.display = 'none';
        } else {
            post.style.display = '';
        }
    }

    // --- UI与事件处理 ---
    function createUI() {
        if (document.getElementById('post-filter-container')) return;

        const container = document.createElement('div');
        container.id = 'post-filter-container';
        container.style.cssText = `
            position: fixed; bottom: 20px; right: 20px;
            background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 8px;
            padding: 10px 15px; z-index: 9999; font-family: Arial, sans-serif;
            font-size: 14px; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        `;
        container.innerHTML = `
            <div style="font-weight: bold; margin-bottom: 8px; text-align: center;">回复筛选 (自动)</div>
            <label for="like-threshold-input">最低点赞数:</label>
            <input type="number" id="like-threshold-input" value="${currentThreshold}" min="0" style="width: 50px; margin-left: 5px; border: 1px solid #ccc; border-radius: 4px; padding: 2px 4px;">
            <br>
            <button id="filter-btn" style="width: 100%; margin-top: 10px; padding: 5px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer;">应用筛选</button>
            <button id="show-all-btn" style="width: 100%; margin-top: 5px; padding: 5px; background-color: #f44336; color: white; border: none; border-radius: 4px; cursor: pointer;">显示全部</button>
        `;
        document.body.appendChild(container);

        document.getElementById('filter-btn').addEventListener('click', applyFilterToPage);
        document.getElementById('show-all-btn').addEventListener('click', showAllPosts);
    }

    function applyFilterToPage() {
        const thresholdInput = document.getElementById('like-threshold-input');
        const newThreshold = parseInt(thresholdInput.value, 10);
        if (isNaN(newThreshold)) { alert('请输入一个有效的数字!'); return; }

        isFilterActive = true;
        currentThreshold = newThreshold;
        console.log(`筛选已激活!当前阈值: ${currentThreshold}`);

        document.querySelectorAll('article.topic-post').forEach(post => {
            processPost(post, currentThreshold);
        });
    }

    function showAllPosts() {
        isFilterActive = false;
        console.log('筛选已关闭,显示所有回复。');
        document.querySelectorAll('article.topic-post').forEach(post => {
            post.style.display = '';
        });
    }

    // --- MutationObserver 监视器设置 ---
    function setupObserver(targetNode) {
        const observerOptions = { childList: true, subtree: false };
        const observer = new MutationObserver((mutationsList) => {
            if (!isFilterActive) return;

            for (const mutation of mutationsList) {
                mutation.addedNodes.forEach(node => {
                    // 检查新添加的节点是否是一个帖子
                    if (node.nodeType === 1 && node.matches('.topic-post')) {
                        console.log('检测到新回复,自动应用筛选...');
                        processPost(node, currentThreshold);
                    }
                });
            }
        });
        observer.observe(targetNode, observerOptions);
        console.log('MutationObserver 已启动,正在监视新回复。监视目标:', targetNode);
    }

    // --- 脚本主入口:轮询检测机制 ---
    function initializeScript() {
        // 不再寻找容器,而是寻找第一个帖子本身
        const postSelector = '.topic-post';
        const initInterval = setInterval(() => {
            const firstPost = document.querySelector(postSelector);

            if (firstPost) {
                // 找到了第一个帖子!
                clearInterval(initInterval);

                // 获取它的父元素作为监视目标
                const postsContainer = firstPost.parentElement;
                console.log(`成功找到帖子并将其父元素作为监视目标!`, postsContainer);

                // 执行脚本核心功能
                createUI();
                setupObserver(postsContainer);

            }
        }, 500); // 每500毫秒检查一次
    }

    // 启动脚本
    initializeScript();

})();
3 个赞