mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-14 02:00:37 +08:00
Refactor: adjust domainset
This commit is contained in:
parent
274c2453e2
commit
6e9d2181eb
@ -137,14 +137,6 @@ export const buildRejectDomainSet = task(require.main === module, __filename)(as
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
span.traceChildSync(
|
|
||||||
'build domain map for sort & collect stat',
|
|
||||||
() => {
|
|
||||||
rejectOutput.calcDomainMap();
|
|
||||||
rejectExtraOutput.calcDomainMap();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create reject stats
|
// Create reject stats
|
||||||
const rejectDomainsStats: string[] = span
|
const rejectDomainsStats: string[] = span
|
||||||
.traceChild('create reject stats')
|
.traceChild('create reject stats')
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import createKeywordFilter from '../aho-corasick';
|
|||||||
import { buildParseDomainMap, sortDomains } from '../stable-sort-domain';
|
import { buildParseDomainMap, sortDomains } from '../stable-sort-domain';
|
||||||
import { RuleOutput } from './base';
|
import { RuleOutput } from './base';
|
||||||
import type { SingboxSourceFormat } from '../singbox';
|
import type { SingboxSourceFormat } from '../singbox';
|
||||||
import { nullthrow } from 'foxact/nullthrow';
|
|
||||||
|
|
||||||
type Preprocessed = string[];
|
type Preprocessed = string[];
|
||||||
|
|
||||||
@ -15,29 +14,24 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
|||||||
|
|
||||||
const results: string[] = [];
|
const results: string[] = [];
|
||||||
|
|
||||||
const dumped = this.domainTrie.dump();
|
this.domainTrie.dump((domain) => {
|
||||||
|
if (kwfilter(domain)) {
|
||||||
for (let i = 0, len = dumped.length; i < len; i++) {
|
return;
|
||||||
const domain = dumped[i];
|
|
||||||
if (!kwfilter(domain)) {
|
|
||||||
results.push(domain);
|
|
||||||
}
|
}
|
||||||
}
|
results.push(domain);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!this.apexDomainMap || !this.subDomainMap) {
|
||||||
|
const { domainMap, subdomainMap } = buildParseDomainMap(results);
|
||||||
|
this.apexDomainMap = domainMap;
|
||||||
|
this.subDomainMap = subdomainMap;
|
||||||
|
}
|
||||||
const sorted = sortDomains(results, this.apexDomainMap, this.subDomainMap);
|
const sorted = sortDomains(results, this.apexDomainMap, this.subDomainMap);
|
||||||
sorted.push('this_ruleset_is_made_by_sukkaw.ruleset.skk.moe');
|
sorted.push('this_ruleset_is_made_by_sukkaw.ruleset.skk.moe');
|
||||||
|
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
|
||||||
calcDomainMap() {
|
|
||||||
if (!this.apexDomainMap || !this.subDomainMap) {
|
|
||||||
const { domainMap, subdomainMap } = buildParseDomainMap(this.$preprocessed);
|
|
||||||
this.apexDomainMap = domainMap;
|
|
||||||
this.subDomainMap = subdomainMap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
surge(): string[] {
|
surge(): string[] {
|
||||||
return this.$preprocessed;
|
return this.$preprocessed;
|
||||||
}
|
}
|
||||||
@ -72,17 +66,18 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
|||||||
invariant(this.$preprocessed, 'Non dumped yet');
|
invariant(this.$preprocessed, 'Non dumped yet');
|
||||||
invariant(this.apexDomainMap, 'Missing apex domain map');
|
invariant(this.apexDomainMap, 'Missing apex domain map');
|
||||||
|
|
||||||
return Array.from(
|
return Array.from(this.$preprocessed
|
||||||
nullthrow(this.$preprocessed, 'Non dumped yet')
|
.reduce<Map<string, number>>(
|
||||||
.reduce<Map<string, number>>((acc, cur) => {
|
(acc, cur) => {
|
||||||
const suffix = this.apexDomainMap!.get(cur);
|
const suffix = this.apexDomainMap!.get(cur);
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
acc.set(suffix, (acc.get(suffix) ?? 0) + 1);
|
acc.set(suffix, (acc.get(suffix) ?? 0) + 1);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, new Map())
|
},
|
||||||
.entries()
|
new Map()
|
||||||
)
|
)
|
||||||
|
.entries())
|
||||||
.filter(a => a[1] > 9)
|
.filter(a => a[1] > 9)
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) => (b[1] - a[1]) || a[0].localeCompare(b[0])
|
(a, b) => (b[1] - a[1]) || a[0].localeCompare(b[0])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user