mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-03 04:21:53 +08:00
Update Reject Filter Parsing
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user