puge 5 jaren geleden
bovenliggende
commit
4efa030b5a
4 gewijzigde bestanden met toevoegingen van 64 en 45 verwijderingen
  1. 1 1
      js/options.js
  2. 58 40
      js/popup.js
  3. 2 2
      manifest.json
  4. 3 2
      popup.html

+ 1 - 1
js/options.js

@@ -1,4 +1,4 @@
-const serverUrl = 'http://154.8.196.163:8005'
+const serverUrl = 'https://going.run/assist'
 // 登录按钮点击
 document.getElementsByClassName('login-button')[0].onclick = function () {
 	const username = document.getElementById('username').value

+ 58 - 40
js/popup.js

@@ -1,52 +1,21 @@
-const buttonItem = document.getElementsByTagName('button')[0]
-const serverUrl = 'http://154.8.196.163:8005'
+const serverUrl = 'https://going.run/assist'
 
 const getSchemeData = new Promise((resolve, reject) => {
   getCurrentTabId((tabInfo) => {
-    fetch(`${serverUrl}/?edition=1&url=${tabInfo.url}`).then(data => data.json()).then(dataTemp => {
+    fetch(`${serverUrl}?route=search`, {
+      method: 'POST',
+      body: JSON.stringify({
+        "edition": 2,
+        "url": tabInfo.url
+      }),
+      redirect: 'follow'
+    }).then(data => data.json()).then(dataTemp => {
       dataTemp.tabInfo = tabInfo
       resolve(dataTemp)
     })
   })
 })
 
-buttonItem.onclick = function () {
-  getSchemeData.then((dataTemp) => {
-    if (dataTemp.err === 0) {
-      // console.log(dataTemp.type)
-      switch (dataTemp.type) {
-        case 'run': {
-          chrome.notifications.create(null, {
-            type: 'basic',
-            iconUrl: 'img/48.png',
-            title: '运行方案',
-            message: '远程方案以载入并运行!'
-          })
-          // console.log(unescape(dataTemp.data))
-          chrome.tabs.executeScript(dataTemp.tabInfo.id, {code: unescape(dataTemp.data)})
-          break
-        }
-      }
-    } else if (dataTemp.err === 999) {
-      chrome.notifications.create(null, {
-        type: 'basic',
-        iconUrl: 'img/48.png',
-        title: '版本过低',
-        message: '有新版本请在弹出页面下载最新插件!'
-      })
-      // console.log(unescape(dataTemp.data))
-      chrome.tabs.create({url: dataTemp.url})
-    } else {
-      chrome.notifications.create(null, {
-        type: 'basic',
-        iconUrl: 'img/48.png',
-        title: '插件提示',
-        message: unescape(dataTemp.message)
-      })
-    }
-  })
-}
-
 let userInfo = localStorage.getItem('userInfo')
 if (userInfo) {
 	userInfo = JSON.parse(userInfo)
@@ -65,16 +34,65 @@ document.getElementsByClassName('login')[0].onclick = function () {
   window.open(chrome.extension.getURL('options.html'))
 }
 
+let dataCopy = null
+
 window.onload = function() { 
   // alert("页面加载完成!"); 
   // 获取是否有脚本
   getSchemeData.then((dataTemp) => {
     console.log(dataTemp)
     const scriptBox = document.getElementsByClassName('script-box')[0]
+    if (dataTemp.edition > 1) {
+      chrome.notifications.create(null, {
+        type: 'basic',
+        iconUrl: 'img/48.png',
+        title: '版本过低',
+        message: '有新版本请在弹出页面下载最新插件!'
+      })
+      // console.log(unescape(dataTemp.data))
+      chrome.tabs.create({url: dataTemp.url})
+      return
+    }
     if (dataTemp.err !== 0) {
       scriptBox.classList.add('no-scheme')
     } else {
+      const data = dataTemp['data']
+      dataCopy = data
+      let buttonHtml = ''
+      let ind = 0
+      data.forEach(element => {
+        ind++
+        buttonHtml += `<button data-ind="${ind}">${element.name}</button>`
+      });
+      document.querySelector('.button-box').innerHTML = buttonHtml
       scriptBox.classList.add('scheme')
+      setTimeout(() => {
+        const buttonList = document.getElementsByTagName('button')
+        for (const key in buttonList) {
+          if (Object.hasOwnProperty.call(buttonList, key)) {
+            const element = buttonList[key];
+            element.onclick = function () {
+              
+              let index = this.getAttribute("data-ind")
+              index = parseInt(index)
+              let dataTempCopy = dataCopy[index]
+              switch (dataTempCopy.type) {
+                case 'run': {
+                  chrome.notifications.create(null, {
+                    type: 'basic',
+                    iconUrl: 'img/48.png',
+                    title: '运行方案',
+                    message: '远程方案以载入并运行!'
+                  })
+                  // console.log(unescape(dataTemp.data))
+                  chrome.tabs.executeScript(dataTemp.tabInfo.id, {code: unescape(dataTempCopy.data)})
+                  break
+                }
+              }
+            }
+          }
+        }
+      }, 0);
     }
   })
 }

+ 2 - 2
manifest.json

@@ -1,7 +1,7 @@
 {
 	"manifest_version": 2,
 	"name": "脚本助手",
-	"version": "1.0.4",
+	"version": "1.0.5",
 	"description": "脚本助手",
 	"icons": {
 		"16": "./img/16.png",
@@ -18,7 +18,7 @@
 		"activeTab",
 		"notifications",
 		"webRequest",
-		"http:/154.8.196.163/*"
+		"https://going.run/*"
 	],
 	"homepage_url": "https://github.com/PUGE",
 	"options_page": "options.html",

+ 3 - 2
popup.html

@@ -12,7 +12,7 @@
         margin: 0;
       }
       button {
-        width: 100%;
+        width: 96%;
         border: none;
         height: 30px;
         background-color: #009fe9;
@@ -20,6 +20,8 @@
         cursor: pointer;
         user-select: none;
         box-shadow: 1px 1px 4px #968a8a;
+        margin: 0 2%;
+        margin-top: 5px;
       }
       .user-bar {
         font-family: "Microsoft YaHei";
@@ -90,7 +92,6 @@
         <p>此页面没有适用脚本!</p>
       </div>
       <div class="button-box">
-        <button>获取方案</button>
       </div>
     </div>