Update Reject Filter Parsing

This commit is contained in:
SukkaW
2022-12-26 00:12:59 +08:00
parent 14494a0919
commit 44aeb217d8
8 changed files with 366 additions and 92 deletions

View File

@@ -40,17 +40,19 @@ const filterRuleWhitelistDomainSets = new Set(PREDEFINED_WHITELIST);
// Parse from AdGuard Filters
console.time('* Download and process AdBlock Filter Rules');
let shouldStop = false;
await Promise.all(ADGUARD_FILTERS.map(input => {
const promise = Array.isArray(input) && input.length === 2
? processFilterRules(input[0], input[1])
: processFilterRules(input);
const promise = typeof input === 'string'
? processFilterRules(input, undefined, false)
: processFilterRules(input[0], input[1] ?? undefined, input[2] ?? false)
return promise.then((i) => {
if (i) {
const { white, black, foundDebugDomain } = i;
if (foundDebugDomain) {
process.exit(1);
};
shouldStop = true;
}
white.forEach(i => filterRuleWhitelistDomainSets.add(i));
black.forEach(i => domainSets.add(i));
} else {
@@ -61,6 +63,10 @@ const filterRuleWhitelistDomainSets = new Set(PREDEFINED_WHITELIST);
console.timeEnd('* Download and process AdBlock Filter Rules');
if (shouldStop) {
process.exit(1);
}
previousSize = domainSets.size - previousSize;
console.log(`Import ${previousSize} rules from adguard filters!`);
@@ -246,6 +252,11 @@ function isInWhiteList (domain) {
if (domain === white || domain.endsWith(white)) {
return true;
}
if (white.endsWith(domain)) {
// If a whole domain is in blacklist but a subdomain is in whitelist
// We have no choice but to remove the whole domain from blacklist
return true;
}
}
return false;