谷歌百度搜狗神马必应搜索去广告,适配电脑和手机
当前为
// ==UserScript==
// @name 搜索引擎去广告
// @author 酷安@耗子Sky
// @description 谷歌百度搜狗神马必应搜索去广告,适配电脑和手机
// @version 9
// @match *://www.google.ca/*
// @match *://www.google.co.jp/*
// @match *://www.google.com.hk/*
// @match *://www.google.com/*
// @match *://m.baidu.com/*
// @match *://www.baidu.com/*
// @match *://m.sm.cn/*
// @match *://yz.m.sm.cn/*
// @match *://wap.sogou.com/*
// @match *://www.sogou.com/*
// @match *://cn.bing.com/*
// @match *://www.bing.com/*
// @run-at document-start
// @namespace https://gf.qytechs.cn/users/452911
// ==/UserScript==
(function () {
//百度执行
if (location.hostname.indexOf("baidu") < 0) return;
// 后续代码
(function(){
function remove(sel) {
document.querySelectorAll(sel).forEach( a => a.remove());
}
var g_times = 0;
function myfun() {
function removeads() {
remove(".ec_wise_ad");
remove(".se-recommend-word-list-container");
remove("#se-recommend-word-list-container");
remove('[class*="ball-wrapper"]');
remove('[style="position: fixed; bottom: 0px; left: 0px; z-index: 300; width: 100%; height: 52px; background: rgb(255, 255, 255); opacity: 1; border-top: 1px solid rgb(224, 224, 224); display: flex;"]');
remove('[ad_dot_url*="http"]');
remove(".dl-banner-without-logo");
remove(".ad_result");
remove(".ad_sc");
remove('[data-text-ad="1"]');
remove('#content_left > *:not([id]) *');
remove('[class="result c-container new-pmd"][id="1"][tpl="se_com_default"][data-click="{"]');
}
removeads();
window.setTimeout(removeads);
if(g_times >= 9999) {
window.clearInterval(timer);
}
g_times ++;
}
var timer = setInterval(myfun,150);
myfun();
})();
})();
//规则转换
(function () {
let rules = `
! 没有两个 # 的行会忽略
baidu.com##.ec_wise_ad
##.se-recommend-word-list-container
###se-recommend-word-list-container
##[class*="ball-wrapper"]
##[style="position: fixed; bottom: 0px; left: 0px; z-index: 300; width: 100%; height: 52px; background: rgb(255, 255, 255); opacity: 1; border-top: 1px solid rgb(224, 224, 224); display: flex;"]
##[ad_dot_url*="http"]
##.dl-banner-without-logo
##.ad_result
##.ad_sc
##[data-text-ad="1"]
###content_left > *:not([id]) *
##[class="result c-container new-pmd"][id="1"][tpl="se_com_default"][data-click="{"]
##.biz_sponsor
##.b_algospacing
##div.b_caption > p[class]
##[onmousedown*="ad"][h*="Ads"]
##LI.b_ad.b_adTop
##[href^='http://yz.m.sm.cn/adclick']
! :remove() 会用 js 移除元素,:remove() 必须放在行尾
域名###ad:remove()
! :click() 会用 js 模拟点击元素,必须放在行尾
域名###btn:click()
`,
rulearray = rules.split("\n"),
selarray = [];
function click(sel) {
document.querySelectorAll(sel).forEach((a) => a.click());
}
function remove(sel) {
document.querySelectorAll(sel).forEach((a) => a.remove());
}
function parseFunc(sel) {
if (sel.indexOf(":remove()") > 0) {
selarray.push({ sel: sel.slice(0, -9), type: 1 });
} else if (sel.indexOf(":click()") > 0) {
selarray.push({ sel: sel.slice(0, -8), type: 2 });
} else {
selarray.push({ sel: sel, type: 0 });
}
}
let styelem = document.createElement("style");
rulearray.forEach((rule) => {
if (rule.indexOf("##") > 0) {
let domains = rule.split("##")[0].split(","),
selector = rule.split("##")[1];
domains.forEach((domain) => {
if (domain.slice(0, 1) == "~") {
if (location.hostname.indexOf(domain.slice(1)) >= 0) return;
} else {
if (location.hostname.indexOf(domain) < 0) return;
}
parseFunc(selector);
});
} else if (rule.indexOf("##") == 0) parseFunc(rule.slice(2));
});
var g_times = 0,
csel = "";
function myfun() {
document.documentElement.appendChild(styelem);
function removeads() {
csel = "";
selarray.forEach((selo) => {
switch (selo.type) {
case 0:
csel += `,${selo.sel}`;
break;
case 1:
remove(selo.sel);
break;
case 2:
click(selo.sel);
break;
}
});
if (csel.length >= 2)
styelem.textContent = csel.slice(1) + " {display: none !important;};";
}
window.setTimeout(removeads);
if (g_times >= 1) {
window.clearInterval(timer);
}
g_times++;
}
var timer = setInterval(myfun, 500);
myfun();
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址