mirror of
https://gitee.com/bitdance-team/chrome-extension
synced 2025-01-27 13:40:26 +08:00
从源头屏蔽Google广告加载
This commit is contained in:
parent
b175506ab3
commit
39a4721dda
@ -0,0 +1,20 @@
|
|||||||
|
// refer: https://www.it1352.com/1996113.html
|
||||||
|
chrome.webRequest.onBeforeRequest.addListener(
|
||||||
|
function (details) {
|
||||||
|
let isBlock = false
|
||||||
|
|| details.initiator === "https://googleads.g.doubleclick.net"
|
||||||
|
|| details.initiator.indexOf("googleads.g.doubleclick.net") != -1
|
||||||
|
|| details.url.indexOf("googleads.g.doubleclick.net") != -1
|
||||||
|
|| details.url.indexOf("pagead2.googlesyndication.com") != -1
|
||||||
|
|| details.url.indexOf("pagead2.googlesyndication.com") != -1
|
||||||
|
|| details.url.indexOf("partner.googleadservices.com") != -1
|
||||||
|
|| details.url.indexOf("adservice.google.com") != -1
|
||||||
|
|| details.url.indexOf("googleads") != -1
|
||||||
|
|| details.url.indexOf("adsbygoogle") != -1
|
||||||
|
if (isBlock) // 拦截后打印到控制台显示
|
||||||
|
console.log(isBlock ? "block" : "allow", details)
|
||||||
|
return { cancel: isBlock };
|
||||||
|
},
|
||||||
|
{ urls: ["<all_urls>"] },
|
||||||
|
["blocking"]
|
||||||
|
);
|
@ -0,0 +1,24 @@
|
|||||||
|
// console.log("[BitDance extension] 学生助手插件 - 删除谷歌广告模块加载成功");
|
||||||
|
// window.onload = () => {
|
||||||
|
|
||||||
|
// // 基本上 background_preventAdsScript.js 可以在源头拦截所有广告,所以下面的代码正常情况可以不用,除非用户未授权所需权限
|
||||||
|
|
||||||
|
// // 谷歌广告的通用特性是几层ins中间包含iframe,最外层ins有adsbygoogle这个class,所以上来就给他干掉
|
||||||
|
// var insList = document.getElementsByTagName("ins");
|
||||||
|
// for (var i = insList.length - 1; i >= 0; i--) {
|
||||||
|
// ins = insList[i];
|
||||||
|
// if (ins.classList.contains("adsbygoogle")) {
|
||||||
|
// console.log("发现google广告ins容器,删除!");
|
||||||
|
// ins.parentNode.removeChild(ins);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 如果不含ins,但是能够断定是广告iframe,也干掉他
|
||||||
|
// var iframes = document.getElementsByTagName("iframe");
|
||||||
|
// for (var i = iframes.length - 1; i >= 0; i--) {
|
||||||
|
// if (iframes[i].src.indexOf("googleads.g.doubleclick.net") > -1) {
|
||||||
|
// console.log("发现google广告,删除!");
|
||||||
|
// iframes[i].parentNode.removeChild(iframes[i]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
@ -15,6 +15,7 @@
|
|||||||
"scripts": [
|
"scripts": [
|
||||||
"assets/js/lib/jquery.min.js",
|
"assets/js/lib/jquery.min.js",
|
||||||
"assets/js/background.js",
|
"assets/js/background.js",
|
||||||
|
"assets/js/remove-google-ads/background_preventAdsScript.js",
|
||||||
"assets/html/pomodoro/background.js",
|
"assets/html/pomodoro/background.js",
|
||||||
"assets/js/advanced-search/background.js",
|
"assets/js/advanced-search/background.js",
|
||||||
"assets/html/screenshot/background.js"
|
"assets/html/screenshot/background.js"
|
||||||
@ -37,6 +38,15 @@
|
|||||||
"css": [],
|
"css": [],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"*://*/*"
|
||||||
|
],
|
||||||
|
"js": [
|
||||||
|
"assets/js/remove-google-ads/removeAds.js"
|
||||||
|
],
|
||||||
|
"run_at": "document_start"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": [
|
||||||
"*://blog.csdn.net/*"
|
"*://blog.csdn.net/*"
|
||||||
@ -47,6 +57,15 @@
|
|||||||
],
|
],
|
||||||
"run_at": "document_start"
|
"run_at": "document_start"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"*://www.it1352.com/*"
|
||||||
|
],
|
||||||
|
"js": [
|
||||||
|
"assets/js/expand-full-text/www.it1352.com.js"
|
||||||
|
],
|
||||||
|
"run_at": "document_start"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": [
|
||||||
"*://fanyi.qq.com/*"
|
"*://fanyi.qq.com/*"
|
||||||
@ -122,8 +141,10 @@
|
|||||||
"contextMenus",
|
"contextMenus",
|
||||||
"storage",
|
"storage",
|
||||||
"webRequest",
|
"webRequest",
|
||||||
|
"webRequestBlocking",
|
||||||
"tabs",
|
"tabs",
|
||||||
"activeTab",
|
"activeTab",
|
||||||
"notifications"
|
"notifications",
|
||||||
|
"<all_urls>"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user