@@ -15,10 +15,9 @@ export class DomainsetOutput extends RuleOutput<string[]> {
15
15
private $clash : string [ ] = [ 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' ] ;
16
16
private $singbox_domains : string [ ] = [ 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' ] ;
17
17
private $singbox_domains_suffixes : string [ ] = [ 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe' ] ;
18
-
18
+ private $adguardhome : string [ ] = [ ] ;
19
19
preprocess ( ) {
20
20
const kwfilter = createKeywordFilter ( this . domainKeywords ) ;
21
- const results : string [ ] = [ ] ;
22
21
23
22
this . domainTrie . dumpWithoutDot ( ( domain , subdomain ) => {
24
23
if ( kwfilter ( domain ) ) {
@@ -29,21 +28,29 @@ export class DomainsetOutput extends RuleOutput<string[]> {
29
28
this . $clash . push ( subdomain ? `+.${ domain } ` : domain ) ;
30
29
( subdomain ? this . $singbox_domains : this . $singbox_domains_suffixes ) . push ( domain ) ;
31
30
32
- results . push ( domain ) ;
31
+ if ( subdomain ) {
32
+ this . $adguardhome . push ( `||${ domain } ^` ) ;
33
+ } else {
34
+ this . $adguardhome . push ( `|${ domain } ^` ) ;
35
+ }
33
36
} , true ) ;
34
37
35
- return results ;
38
+ return this . $surge ;
36
39
}
37
40
38
41
surge ( ) : string [ ] {
42
+ this . runPreprocess ( ) ;
39
43
return this . $surge ;
40
44
}
41
45
42
46
clash ( ) : string [ ] {
47
+ this . runPreprocess ( ) ;
43
48
return this . $clash ;
44
49
}
45
50
46
51
singbox ( ) : string [ ] {
52
+ this . runPreprocess ( ) ;
53
+
47
54
return RuleOutput . jsonToLines ( {
48
55
version : 2 ,
49
56
rules : [ {
@@ -55,6 +62,8 @@ export class DomainsetOutput extends RuleOutput<string[]> {
55
62
56
63
protected apexDomainMap : Map < string , string > | null = null ;
57
64
getStatMap ( ) {
65
+ this . runPreprocess ( ) ;
66
+
58
67
invariant ( this . $preprocessed , 'Non dumped yet' ) ;
59
68
60
69
if ( ! this . apexDomainMap ) {
@@ -90,7 +99,7 @@ export class DomainsetOutput extends RuleOutput<string[]> {
90
99
mitmSgmodule = undefined ;
91
100
92
101
adguardhome ( ) : string [ ] {
93
- const results : string [ ] = [ ] ;
102
+ this . runPreprocess ( ) ;
94
103
95
104
// const whitelistArray = sortDomains(Array.from(whitelist));
96
105
// for (let i = 0, len = whitelistArray.length; i < len; i++) {
@@ -102,51 +111,42 @@ export class DomainsetOutput extends RuleOutput<string[]> {
102
111
// }
103
112
// }
104
113
105
- for ( let i = 0 , len = this . $preprocessed . length ; i < len ; i ++ ) {
106
- const domain = this . $preprocessed [ i ] ;
107
- if ( domain [ 0 ] === '.' ) {
108
- results . push ( `||${ domain . slice ( 1 ) } ^` ) ;
109
- } else {
110
- results . push ( `|${ domain } ^` ) ;
111
- }
112
- }
113
-
114
114
for ( const wildcard of this . domainWildcard ) {
115
115
const processed = wildcard . replaceAll ( '?' , '*' ) ;
116
116
if ( processed . startsWith ( '*.' ) ) {
117
- results . push ( `||${ processed . slice ( 2 ) } ^` ) ;
117
+ this . $adguardhome . push ( `||${ processed . slice ( 2 ) } ^` ) ;
118
118
} else {
119
- results . push ( `|${ processed } ^` ) ;
119
+ this . $adguardhome . push ( `|${ processed } ^` ) ;
120
120
}
121
121
}
122
122
123
123
for ( const keyword of this . domainKeywords ) {
124
124
// Use regex to match keyword
125
- results . push ( `/${ escapeStringRegexp ( keyword ) } /` ) ;
125
+ this . $adguardhome . push ( `/${ escapeStringRegexp ( keyword ) } /` ) ;
126
126
}
127
127
128
128
for ( const ipGroup of [ this . ipcidr , this . ipcidrNoResolve ] ) {
129
129
for ( const ipcidr of ipGroup ) {
130
130
if ( ipcidr . endsWith ( '/32' ) ) {
131
- results . push ( `||${ ipcidr . slice ( 0 , - 3 ) } ` ) ;
131
+ this . $adguardhome . push ( `||${ ipcidr . slice ( 0 , - 3 ) } ` ) ;
132
132
/* else if (ipcidr.endsWith('.0/24')) {
133
133
results.push(`||${ipcidr.slice(0, -6)}.*`);
134
134
} */
135
135
} else {
136
- results . push ( `||${ ipcidr } ^` ) ;
136
+ this . $adguardhome . push ( `||${ ipcidr } ^` ) ;
137
137
}
138
138
}
139
139
}
140
140
for ( const ipGroup of [ this . ipcidr6 , this . ipcidr6NoResolve ] ) {
141
141
for ( const ipcidr of ipGroup ) {
142
142
if ( ipcidr . endsWith ( '/128' ) ) {
143
- results . push ( `||${ ipcidr . slice ( 0 , - 4 ) } ` ) ;
143
+ this . $adguardhome . push ( `||${ ipcidr . slice ( 0 , - 4 ) } ` ) ;
144
144
} else {
145
- results . push ( `||${ ipcidr } ` ) ;
145
+ this . $adguardhome . push ( `||${ ipcidr } ` ) ;
146
146
}
147
147
}
148
148
}
149
149
150
- return results ;
150
+ return this . $adguardhome ;
151
151
}
152
152
}
0 commit comments