|
@@ -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,27 +14,22 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
|
|
|
|
|
|
|
const results: string[] = [];
|
|
const results: string[] = [];
|
|
|
|
|
|
|
|
- const dumped = this.domainTrie.dump();
|
|
|
|
|
-
|
|
|
|
|
- for (let i = 0, len = dumped.length; i < len; i++) {
|
|
|
|
|
- const domain = dumped[i];
|
|
|
|
|
- if (!kwfilter(domain)) {
|
|
|
|
|
- results.push(domain);
|
|
|
|
|
|
|
+ this.domainTrie.dump((domain) => {
|
|
|
|
|
+ if (kwfilter(domain)) {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ results.push(domain);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- const sorted = sortDomains(results, this.apexDomainMap, this.subDomainMap);
|
|
|
|
|
- sorted.push('this_ruleset_is_made_by_sukkaw.ruleset.skk.moe');
|
|
|
|
|
-
|
|
|
|
|
- return sorted;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- calcDomainMap() {
|
|
|
|
|
if (!this.apexDomainMap || !this.subDomainMap) {
|
|
if (!this.apexDomainMap || !this.subDomainMap) {
|
|
|
- const { domainMap, subdomainMap } = buildParseDomainMap(this.$preprocessed);
|
|
|
|
|
|
|
+ const { domainMap, subdomainMap } = buildParseDomainMap(results);
|
|
|
this.apexDomainMap = domainMap;
|
|
this.apexDomainMap = domainMap;
|
|
|
this.subDomainMap = subdomainMap;
|
|
this.subDomainMap = subdomainMap;
|
|
|
}
|
|
}
|
|
|
|
|
+ const sorted = sortDomains(results, this.apexDomainMap, this.subDomainMap);
|
|
|
|
|
+ sorted.push('this_ruleset_is_made_by_sukkaw.ruleset.skk.moe');
|
|
|
|
|
+
|
|
|
|
|
+ return sorted;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
surge(): string[] {
|
|
surge(): string[] {
|
|
@@ -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(
|
|
|
|
|
- nullthrow(this.$preprocessed, 'Non dumped yet')
|
|
|
|
|
- .reduce<Map<string, number>>((acc, cur) => {
|
|
|
|
|
|
|
+ return Array.from(this.$preprocessed
|
|
|
|
|
+ .reduce<Map<string, number>>(
|
|
|
|
|
+ (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])
|