0
0
mirror of https://codeberg.org/crimeflare/cloudflare-tor synced 2024-11-05 08:52:39 +00:00
cloudflare-tor/ismitmlink/bg.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-02-19 00:53:18 +00: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 03:33:26 +00:00
if (Object.keys(mymemory).length > 20000) {
2019-02-19 00:53:18 +00: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]);
});
}
}
});