0
0
mirror of https://codeberg.org/crimeflare/cloudflare-tor synced 2024-12-22 23:50:31 +00:00
This commit is contained in:
Michael Vigil 2020-09-13 01:44:56 +02:00
parent eea88d0e41
commit e88f4d9f77

View File

@ -1,4 +1,4 @@
let localUse = false,
let localUse = -1,
localDB = [],
timr, memcache = {},
forcePurge = false,
@ -1082,9 +1082,9 @@ function get_realdomain(w) {
return wa[1] + '.' + wa[0];
}
function is_hostile(f) {
if (localUse) {
if (localUse >= 1) {
return new Promise((g, b) => {
g(localDB.includes(f) ? true : false);
g(localDB.includes(get_realdomain(f)) ? true : false);
});
}
return new Promise((g, b) => {
@ -1169,7 +1169,7 @@ function forget_cache() {
'mul': (g.mul != undefined ? g.mul : 'eo')
});
chrome.storage.local.set({
'opd': (g.opd == 'n' ? 'n' : 'y')
'opd': (g.opd != undefined ? g.opd : 'y')
});
chrome.storage.local.set({
'ldb': (g.ldb != undefined ? g.ldb : '[]')
@ -1187,7 +1187,17 @@ function forget_cache() {
}, 1814400000);
}
chrome.storage.local.get(['lastU', 'lastV', 'ldb', 'opd'], (g) => {
localUse = (g.opd == 'n') ? true : false;
switch (g.opd) {
case 'n':
localUse = 1;
break;
case 'l':
localUse = 2;
break;
default:
localUse = -1;
break;
}
localDB = JSON.parse(g.ldb || '[]');
if (g.lastU) {
if (Math.abs(Math.round((new Date()).getTime() / 1000) - g.lastU) > 1814400) {
@ -1216,7 +1226,7 @@ chrome.storage.local.get(['lastU', 'lastV', 'ldb', 'opd'], (g) => {
'mul': (g.mul != undefined ? g.mul : 'eo')
});
chrome.storage.local.set({
'opd': (g.opd == 'n' ? 'n' : 'y')
'opd': (g.opd != undefined ? g.opd : 'y')
});
chrome.storage.local.set({
'ldb': (g.ldb != undefined ? g.ldb : '[]')
@ -1258,7 +1268,7 @@ chrome.storage.local.get(['lastU', 'lastV', 'ldb', 'opd'], (g) => {
'mul': (g.mul != undefined ? g.mul : 'eo')
});
chrome.storage.local.set({
'opd': (g.opd == 'n' ? 'n' : 'y')
'opd': (g.opd != undefined ? g.opd : 'y')
});
chrome.storage.local.set({
'ldb': (g.ldb != undefined ? g.ldb : '[]')
@ -1275,6 +1285,34 @@ chrome.storage.local.get(['lastU', 'lastV', 'ldb', 'opd'], (g) => {
forget_cache();
}, 1814400000);
});
chrome.webRequest.onResponseStarted.addListener(r => {
if (localUse == 2) {
let ismitm = false,
hn, rh = r.responseHeaders;
for (let i = 0; i < rh.length; i++) {
hn = rh[i]['name'].toLowerCase();
if (hn == 'cf-ray' || hn == 'cf-cache-status') {
ismitm = true;
break;
}
}
if (ismitm) {
let enemy = get_realdomain((new URL(r.url)).hostname);
if (enemy.length >= 4 && !localDB.includes(enemy)) {
localDB.push(enemy);
chrome.storage.local.set({
'ldb': JSON.stringify(localDB)
});
chrome.storage.local.set({
[enemy]: 'y'
});
}
}
}
}, {
urls: ['http://*/*', 'https://*/*'],
types: ['main_frame', 'sub_frame', 'script']
}, ['responseHeaders']);
chrome.runtime.onMessage.addListener((requests, sender, sendResponse) => {
if (requests) {
if (requests === 'clear') {
@ -1287,13 +1325,19 @@ chrome.runtime.onMessage.addListener((requests, sender, sendResponse) => {
chrome.storage.local.set({
'opd': 'y'
});
localUse = false;
localUse = -1;
break;
case 'dbmode,s0':
chrome.storage.local.set({
'opd': 'n'
});
localUse = true;
localUse = 1;
break;
case 'dbmode,s2':
chrome.storage.local.set({
'opd': 'l'
});
localUse = 2;
break;
case 'dbmode,cl':
chrome.storage.local.set({