puge преди 5 години
родител
ревизия
67152c32d0
променени са 2 файла, в които са добавени 32 реда и са изтрити 23 реда
  1. 31 22
      background.js
  2. 1 1
      manifest.json

+ 31 - 22
background.js

@@ -81,32 +81,41 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
 })
 
 
-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",
-  "https://g.alicdn.com/damai/pc-seat/0.0.5/vendor.js": "https://cunchu.site/work/script/damai.js",
-  "https://g.alicdn.com/damai/pc-seat/0.0.5/pc.js": "https://cunchu.site/work/script/damai-pc.js"
+var blockListTemp = null
+
+if (blockListTemp != null) {
+  lanjie(blockListTemp)
+} else {
+  fetch(`http://cunchu.site/data/blockList.json`).then(data => data.json()).then(dataTemp => {
+    blockListTemp = dataTemp
+    lanjie(dataTemp)
+  })
 }
 
-// 拦截请求
-chrome.webRequest.onBeforeRequest.addListener(
-  function(details) {
-    
-    for (const key in blockList) {
-      if (details.url.includes(key)) {
-        console.log(details.url)
-        return {
-          redirectUrl: blockList[key]
+
+function lanjie (blockList) {
+  // 拦截请求
+  chrome.webRequest.onBeforeRequest.addListener(
+    function(details) {
+      
+      for (const key in blockList) {
+        if (details.url.includes(key) || new RegExp(key).test(details.url)) {
+          console.log(details.url)
+          return {
+            redirectUrl: blockList[key]
+          }
         }
       }
-    }
-    return {
-      cancel: false
-    };
-  },
-  {urls: ["<all_urls>"]},
-  ["blocking"]
-)
+      return {
+        cancel: false
+      };
+    },
+    {urls: ["<all_urls>"]},
+    ["blocking"]
+  )
+}
+
+
 
 // function logResponse(responseDetails) {
 //   console.log(responseDetails);

+ 1 - 1
manifest.json

@@ -1,7 +1,7 @@
 {
 	"manifest_version": 2,
 	"name": "脚本助手",
-	"version": "1.1.3",
+	"version": "1.1.4",
 	"description": "脚本助手",
 	"icons": {
 		"16": "./img/16.png",