stop_cloudflare/ismitmlink/bg.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-02-19 01:53:18 +01:00
const apiurl = 'https://searxes.danwin1210.me/collab/open/ismitm.php';
let mymemory = {};
function ismitm(f) {
return new Promise((g, b) => {
fetch(apiurl, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'f=' + f
}).then(function (r) {
return r.json();
}).then(function (r) {
if (r[0]) {
g(r[1]);
} else {
b();
}
}).catch(b);
});
}
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request && sender) {
if (mymemory[request] != undefined) {
let rlt = mymemory[request];
2019-02-26 04:33:26 +01:00
if (Object.keys(mymemory).length > 20000) {
2019-02-19 01:53:18 +01:00
let cnt = 1;
for (let t in mymemory) {
if (cnt > 10) {
break;
}
mymemory[t] = null;
delete mymemory[t];
cnt++;
}
}
browser.tabs.sendMessage(sender.tab.id, [request, rlt]);
} else {
ismitm(request).then(function (a) {
mymemory[request] = a;
browser.tabs.sendMessage(sender.tab.id, [request, a]);
}, function () {
browser.tabs.sendMessage(sender.tab.id, [request, false]);
});
}
}
});