Greasy Fork

移除百度首页推荐

百度首页推荐内容移除

当前为 2025-01-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         移除百度首页推荐
// @version      0.05
// @author       wangws
// @namespace    https://www.acfun.cn/u/955021
// @match        https://www.baidu.com/*
// @match        https://ipv6.baidu.com/*
// @description:zh-cn 百度首页推荐内容移除
// @description 百度首页推荐内容移除
// @license MIT
// ==/UserScript==
function removeElementById(elementId) {
    const element = document.getElementById(elementId);
    if (element) {
        element.remove();
    } else {
        console.warn(`Element with ID "${elementId}" not found.`);
    }
}

function removeElementsByClassName(className) {
    const elements = document.getElementsByClassName(className);
    while (elements.length > 0) {
        elements[0].remove();
    }
}

// 删除搜索框下方热搜
removeElementById('s_new_search_guide');

// 删除搜索框下方热搜(重复代码,可以移除)
// document.getElementsByClassName('new_search_guide_bub').remove();

setTimeout(function () {
    // 点开我的关注
    let mine = document.getElementById('s_menu_mine');
    if (mine) {
        mine.click();
    } else {
        console.warn('Element with ID "s_menu_mine" not found.');
    }

    // 删除搜索框下方热搜
    removeElementById('s-hotsearch-wrapper');

    // 删除推荐tab以及推荐内容
    removeElementsByClassName('s-menu-item');

    // 删除搜索框内新闻
    let kw = document.getElementById('kw');
    if (kw) {
        kw.setAttribute('placeholder', '');
    } else {
        console.warn('Element with ID "kw" not found.');
    }
}, 200);