Explorar el Código

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

PUGE hace 2 años
padre
commit
0406b29269
Se han modificado 9 ficheros con 182 adiciones y 101 borrados
  1. 104 32
      back/background.js
  2. 1 1
      back/insert.js
  3. 70 0
      back/options.js
  4. 1 0
      back/popup.js
  5. 0 0
      background.js
  6. 0 66
      js/options.js
  7. 0 0
      js/popup.js
  8. 4 1
      manifest.json
  9. 2 1
      options.html

+ 104 - 32
back/background.js

@@ -1,6 +1,4 @@
-var userInfo = null
-var username = localStorage.getItem('owoUsername')
-var password = localStorage.getItem('owoPassword')
+var userInfo = {}
 
 var tempData = null
 var openList = {}
@@ -12,24 +10,35 @@ 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 reloadUser (callBack) {
+  chrome.storage.sync.get('userInfo', function(data) {
+    // alert(data)
+    userInfoTemp = data.userInfo
+    if (!userInfoTemp) return
+    username = userInfoTemp.username
+    password = userInfoTemp.password
+    if (username && password) {
+      fetch(`https://user.hanshu.run/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
+          if (callBack) callBack()
+        }
+      })
     }
   })
+  
 }
+reloadUser()
 
 // 对数据进行处理
 function clearData (data) {
@@ -42,8 +51,29 @@ function clearData (data) {
   return returnData
 }
 
+function reGetData (url, callBack) {
+  const nowTime = Date.parse(new Date())
+  const serverUrl = 'https://going.run/assistAll'
+  fetch(`${serverUrl}?route=search&username=` + (userInfo.username || ''), {
+    method: 'POST',
+    body: JSON.stringify({
+      "edition": 5,
+      "url": url
+    }),
+    redirect: 'follow'
+  }).then(data => data.json()).then(dataTemp => {
+    
+    tempData = {
+      time: nowTime,
+      data: dataTemp
+    }
+    if (callBack) callBack(dataTemp)
+  })
+}
+
 // 监听消息
 chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
+  console.log(message)
   switch (message.name) {
     case 'getData':
       const nowTime = Date.parse(new Date())
@@ -52,20 +82,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
         // console.log('使用缓存返回!', tempData)
         sendResponse(clearData(tempData.data))
       } else {
-        const serverUrl = 'https://going.run/assistAll'
-        fetch(`${serverUrl}?route=search`, {
-          method: 'POST',
-          body: JSON.stringify({
-            "edition": 5,
-            "url": message.url
-          }),
-          redirect: 'follow'
-        }).then(data => data.json()).then(dataTemp => {
-          
-          tempData = {
-            time: nowTime,
-            data: dataTemp
-          }
+        reGetData(message.url, (dataTemp) => {
           sendResponse(clearData(dataTemp))
         })
       }
@@ -74,9 +91,17 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
       tempData = null
       fetch(`http://cunchu.site/data/blockList.json`).then(data => data.json()).then(dataTemp => {
         blockListTemp = dataTemp
+        chrome.storage.sync.set({userInfo: {}})
+        userInfo = {}
         lanjie(dataTemp)
         sendResponse()
       })
+    case 'reloadUser':
+      setTimeout(() => {
+        reloadUser(() => {
+          reGetData('')
+        })
+      }, 100);
     default:
       break;
   }
@@ -118,6 +143,53 @@ function lanjie (blockList) {
   )
 }
 
+chrome.runtime.onMessageExternal.addListener(
+  function(request, sender, sendResponse) {
+    sendResponse('ok')
+    switch (request.name) {
+      case 'sendMessage':
+        var myHeaders = new Headers();
+        myHeaders.append("Content-Type", "application/json");
+
+        var raw = JSON.stringify({
+          "first": {
+            "value": "插件提示",
+            "color": "#173177"
+          },
+          "keyword1": {
+            "value": request.keyword1,
+            "color": "#173177"
+          },
+          "keyword2": {
+            "value": request.keyword1,
+            "color": "#173177"
+          },
+          "keyword3": {
+            "value": (new Date()).toLocaleString(),
+            "color": "#173177"
+          },
+          "remark": {
+            "value": request.remark,
+            "color": "#173177"
+          }
+        });
+
+        var requestOptions = {
+          method: 'POST',
+          headers: myHeaders,
+          body: raw,
+          redirect: 'follow'
+        };
+
+        fetch(`https://hanshu.run/gzh?type=${request.type}&template=EvpHwEBpG2rkLHYMtIH2ADww9JCQwEaWlTAqyoPF6xQ`, requestOptions)
+          .then(response => response.text())
+          .then(result => console.log(result))
+          .catch(error => console.log('error', error));
+      default:
+        break;
+    }
+  }
+);
 
 
 // function logResponse(responseDetails) {

+ 1 - 1
back/insert.js

@@ -1,4 +1,4 @@
-const serverUrl = 'https://going.run/assistAll'
+
 // let tempData = localStorage.getItem('tempData')
 // if (tempData) {
 //   tempData = JSON.parse(tempData)

+ 70 - 0
back/options.js

@@ -0,0 +1,70 @@
+//在popup.js 中调用 backgourd.js 中的变量和方法,很重要
+var bg = chrome.extension.getBackgroundPage();
+
+const serverUrl = 'https://going.run/assist'
+
+function login (username, password) {
+  fetch(`https://user.hanshu.run/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) {
+      bg.userInfo = res.data
+      chrome.storage.sync.set({userInfo: {username, password, session: bg.userInfo.session}})
+      chrome.runtime.sendMessage({name:"reloadUser"},function() {})
+      document.querySelector('.login-box').style.display = 'none'
+      let newHtml = `<table border="0"><thead><tr><th>编号</th><th>脚本名称</th><th>开启状态</th></tr></thead><tbody>`
+      fetch(`https://going.run/assist?route=getList&username=${username}&session=${bg.userInfo.session}`).then((response) => {return response.json();}).then((res) => {
+        console.log(bg.openList)
+        res.data.forEach(element => {
+          newHtml += `<tr><td>${element.id}</td><td>${element.name}</td><td><input type="checkbox" key="${element.id}" id="check${element.id}" name="check${element.id}" ${bg.openList[element.id] ? 'checked' : ''}></td></tr>`
+        });
+        newHtml += `</tbody></table>`
+        document.querySelector('#selectTable').innerHTML = newHtml
+        document.querySelector('#selectTable').style.display = 'block'
+        setTimeout(() => {
+          document.querySelectorAll('table input').forEach(element => {
+            element.onchange = function (e) {
+              const itemId = e.target.getAttribute("key")
+              bg.openList[itemId] = !bg.openList[itemId]
+              bg.saveOpenList()
+            }
+          });
+        }, 0);
+      })
+    }
+  })
+}
+chrome.storage.sync.get('userInfo', function(data) {
+  console.log(data)
+  const userInfo = data.userInfo
+  if (userInfo && userInfo.username && userInfo.password && userInfo.session) {
+    login(userInfo.username, userInfo.password)
+  }
+})
+// 登录按钮点击
+document.getElementsByClassName('login-button')[0].onclick = function () {
+	const username = document.getElementById('username').value
+  const password = document.getElementById('password').value
+  if (!username || !password) {
+    chrome.notifications.create(null, {
+      type: 'basic',
+      iconUrl: 'img/48.png',
+      title: '运行方案',
+      message: '用户名或密码不能为空!'
+    })
+    return
+  }
+	login(username, password)
+}
+
+document.getElementsByClassName('login-button')[1].onclick = function () {
+	window.open('https://demos.run/debuger/index.html?view-loginContent=register#login')
+}

