Toggle Low Heat Posts

切换隐藏/显示热度低于150的帖子,并使按钮更加显眼

目前為 2024-12-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Toggle Low Heat Posts
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  切换隐藏/显示热度低于150的帖子,并使按钮更加显眼
// @author       Your Name
// @match        https://bbs.hupu.com/topic-daily-hot
// @license      LGPL
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let isHidden = false; // 状态变量,初始为未隐藏

    // 创建Toggle按钮并添加到页面右上方
    const toggleButton = document.createElement('button');
    updateButtonText();
    toggleButton.style.position = 'fixed';
    toggleButton.style.top = '20px';
    toggleButton.style.right = '20px';
    toggleButton.style.zIndex = '9999';
    toggleButton.style.padding = '10px 20px';
    toggleButton.style.fontSize = '16px';
    toggleButton.style.backgroundColor = '#1890ff'; // 蓝色背景
    toggleButton.style.color = '#ffffff'; // 白色文字
    toggleButton.style.border = 'none';
    toggleButton.style.borderRadius = '5px';
    toggleButton.style.cursor = 'pointer';
    toggleButton.style.boxShadow = '0 2px 5px rgba(0,0,0,0.3)';
    document.body.appendChild(toggleButton);

    // 添加按钮悬停效果
    toggleButton.addEventListener('mouseenter', function() {
        toggleButton.style.backgroundColor = '#40a9ff'; // 悬停时颜色变深
    });
    toggleButton.addEventListener('mouseleave', function() {
        toggleButton.style.backgroundColor = '#1890ff'; // 恢复原始颜色
    });

    // 更新按钮文本和状态
    function updateButtonText() {
        toggleButton.innerText = isHidden ? 'Show Low Heat Posts' : 'Hide Low Heat Posts';
    }

    // 点击Toggle按钮时执行函数
    toggleButton.addEventListener('click', function() {
        const posts = document.querySelectorAll('.bbs-sl-web-post-body');
        posts.forEach(post => {
            const replyCountText = post.querySelector('.post-datum').innerText.split('/')[0].trim();
            const replyCount = parseInt(replyCountText, 10);
            if (replyCount < 150) {
                post.style.display = isHidden ? '' : 'none'; // 根据状态显示或隐藏
            }
        });
        isHidden = !isHidden; // 切换状态
        updateButtonText(); // 更新按钮文本
    });
})();