diff --git a/packages/shell-chrome/assets/js/remove-google-ads/background_preventAdsScript.js b/packages/shell-chrome/assets/js/remove-google-ads/background_preventAdsScript.js new file mode 100644 index 0000000..ca60780 --- /dev/null +++ b/packages/shell-chrome/assets/js/remove-google-ads/background_preventAdsScript.js @@ -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: [""] }, + ["blocking"] +); diff --git a/packages/shell-chrome/assets/js/remove-google-ads/removeAds.js b/packages/shell-chrome/assets/js/remove-google-ads/removeAds.js new file mode 100644 index 0000000..ad41942 --- /dev/null +++ b/packages/shell-chrome/assets/js/remove-google-ads/removeAds.js @@ -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]); +// } +// } +// } diff --git a/packages/shell-chrome/manifest.json b/packages/shell-chrome/manifest.json index 16c52ef..d27c054 100644 --- a/packages/shell-chrome/manifest.json +++ b/packages/shell-chrome/manifest.json @@ -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", + "" ] }