|
@@ -1,6 +1,4 @@
|
|
|
-var userInfo = null
|
|
|
|
|
-var username = localStorage.getItem('owoUsername')
|
|
|
|
|
-var password = localStorage.getItem('owoPassword')
|
|
|
|
|
|
|
+var userInfo = {}
|
|
|
|
|
|
|
|
var tempData = null
|
|
var tempData = null
|
|
|
var openList = {}
|
|
var openList = {}
|
|
@@ -12,24 +10,35 @@ function saveOpenList () {
|
|
|
localStorage.setItem('owoOpenList', JSON.stringify(openList))
|
|
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) {
|
|
function clearData (data) {
|
|
@@ -42,8 +51,29 @@ function clearData (data) {
|
|
|
return returnData
|
|
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) {
|
|
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
|
|
|
|
|
+ console.log(message)
|
|
|
switch (message.name) {
|
|
switch (message.name) {
|
|
|
case 'getData':
|
|
case 'getData':
|
|
|
const nowTime = Date.parse(new Date())
|
|
const nowTime = Date.parse(new Date())
|
|
@@ -52,20 +82,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
|
|
|
// console.log('使用缓存返回!', tempData)
|
|
// console.log('使用缓存返回!', tempData)
|
|
|
sendResponse(clearData(tempData.data))
|
|
sendResponse(clearData(tempData.data))
|
|
|
} else {
|
|
} 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))
|
|
sendResponse(clearData(dataTemp))
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -74,9 +91,17 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
|
|
|
tempData = null
|
|
tempData = null
|
|
|
fetch(`http://cunchu.site/data/blockList.json`).then(data => data.json()).then(dataTemp => {
|
|
fetch(`http://cunchu.site/data/blockList.json`).then(data => data.json()).then(dataTemp => {
|
|
|
blockListTemp = dataTemp
|
|
blockListTemp = dataTemp
|
|
|
|
|
+ chrome.storage.sync.set({userInfo: {}})
|
|
|
|
|
+ userInfo = {}
|
|
|
lanjie(dataTemp)
|
|
lanjie(dataTemp)
|
|
|
sendResponse()
|
|
sendResponse()
|
|
|
})
|
|
})
|
|
|
|
|
+ case 'reloadUser':
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ reloadUser(() => {
|
|
|
|
|
+ reGetData('')
|
|
|
|
|
+ })
|
|
|
|
|
+ }, 100);
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
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) {
|
|
// function logResponse(responseDetails) {
|