+ 1 - 0
back/popup.js

@@ -46,6 +46,7 @@ document.getElementsByClassName('userInfo')[0].onclick = function () {
     window.open(chrome.extension.getURL('options.html'), "_blank")
   } else {
     chrome.storage.sync.set({userInfo: {}})
+    chrome.runtime.sendMessage({name:"reloadUser"},function() {})
     location.reload();
   }
 }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
background.js


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 66
js/options.js


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
js/popup.js


+ 4 - 1
manifest.json

@@ -1,7 +1,7 @@
 {
 	"manifest_version": 2,
 	"name": "脚本助手",
-	"version": "1.1.20",
+	"version": "1.1.22",
 	"description": "脚本助手",
 	"icons": {
 		"16": "./img/16.png",
@@ -35,6 +35,9 @@
 		"http://*/*",
   		"https://*/*"
 	],
+	"externally_connectable": {
+		"matches": ["*://*.tlscontact.com/*"]
+	},
 	"homepage_url": "https://github.com/PUGE",
 	"options_page": "options.html",
 	"options_ui": {

+ 2 - 1
options.html

@@ -87,7 +87,8 @@
       <input id="username" type="text">
       <div class="label">密码:</div>
       <input id="password" type="password">
-      <button class="login-button" onclick="login()">登录</button>
+      <button class="login-button" >登录</button>
+      <button class="login-button">注册</button>
     </div>
     <div id="selectTable" style="display: none;">
 

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio