insert.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const serverUrl = 'https://going.run/assistAll'
  2. let tempData = localStorage.getItem('tempData')
  3. if (tempData) {
  4. tempData = JSON.parse(tempData)
  5. }
  6. function addScr (data) {
  7. var script = document.createElement("script");
  8. script.type = "text/javascript";
  9. script.charset = "UTF-8";
  10. script.innerHTML = data;
  11. document.body.appendChild(script)
  12. }
  13. const getSchemeData = new Promise((resolve, reject) => {
  14. const nowTime = Date.parse(new Date())
  15. if (tempData && (tempData.time + 10 * 60 * 1000) > nowTime) {
  16. console.log('使用缓存返回!', tempData)
  17. resolve(tempData.data)
  18. }
  19. const urlStr = window.location.href
  20. fetch(`${serverUrl}?route=search`, {
  21. method: 'POST',
  22. body: JSON.stringify({
  23. "edition": 2,
  24. "url": urlStr
  25. }),
  26. redirect: 'follow'
  27. }).then(data => data.json()).then(dataTemp => {
  28. resolve(dataTemp)
  29. })
  30. })
  31. getSchemeData.then((dataTemp) => {
  32. let urlStr = window.location.href
  33. localStorage.setItem('tempData', JSON.stringify({
  34. time: Date.parse(new Date()),
  35. data: dataTemp
  36. }))
  37. urlStr = urlStr.replace('https://', '')
  38. urlStr = urlStr.replace('http://', '')
  39. dataTemp.forEach(element => {
  40. if (urlStr.startsWith(element.url)) {
  41. addScr(element.data)
  42. return
  43. }
  44. })
  45. })