Greasy Fork is available in English.
必应搜索首页净化,还你一个干净的必应搜索首页,新增可自定义隐藏栏目
当前为
// ==UserScript==
// @name 必应搜索首页净化
// @namespace BingSearchHomeClean
// @version 1.2.4
// @description 必应搜索首页净化,还你一个干净的必应搜索首页,新增可自定义隐藏栏目
// @author Lee
// @match *://*.bing.com/*
// @grant GM_registerMenuCommand
// @license GPL-3.0
// @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGZpbGw9IiMxNDg2QzkiIGQ9Im0xMC4xMjkgOC41OTZsMS43MzUgNC4zMjhsMi43NyAxLjI5TDE5IDE2LjI0N1YxMS43eiIgb3BhY2l0eT0iLjciLz48cGF0aCBmaWxsPSIjMTQ4NkM5IiBkPSJNMTQuNjM0IDE0LjIxNEw5IDE3LjQ1N1YzLjRMNSAydjE3Ljc2TDkgMjJsMTAtNS43NTNWMTEuN3oiLz48L3N2Zz4=
// ==/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 = `
<div style="position: fixed; top: 10%; right: 10px; background-color: #fff; border: 1px solid #ccc; padding: 10px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); width: 300px; z-index: 1000;">
<h4>选择要隐藏的栏目</h4>
<label><input type="checkbox" id="hideScrollContainer" ${userSettings.hideScrollContainer ? "checked" : ""}> 隐藏发现内容</label><br>
<label><input type="checkbox" id="hideHeader" ${userSettings.hideHeader ? "checked" : ""}> 隐藏图片/视频等头部五栏</label><br>
<label><input type="checkbox" id="hideGold" ${userSettings.hideGold ? "checked" : ""}> 隐藏奖杯数</label><br>
<label><input type="checkbox" id="hideQrCode" ${userSettings.hideQrCode ? "checked" : ""}> 隐藏二维码</label><br>
<label><input type="checkbox" id="hideInputTip" ${userSettings.hideInputTip ? "checked" : ""}> 隐藏输入框提示</label><br>
<label><input type="checkbox" id="hideHotNewsInput" ${userSettings.hideHotNewsInput ? "checked" : ""}> 隐藏输入框内今日热点</label><br>
<label><input type="checkbox" id="hideMicrophone" ${userSettings.hideMicrophone ? "checked" : ""}> 隐藏输入框麦克风图标</label><br>
<label><input type="checkbox" id="hideHotNews" ${userSettings.hideHotNews ? "checked" : ""}> 隐藏今日热点</label><br>
<button id="close" style="margin-top: 10px; width: 100%;">关闭</button>
</div>
`;
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 = "block";
}
}
// 头部五栏
const header = document.querySelector(".scope_cont");
if (header) {
if (userSettings.hideHeader) {
header.style.display = "none";
} else {
header.style.display = "block";
}
}
// 输入框麦克风图标
const microphone = document.querySelector(".mic_cont.icon");
if (microphone) {
if (userSettings.hideMicrophone) {
microphone.style.display = "none";
} else {
microphone.style.display = "block";
}
}
// 奖杯数
const gold = document.querySelector("#id_rh_w");
if (gold) {
if (userSettings.hideGold) {
gold.style.display = "none";
} else {
gold.style.display = "block";
}
}
// 必应app二维码
const qrCode = document.querySelector("#id_qrcode");
if (qrCode) {
if (userSettings.hideQrCode) {
qrCode.style.display = "none";
} else {
qrCode.style.display = "block";
}
}
// 隐藏溢出滚动条
const scrollbar = document.documentElement;
if (scrollbar) {
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 = "block";
}
}
// 输入框内今日热点
const hotNewsInput = document.querySelector("#sa_pn_block");
if (hotNewsInput) {
if (userSettings.hideHotNewsInput) {
hotNewsInput.style.display = "none";
} else {
hotNewsInput.style.display = "block";
}
}
// 搜索结果右侧手机端标识
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 = "block";
}
}
},
// 初始化
init() {
this.getUserSettings();
this.registerMenuCommand();
this.startMutationObserver();
},
};
main.init();
})();