insert.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. dataTemp.forEach(element => {
  38. if (new RegExp(element.url).test(urlStr)) {
  39. addScr(element.data)
  40. return
  41. }
  42. })
  43. })