1
0
mirror of https://gitee.com/bitdance-team/chrome-extension synced 2025-01-25 20:50:26 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

从源头屏蔽Google广告加载

This commit is contained in:
程序员小墨 2022-02-09 16:56:01 +08:00
parent b175506ab3
commit 39a4721dda
3 changed files with 66 additions and 1 deletions

View File

@ -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"]
);

View File

@ -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]);
// }
// }
// }

View File

@ -15,6 +15,7 @@
"scripts": [
"assets/js/lib/jquery.min.js",
"assets/js/background.js",
"assets/js/remove-google-ads/background_preventAdsScript.js",
"assets/html/pomodoro/background.js",
"assets/js/advanced-search/background.js",
"assets/html/screenshot/background.js"
@ -37,6 +38,15 @@
"css": [],
"run_at": "document_start"
},
{
"matches": [
"*://*/*"
],
"js": [
"assets/js/remove-google-ads/removeAds.js"
],
"run_at": "document_start"
},
{
"matches": [
"*://blog.csdn.net/*"
@ -47,6 +57,15 @@
],
"run_at": "document_start"
},
{
"matches": [
"*://www.it1352.com/*"
],
"js": [
"assets/js/expand-full-text/www.it1352.com.js"
],
"run_at": "document_start"
},
{
"matches": [
"*://fanyi.qq.com/*"
@ -122,8 +141,10 @@
"contextMenus",
"storage",
"webRequest",
"webRequestBlocking",
"tabs",
"activeTab",
"notifications"
"notifications",
"<all_urls>"
]
}