Greasy Fork

来自缓存

Greasy Fork is available in English.

移除微博热搜

隐藏网页微博上的热搜栏

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         移除微博热搜
// @namespace    https://github.com/SIXiaolong1117/Rules
// @version      0.2
// @description  隐藏网页微博上的热搜栏
// @license      MIT
// @icon         https://weibo.com/favicon.ico
// @author       SI Xiaolong
// @match        https://weibo.com/*
// @match        https://*.weibo.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 在文档加载前就注入 CSS,确保元素一开始就不会显示
    const css = `
        .hotBand {
            display: none !important;
            visibility: hidden !important;
            opacity: 0 !important;
            height: 0 !important;
            width: 0 !important;
            margin: 0 !important;
            padding: 0 !important;
            pointer-events: none !important;
            position: absolute !important;
            left: -9999px !important;
            top: -9999px !important;
        }
    `;
    const style = document.createElement('style');
    style.textContent = css;
    document.head.appendChild(style);

    // 使用 MutationObserver 在元素添加到 DOM 时立即处理
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList') {
                // 检查新添加的节点
                mutation.addedNodes.forEach(function(node) {
                    if (node.nodeType === 1) { // 元素节点
                        // 检查当前节点
                        if (node.classList && node.classList.contains('hotBand')) {
                            hideElement(node);
                        }
                        // 检查子节点
                        const hotBandElements = node.querySelectorAll?.('.hotBand') || [];
                        hotBandElements.forEach(hideElement);
                    }
                });
            }
        });
    });

    // 彻底隐藏元素的函数
    function hideElement(element) {
        element.style.display = 'none';
        element.style.visibility = 'hidden';
        element.style.opacity = '0';
        element.style.height = '0';
        element.style.width = '0';
        element.style.margin = '0';
        element.style.padding = '0';
        element.style.pointerEvents = 'none';
        element.style.position = 'absolute';
        element.style.left = '-9999px';
        element.style.top = '-9999px';
        
        // 尝试从父元素中移除(更彻底)
        if (element.parentNode) {
            setTimeout(() => {
                if (element.parentNode) {
                    element.parentNode.removeChild(element);
                }
            }, 0);
        }
    }

    // 开始观察整个文档
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });

    // 定时检查兜底,处理特殊情况
    setInterval(() => {
        const hotBandElements = document.querySelectorAll('.hotBand');
        hotBandElements.forEach(hideElement);
    }, 1000);

    // 页面加载完成后也执行一次
    window.addEventListener('DOMContentLoaded', () => {
        const hotBandElements = document.querySelectorAll('.hotBand');
        hotBandElements.forEach(hideElement);
    });

    console.log('[Tampermonkey] 移除微博热搜 已加载');
})();