puge hace 5 años
padre
commit
a630a2889c
Se han modificado 2 ficheros con 42 adiciones y 5 borrados
  1. 35 1
      background.js
  2. 7 4
      manifest.json

+ 35 - 1
background.js

@@ -77,4 +77,38 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
     default:
       break;
   }
-})
+})
+
+var blockList = {
+  "static.122.gov.cn/V1.22.2/veh1/static/js/comm/zbxhcomm.js": "https://cunchu.site/work/script/122.js",
+  "www.google-analytics.com/analytics.js": "https://cunchu.site/work/script/122.js"
+}
+
+// 拦截请求
+chrome.webRequest.onBeforeRequest.addListener(
+  function(details) {
+    
+    for (const key in blockList) {
+      if (details.url.includes(key)) {
+        console.log(details.url)
+        return {
+          redirectUrl: blockList[key]
+        }
+      }
+    }
+    return {
+      cancel: false
+    };
+  },
+  {urls: ["<all_urls>"]},
+  ["blocking"]
+)
+
+// function logResponse(responseDetails) {
+//   console.log(responseDetails);
+// }
+
+// chrome.webRequest.onCompleted.addListener(
+//   logResponse,
+//   {urls: ["<all_urls>"]}
+// );

+ 7 - 4
manifest.json

@@ -14,22 +14,25 @@
 		"default_popup": "popup.html"
 	},
 	"background": {
-		"persistent": false,
+		"persistent": true,
 		"scripts": ["background.js"]
 	},
 	"content_scripts": [
 		{
-      		"matches": ["<all_urls>"],
+			"matches": ["<all_urls>"],
 			"js": ["insert.js"],
 			"all_frames": true,
 			"run_at": "document_end"
-    	}
+		}
 	],
 	"permissions": [
 		"background",
 		"activeTab",
+		"webRequest",
+		"webRequestBlocking",
 		"notifications",
-		"https://going.run/*"
+		"http://*/*",
+  	"https://*/*"
 	],
 	"homepage_url": "https://github.com/PUGE",
 	"options_page": "options.html",