PUGE %!s(int64=4) %!d(string=hai) anos
pai
achega
6568033d66
Modificáronse 6 ficheiros con 149 adicións e 303 borrados
  1. 122 0
      back/background.js
  2. 26 0
      back/insert.js
  3. 0 122
      background.js
  4. 0 26
      insert.js
  5. 0 154
      js/popup.js
  6. 1 1
      manifest.json

+ 122 - 0
back/background.js

@@ -0,0 +1,122 @@
+var userInfo = null
+var username = localStorage.getItem('owoUsername')
+var password = localStorage.getItem('owoPassword')
+
+var tempData = null
+var openList = {}
+if (localStorage.getItem('owoOpenList')) {
+  openList = JSON.parse(localStorage.getItem('owoOpenList'))
+}
+
+function saveOpenList () {
+  localStorage.setItem('owoOpenList', JSON.stringify(openList))
+}
+
+
+if (username && password) {
+  fetch(`http://going.run/userServer?route=login`, {
+    method: 'POST',
+    headers: {
+      "Content-Type": "application/json"
+    },
+    body: JSON.stringify({
+      type: "assist",
+      username: username,
+      password: password
+    })
+  }).then((response) => {return response.json();}).then((res) => {
+    if (res.err === 0) {
+      userInfo = res.data
+    }
+  })
+}
+
+// 对数据进行处理
+function clearData (data) {
+  let returnData = []
+  data.forEach(element => {
+    if (openList[element.id] || element.type == 'autoRun') {
+      returnData.push(element)
+    }
+  })
+  return returnData
+}
+
+// 监听消息
+chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
+  switch (message.name) {
+    case 'getData':
+      const nowTime = Date.parse(new Date())
+      if (tempData && (tempData.time + 1 * 0 * 1000) > nowTime) {
+        console.log('使用缓存返回!', tempData)
+        sendResponse(clearData(tempData.data))
+      } else {
+        const serverUrl = 'https://going.run/assistAll'
+        fetch(`${serverUrl}?route=search`, {
+          method: 'POST',
+          body: JSON.stringify({
+            "edition": 2,
+            "url": message.url
+          }),
+          redirect: 'follow'
+        }).then(data => data.json()).then(dataTemp => {
+          
+          tempData = {
+            time: nowTime,
+            data: dataTemp
+          }
+          sendResponse(clearData(dataTemp))
+        })
+      }
+      break;
+    default:
+      break;
+  }
+  return true
+})
+
+
+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)
+  })
+}
+
+
+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"]
+  )
+}
+
+
+
+// function logResponse(responseDetails) {
+//   console.log(responseDetails);
+// }
+
+// chrome.webRequest.onCompleted.addListener(
+//   logResponse,
+//   {urls: ["<all_urls>"]}
+// );

+ 26 - 0
back/insert.js

@@ -0,0 +1,26 @@
+const serverUrl = 'https://going.run/assistAll'
+// let tempData = localStorage.getItem('tempData')
+// if (tempData) {
+//   tempData = JSON.parse(tempData)
+// }
+
+
+function addScr (data) {
+  var script = document.createElement("script");
+  script.type = "text/javascript";
+  script.charset = "UTF-8";
+  script.innerHTML = data;
+  document.body.appendChild(script)
+}
+
+chrome.runtime.sendMessage({name:"getData", url: window.location.href},function(dataTemp){
+  // console.log(dataTemp)
+  if (!dataTemp) return
+  let urlStr = window.location.href
+  dataTemp.forEach(element => {
+    if (new RegExp(element.url).test(urlStr)) {
+      addScr(element.data)
+      return
+    }
+  })
+})

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 122
background.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 26
insert.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 154
js/popup.js


+ 1 - 1
manifest.json

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

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio