mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 01:30:37 +08:00
Chore: merge reject ruleset and domainset during build
This commit is contained in:
parent
70bbf9c449
commit
6380d0be5a
@ -78,9 +78,7 @@ export const buildRejectDomainSet = task(import.meta.path, async (span) => {
|
|||||||
console.log(`Import ${previousSize} rules from Hosts / AdBlock Filter Rules & reject_sukka.conf!`);
|
console.log(`Import ${previousSize} rules from Hosts / AdBlock Filter Rules & reject_sukka.conf!`);
|
||||||
|
|
||||||
// Dedupe domainSets
|
// Dedupe domainSets
|
||||||
await span.traceChildAsync('dedupe from black keywords/suffixes', async (childSpan) => {
|
await span.traceChildAsync('dedupe from black keywords', async (childSpan) => {
|
||||||
/** Collect DOMAIN-SUFFIX from non_ip/reject.conf for deduplication */
|
|
||||||
const domainSuffixSet = new Set<string>();
|
|
||||||
/** Collect DOMAIN-KEYWORD from non_ip/reject.conf for deduplication */
|
/** Collect DOMAIN-KEYWORD from non_ip/reject.conf for deduplication */
|
||||||
const domainKeywordsSet = new Set<string>();
|
const domainKeywordsSet = new Set<string>();
|
||||||
|
|
||||||
@ -91,28 +89,26 @@ export const buildRejectDomainSet = task(import.meta.path, async (span) => {
|
|||||||
if (type === 'DOMAIN-KEYWORD') {
|
if (type === 'DOMAIN-KEYWORD') {
|
||||||
domainKeywordsSet.add(value.trim());
|
domainKeywordsSet.add(value.trim());
|
||||||
} else if (type === 'DOMAIN-SUFFIX') {
|
} else if (type === 'DOMAIN-SUFFIX') {
|
||||||
domainSuffixSet.add(value.trim());
|
domainSets.add(`.${value.trim()}`); // Add to domainSets for later deduplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove as many domains as possible from domainSets before creating trie
|
// Remove as many domains as possible from domainSets before creating trie
|
||||||
SetHelpers.subtract(domainSets, domainSuffixSet);
|
|
||||||
SetHelpers.subtract(domainSets, filterRuleWhitelistDomainSets);
|
SetHelpers.subtract(domainSets, filterRuleWhitelistDomainSets);
|
||||||
|
|
||||||
childSpan.traceChildSync('dedupe from white/suffixes', () => {
|
childSpan.traceChildSync('dedupe from white suffixes', () => {
|
||||||
const trie = createTrie(domainSets);
|
const trie = createTrie(domainSets);
|
||||||
|
|
||||||
domainSuffixSet.forEach(suffix => {
|
|
||||||
trie.substractSetInPlaceFromFound(suffix, domainSets);
|
|
||||||
});
|
|
||||||
filterRuleWhitelistDomainSets.forEach(suffix => {
|
filterRuleWhitelistDomainSets.forEach(suffix => {
|
||||||
trie.substractSetInPlaceFromFound(suffix, domainSets);
|
trie.substractSetInPlaceFromFound(suffix, domainSets);
|
||||||
domainSets.delete(
|
if (suffix[0] === '.') {
|
||||||
suffix[0] === '.'
|
domainSets.delete(suffix.slice(1));
|
||||||
? suffix.slice(1) // handle case like removing `g.msn.com` due to white `.g.msn.com` (`@@||g.msn.com`)
|
domainSets.delete(suffix);
|
||||||
: `.${suffix}` // If `g.msn.com` is whitelisted, then `.g.msn.com` should be removed from domain set
|
} else {
|
||||||
);
|
domainSets.delete(`.${suffix}`);
|
||||||
|
domainSets.delete(suffix);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user