屏蔽热搜 - 百度、微博、B站、知乎

去除 屏蔽 百度、微博、B站、知乎等4个平台的热搜热榜

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name 屏蔽热搜 - 百度、微博、B站、知乎
// @namespace NoHotSearch
// @description 去除 屏蔽 百度、微博、B站、知乎等4个平台的热搜热榜
// @match *://*.weibo.com/*
// @match *://*.baidu.com/*
// @match *://*.bilibili.com/*
// @match *://*.zhihu.com/*
// @version 1.1.2
// @run-at document-end
// @license MIT
// ==/UserScript==
//编写水平有限!
document.body.addEventListener("DOMNodeInserted", removeHotSearch, false)
function removeHotSearch(){
    let i
/*========================= 百度热搜 √ =========================*/
    //去除主页热搜
    let baidu_h = document.getElementById("s_xmancard_news_new")
    if(baidu_h != null){
        let hotsearch = baidu_h.getElementsByClassName("hot-news-wrapper")[0]
        if(hotsearch != null)hotsearch.style.display = 'none'
    }
    //去除搜索结果页热搜
    let baidu_s = document.getElementById("con-ceiling-wrapper")
    if(baidu_s != null){
        baidu_s.style.display = 'none'
    }
/*========================= 微博热搜 √ =========================*/
    //去除微博主页和详情页右侧热搜
    let weibo = document.getElementById("__sidebar")
    if(weibo != null){
        let weibo_right = weibo.getElementsByClassName("wbpro-side woo-panel-main woo-panel-top woo-panel-right woo-panel-bottom woo-panel-left Card_wrap_2ibWe Card_bottomGap_2Xjqi")
        for(i = 0; i < weibo_right.length; i++){
            if(weibo_right[i].getElementsByClassName("wbpro-side-card7").length != 0){
                weibo_right[i].style.display = 'none'
                break
            }
        }
    }
    //去除微博搜索结果页右侧热搜
    let weibo_s = document.getElementById("pl_band_index")
    if(weibo_s != null)weibo_s.style.display = 'none'
/*========================= B站热搜 √ =========================*/
    let bilibili = document.getElementById("nav-searchform")
    if(bilibili != null){
        //去除搜索框预写入文字
        bilibili.getElementsByTagName("input")[0].setAttribute("placeholder"," ")
        //去除B站搜索面板热搜
        let trending = document.getElementsByClassName("trending")[0]
        let search_panel = document.getElementsByClassName("search-panel")[0]
        let search_pannel = document.getElementsByClassName("search-pannel")[0]//直播页面
        let search_panel_search_panel_popover = document.getElementsByClassName("search-panel search-panel-popover")[0]//搜索结果页面
        if(search_pannel != null)search_panel = search_pannel
        if(search_panel_search_panel_popover != null)search_panel = search_panel_search_panel_popover
        if(search_panel != null && trending != null)trending.style.display = 'none'
        //去除动态热门话题
        let sticky = document.getElementsByClassName("sticky")[0]
        if(sticky != null)sticky.style.display = 'none'
    }
/*========================= 知乎热搜 √ =========================*/
    let zhihu = document.getElementById("ariaTipText")
    if(zhihu != null){
        //去除搜索框预写入文字
        let placeholder_zhihu = document.getElementById("Popover1-toggle")//主页
        let placeholder2_zhihu = document.getElementById("Popover2-toggle")//question页
        if(placeholder2_zhihu != null)placeholder_zhihu = placeholder2_zhihu
        if(placeholder_zhihu != null)placeholder_zhihu.setAttribute("placeholder"," ")
        //去除搜索面板热搜
        let hotsearch_zhihu_s = document.getElementsByClassName("AutoComplete-group")[0]
        if( hotsearch_zhihu_s != null){
            if(hotsearch_zhihu_s.firstChild.innerHTML == '搜索发现')hotsearch_zhihu_s.style.display = 'none'
            else hotsearch_zhihu_s.style.display = ''
        }
        //去除主页热榜
        let topstory_hot_middle = document.getElementsByClassName("TopstoryTabs-link Topstory-tabsLink")[2]
        if(topstory_hot_middle != null && topstory_hot_middle.getAttribute("aria-controls") == 'Topstory-hot')topstory_hot_middle.style.display = 'none'
        let topStory_hot_top = document.getElementsByClassName("TopstoryTabs TopstoryPageHeader-tabs")[0]
        if(topStory_hot_top != null && topStory_hot_top.childNodes[2].getAttribute("aria-controls") == 'Topstory-hot')topStory_hot_top.childNodes[2].style.display = 'none'
        //去除搜索结果页右侧热搜
        let search = document.getElementsByClassName("Card TopSearch TopSearch--new")[0]
        if(search != null)search.style.display = 'none'
    }
}
/*
2023-1-3 13:44: - 2023-1-4 23:55:
屏蔽网页元素的方法
1. 利用 style="display:none;" 隐藏元素
2. 利用.setAttribute(“属性名称”,“修改后的属性值”)修改属性值的方式(主要用于屏蔽搜索框预写入文字)
3. 利用parenttElement.removeChild(childtElement)移除指定元素
4. 利用.innerHTML = ""将元素的所有子级元素清空
5. 利用.remove()直接移除元素
由于用(3)(4)(5)直接移除元素会导致各种问题(莫名其妙的报错,屏蔽元素后面的所有元素都被隐藏,或引起指定场景下莫名其妙的元素消失)
但是(1)不但没有这些问题,而且就算开着脚本也不影响调试,因此利用(1)隐藏元素的方式最为温柔,稳定性最高


常用元素定位方法

.getElementById("")
.getElementsByClassName("")
.getElementsByTagName("")

.parentElement  ——获取父级元素
.parentNode  ——获取父级节点
.childNodes  ——获取子级节点
.firstChild  ——获取首个子节点
.lastChild  ——获取末尾子节点


常用方法
.style.display = 'none'  ——隐藏元素
.setAttribute("属性名","属性值")  ——设置元素属性值 <div 属性名=“属性值”></div>
.getAttribute('属性名')  ——根据属性名获取属性值
.innerHTML  ——获取或修改元素值 <div>元素值</div>
*/