Greasy Fork

Greasy Fork is available in English.

去你的热搜 - 移除H5版微博的热搜显示

移除H5版微博的热搜显示

当前为 2024-05-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         去你的热搜 - 移除H5版微博的热搜显示
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  移除H5版微博的热搜显示
// @author       You
// @match        https://m.weibo.cn/*
// @grant        none
// @license      WTFPL
// ==/UserScript==

(function() {
    'use strict';

    // 函数:根据特定父类名更改特定子类名元素的文本内容
    function changeTextByParentAndChild(parentClass, childClass, newText) {
        let parents = document.getElementsByClassName(parentClass);
        for (let parent of parents) {
            let childElements = parent.getElementsByClassName(childClass);
            for (let childElement of childElements) {
                childElement.textContent = newText;
            }
        }
    }

    // 函数:根据特定父类名更改输入元素的占位符
    function changePlaceholderByParent(parentClass, newPlaceholder) {
        let parents = document.getElementsByClassName(parentClass);
        for (let parent of parents) {
            let inputElements = parent.getElementsByTagName('input');
            for (let inputElement of inputElements) {
                if (inputElement.getAttribute('type') === 'search') {
                    inputElement.setAttribute('placeholder', newPlaceholder);
                }
            }
        }
    }

    // 函数:移除具有特定类名的元素
    function removeElementsByClass(className) {
        let elements = document.getElementsByClassName(className);
        while (elements.length > 0) {
            elements[0].parentNode.removeChild(elements[0]);
        }
    }

    // 创建一个MutationObserver来监视DOM中的变化
    let observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            // 检查添加的节点中是否包含具有指定父类和子类名的元素
            let addedNodes = mutation.addedNodes;
            for (let node of addedNodes) {
                if (node.getElementsByClassName) {
                    let parents = node.getElementsByClassName('nav-search');
                    for (let parent of parents) {
                        changeTextByParentAndChild('nav-search', 'm-text-cut', '微博搜索');
                    }

                    changePlaceholderByParent('nt-search', '微博搜索');

                    if (document.querySelector('.nt-search')) {
                        removeElementsByClass('card16');
                    }
                }
            }
        });
    });

    // 开始观察文档的变化
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();