Răsfoiți Sursa

Merge branch 'master' of https://github.com/PUGE/assist

puge 5 ani în urmă
părinte
comite
c5327ae0dd
1 a modificat fișierele cu 31 adăugiri și 22 ștergeri
  1. 31 22
      background.js

+ 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);