// ==UserScript== // @name 必应搜索首页净化 // @namespace BingSearchHomeClean // @version 1.2.7 // @description 必应搜索首页净化,还你一个干净的必应搜索首页,新增可自定义隐藏栏目 // @author Lee // @match *://*.bing.com/* // @exclude /^https?:\/\/.*bing\.com\/.+\?[a-z]+=.+/ // @grant GM_registerMenuCommand // @license GPL-3.0 // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGZpbGw9IiMxNDg2QzkiIGQ9Im0xMC4xMjkgOC41OTZsMS43MzUgNC4zMjhsMi43NyAxLjI5TDE5IDE2LjI0N1YxMS43eiIgb3BhY2l0eT0iLjciLz48cGF0aCBmaWxsPSIjMTQ4NkM5IiBkPSJNMTQuNjM0IDE0LjIxNEw5IDE3LjQ1N1YzLjRMNSAydjE3Ljc2TDkgMjJsMTAtNS43NTNWMTEuN3oiLz48L3N2Zz4= // @downloadURL none // ==/UserScript== (function () { "use strict"; let userSettings = {}; let main = { // 读取用户设置,没有则创建默认设置 getUserSettings() { if (!localStorage.getItem("bingUserSettings")) { localStorage.setItem( "bingUserSettings", JSON.stringify({ hideScrollContainer: true, hideHeader: true, hideMicrophone: true, hideGold: true, hideQrCode: true, hideScrollbar: true, hideInputTip: true, hideHotNewsInput: true, hideMobilePhoneLogo: true, hideQrCodeMobile: true, hideHotNews: true, }) ); } userSettings = JSON.parse(localStorage.getItem("bingUserSettings")); }, // 注册菜单指令 registerMenuCommand() { GM_registerMenuCommand("自定义隐藏栏目", () => { const settingsPanel = document.createElement("div"); settingsPanel.innerHTML = `

选择要隐藏的栏目









`; document.body.appendChild(settingsPanel); document.getElementById("hideScrollContainer").addEventListener("change", (e) => { userSettings.hideScrollContainer = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("hideHeader").addEventListener("change", (e) => { userSettings.hideHeader = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("hideGold").addEventListener("change", (e) => { userSettings.hideGold = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("hideQrCode").addEventListener("change", (e) => { userSettings.hideQrCode = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("hideInputTip").addEventListener("change", (e) => { userSettings.hideInputTip = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("hideHotNewsInput").addEventListener("change", (e) => { userSettings.hideHotNewsInput = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("hideMicrophone").addEventListener("change", (e) => { userSettings.hideMicrophone = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("hideHotNews").addEventListener("change", (e) => { userSettings.hideHotNews = e.target.checked; localStorage.setItem("bingUserSettings", JSON.stringify(userSettings)); this.startBingSearchClean(); }); document.getElementById("close").addEventListener("click", () => { document.body.removeChild(settingsPanel); }); }); }, // 执行净化操作 startMutationObserver() { const observer = new MutationObserver(() => { this.startBingSearchClean(); }); // 开始观察 observer.observe(document.body, { childList: true, subtree: true }); }, startBingSearchClean() { // 发现内容 const container = document.querySelector("#scroll_cont"); if (container) { if (userSettings.hideScrollContainer) { container.style.display = "none"; } else { container.style.display = "revert"; } } // 头部五栏 const header = document.querySelector(".scope_cont"); if (header) { if (userSettings.hideHeader) { header.style.display = "none"; } else { header.style.display = "revert"; } } // 输入框麦克风图标 const microphone = document.querySelector(".mic_cont.icon"); if (microphone) { if (userSettings.hideMicrophone) { microphone.style.display = "none"; } else { microphone.style.display = "inline-block"; } } // 奖杯数 const gold = document.querySelector("#id_rh_w"); if (gold) { if (userSettings.hideGold) { gold.style.display = "none"; } else { gold.style.display = "revert"; } } // 必应app二维码 const qrCode = document.querySelector("#id_qrcode"); if (qrCode) { if (userSettings.hideQrCode) { qrCode.style.display = "none"; } else { qrCode.style.display = "revert"; } } // 隐藏溢出滚动条 const scrollbar = document.documentElement; if (scrollbar && container) { if (userSettings.hideScrollContainer) { scrollbar.style.overflow = "hidden"; } else { scrollbar.style.overflow = "auto"; } } // 输入框内提示 const inputTip = document.querySelector(".sb_form_placeholder"); if (inputTip) { if (userSettings.hideInputTip) { inputTip.style.display = "none"; } else { inputTip.style.display = "revert"; } } // 输入框内今日热点 const hotNewsInput = document.querySelector("#sa_pn_initial"); if (hotNewsInput) { if (userSettings.hideHotNewsInput) { hotNewsInput.style.display = "none"; } else { hotNewsInput.style.display = "revert"; } } // 搜索结果右侧手机端标识 const mobilePhoneLogo = document.querySelector(".id_mobile"); if (mobilePhoneLogo) mobilePhoneLogo.style.display = "none"; // 下载手机端二维码推荐 const qrCodeMobile = document.querySelector("#id_qrcode_popup_container"); if (qrCodeMobile) qrCodeMobile.style.display = "none"; // 今日上的热点 const hotNews = document.querySelector(".below_sbox"); if (hotNews) { if (userSettings.hideHotNews) { hotNews.style.display = "none"; } else { hotNews.style.display = "revert"; } } }, // 初始化 init() { this.getUserSettings(); this.registerMenuCommand(); this.startMutationObserver(); }, }; main.init(); })();