|
@@ -1,10 +1,10 @@
|
|
|
const serverUrl = 'https://going.run/assistAll'
|
|
const serverUrl = 'https://going.run/assistAll'
|
|
|
-
|
|
|
|
|
// let tempData = localStorage.getItem('tempData')
|
|
// let tempData = localStorage.getItem('tempData')
|
|
|
// if (tempData) {
|
|
// if (tempData) {
|
|
|
// tempData = JSON.parse(tempData)
|
|
// tempData = JSON.parse(tempData)
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
+
|
|
|
function addScr (data) {
|
|
function addScr (data) {
|
|
|
var script = document.createElement("script");
|
|
var script = document.createElement("script");
|
|
|
script.type = "text/javascript";
|
|
script.type = "text/javascript";
|
|
@@ -13,33 +13,10 @@ function addScr (data) {
|
|
|
document.body.appendChild(script)
|
|
document.body.appendChild(script)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const getSchemeData = new Promise((resolve, reject) => {
|
|
|
|
|
- const nowTime = Date.parse(new Date())
|
|
|
|
|
- // if (tempData && (tempData.time + 10 * 60 * 1000) > nowTime) {
|
|
|
|
|
- // console.log('使用缓存返回!', tempData)
|
|
|
|
|
- // resolve(tempData.data)
|
|
|
|
|
- // }
|
|
|
|
|
- const urlStr = window.location.href
|
|
|
|
|
- fetch(`${serverUrl}?route=search`, {
|
|
|
|
|
- method: 'POST',
|
|
|
|
|
- body: JSON.stringify({
|
|
|
|
|
- "edition": 2,
|
|
|
|
|
- "url": urlStr
|
|
|
|
|
- }),
|
|
|
|
|
- redirect: 'follow'
|
|
|
|
|
- }).then(data => data.json()).then(dataTemp => {
|
|
|
|
|
- resolve(dataTemp)
|
|
|
|
|
- })
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-getSchemeData.then((dataTemp) => {
|
|
|
|
|
|
|
+chrome.runtime.sendMessage({name:"getData", url: window.location.href},function(dataTemp){
|
|
|
|
|
+ console.log(dataTemp)
|
|
|
|
|
+ if (!dataTemp) return
|
|
|
let urlStr = window.location.href
|
|
let urlStr = window.location.href
|
|
|
- localStorage.setItem('tempData', JSON.stringify({
|
|
|
|
|
- time: Date.parse(new Date()),
|
|
|
|
|
- data: dataTemp
|
|
|
|
|
- }))
|
|
|
|
|
dataTemp.forEach(element => {
|
|
dataTemp.forEach(element => {
|
|
|
if (new RegExp(element.url).test(urlStr)) {
|
|
if (new RegExp(element.url).test(urlStr)) {
|
|
|
addScr(element.data)
|
|
addScr(element.data)
|