| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- var userInfo = null
- var username = localStorage.getItem('owoUsername')
- var password = localStorage.getItem('owoPassword')
- var tempData = null
- var openList = {}
- function saveUser (username, password) {
- localStorage.setItem('owoUsername', username)
- localStorage.setItem('owoPassword', password)
- }
- 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]) {
- 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 * 60 * 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;
- }
- })
|