bg.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const apiurl = 'https://searxes.danwin1210.me/collab/open/ismitm.php';
  2. let mymemory = {};
  3. function ismitm(f) {
  4. return new Promise((g, b) => {
  5. fetch(apiurl, {
  6. method: 'POST',
  7. mode: 'cors',
  8. headers: {
  9. 'Content-Type': 'application/x-www-form-urlencoded'
  10. },
  11. body: 'f=' + f
  12. }).then(function (r) {
  13. return r.json();
  14. }).then(function (r) {
  15. if (r[0]) {
  16. g(r[1]);
  17. } else {
  18. b();
  19. }
  20. }).catch(b);
  21. });
  22. }
  23. browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
  24. if (mymemory[request] != undefined) {
  25. let rlt = mymemory[request];
  26. if (Object.keys(mymemory).length > 300) {
  27. let cnt = 1;
  28. for (let t in mymemory) {
  29. if (cnt > 10) {
  30. break;
  31. }
  32. mymemory[t] = null;
  33. delete mymemory[t];
  34. cnt++;
  35. }
  36. }
  37. browser.tabs.sendMessage(sender.tab.id, [request, rlt]);
  38. } else {
  39. ismitm(request).then(function (a) {
  40. mymemory[request] = a;
  41. browser.tabs.sendMessage(sender.tab.id, [request, a]);
  42. }, function () {
  43. browser.tabs.sendMessage(sender.tab.id, [request, false]);
  44. });
  45. }
  46. });