屏蔽百度搜索页面无用信息

屏蔽百度搜索页面的引导元素,并去除百度首页搜索框自动加载的热搜内容词条,清空 placeholder

目前为 2024-12-31 提交的版本。查看 最新版本

// ==UserScript==
// @name         屏蔽百度搜索页面无用信息
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  屏蔽百度搜索页面的引导元素,并去除百度首页搜索框自动加载的热搜内容词条,清空 placeholder
// @author       sept
// @match        https://www.baidu.com/*
// @grant        none
// @license      MIT
// @icon         https://free4.yunpng.top/2024/12/31/6773ce94671e3.png  // 图标的 URL
// ==/UserScript==

(function() {
    'use strict';

    // 屏蔽百度搜索页面中的 id="s_new_search_guide" 的 div 元素
    window.addEventListener('load', function() {
        var guideElement = document.getElementById('s_new_search_guide');
        if (guideElement) {
            guideElement.style.display = 'none';  // 隐藏元素
        }
    });

    // 获取百度搜索框元素
    var inputElement = document.getElementById('kw'); // 百度搜索框的 ID 是 'kw'

    if (inputElement) {
        // 提前清空 placeholder
        inputElement.placeholder = '';

        // 使用 MutationObserver 监控 placeholder 的变化
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.type === 'attributes' && mutation.attributeName === 'placeholder') {
                    // 如果 placeholder 被动态加载,立即清空
                    inputElement.placeholder = '';
                    observer.disconnect(); // 停止监控,避免重复清空
                }
            });
        });

        // 配置 MutationObserver,监控 placeholder 属性的变化
        var config = {
            attributes: true, // 监控属性变化
            attributeFilter: ['placeholder'] // 只监控 placeholder 属性
        };

        // 开始监控
        observer.observe(inputElement, config);
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址