mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Feat: support wildcard from adguard filter
This commit is contained in:
@@ -52,14 +52,12 @@ export class AdGuardHome extends BaseWriteStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
writeDomainWildcards(wildcards: Set<string>): void {
|
||||
for (const wildcard of wildcards) {
|
||||
const processed = wildcard.replaceAll('?', '*');
|
||||
if (processed.startsWith('*.')) {
|
||||
this.result.push(`||${processed.slice(2)}^`);
|
||||
} else {
|
||||
this.result.push(`|${processed}^`);
|
||||
}
|
||||
writeDomainWildcard(wildcard: string): void {
|
||||
const processed = wildcard.replaceAll('?', '*');
|
||||
if (processed.startsWith('*.')) {
|
||||
this.result.push(`||${processed.slice(2)}^`);
|
||||
} else {
|
||||
this.result.push(`|${processed}^`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export abstract class BaseWriteStrategy {
|
||||
abstract writeDomain(domain: string): void;
|
||||
abstract writeDomainSuffix(domain: string): void;
|
||||
abstract writeDomainKeywords(keyword: Set<string>): void;
|
||||
abstract writeDomainWildcards(wildcard: Set<string>): void;
|
||||
abstract writeDomainWildcard(wildcard: string): void;
|
||||
abstract writeUserAgents(userAgent: Set<string>): void;
|
||||
abstract writeProcessNames(processName: Set<string>): void;
|
||||
abstract writeProcessPaths(processPath: Set<string>): void;
|
||||
|
||||
@@ -30,7 +30,7 @@ export class ClashDomainSet extends BaseWriteStrategy {
|
||||
}
|
||||
|
||||
writeDomainKeywords = noop;
|
||||
writeDomainWildcards = noop;
|
||||
writeDomainWildcard = noop;
|
||||
writeUserAgents = noop;
|
||||
writeProcessNames = noop;
|
||||
writeProcessPaths = noop;
|
||||
@@ -64,7 +64,7 @@ export class ClashIPSet extends BaseWriteStrategy {
|
||||
writeDomain = notSupported('writeDomain');
|
||||
writeDomainSuffix = notSupported('writeDomainSuffix');
|
||||
writeDomainKeywords = notSupported('writeDomainKeywords');
|
||||
writeDomainWildcards = notSupported('writeDomainWildcards');
|
||||
writeDomainWildcard = notSupported('writeDomainWildcards');
|
||||
writeUserAgents = notSupported('writeUserAgents');
|
||||
writeProcessNames = notSupported('writeProcessNames');
|
||||
writeProcessPaths = notSupported('writeProcessPaths');
|
||||
@@ -111,8 +111,8 @@ export class ClashClassicRuleSet extends BaseWriteStrategy {
|
||||
appendSetElementsToArray(this.result, keyword, i => `DOMAIN-KEYWORD,${i}`);
|
||||
}
|
||||
|
||||
writeDomainWildcards(wildcard: Set<string>): void {
|
||||
appendSetElementsToArray(this.result, wildcard, i => `DOMAIN-REGEX,${ClashClassicRuleSet.domainWildCardToRegex(i)}`);
|
||||
writeDomainWildcard(wildcard: string): void {
|
||||
this.result.push(`DOMAIN-REGEX,${ClashClassicRuleSet.domainWildCardToRegex(wildcard)}`);
|
||||
}
|
||||
|
||||
writeUserAgents = noop;
|
||||
|
||||
@@ -14,6 +14,6 @@ export class LegacyClashPremiumClassicRuleSet extends ClashClassicRuleSet {
|
||||
super(type, outputDir);
|
||||
}
|
||||
|
||||
override writeDomainWildcards = noop;
|
||||
override writeDomainWildcard = noop;
|
||||
override writeIpAsns = noop;
|
||||
}
|
||||
|
||||
@@ -71,11 +71,9 @@ export class SingboxSource extends BaseWriteStrategy {
|
||||
);
|
||||
}
|
||||
|
||||
writeDomainWildcards(wildcard: Set<string>): void {
|
||||
appendArrayInPlace(
|
||||
this.singbox.domain_regex ??= [],
|
||||
Array.from(wildcard, SingboxSource.domainWildCardToRegex)
|
||||
);
|
||||
writeDomainWildcard(wildcard: string): void {
|
||||
this.singbox.domain_regex ??= [];
|
||||
this.singbox.domain_regex.push(SingboxSource.domainWildCardToRegex(wildcard));
|
||||
}
|
||||
|
||||
writeUserAgents = noop;
|
||||
|
||||
@@ -12,7 +12,7 @@ export class SurfboardRuleSet extends SurgeRuleSet {
|
||||
super(type, outputDir);
|
||||
}
|
||||
|
||||
override writeDomainWildcards = noop;
|
||||
override writeDomainWildcard = noop;
|
||||
override writeUserAgents = noop;
|
||||
override writeUrlRegexes = noop;
|
||||
override writeIpAsns = noop;
|
||||
|
||||
@@ -33,7 +33,7 @@ export class SurgeDomainSet extends BaseWriteStrategy {
|
||||
}
|
||||
|
||||
writeDomainKeywords = noop;
|
||||
writeDomainWildcards = noop;
|
||||
writeDomainWildcard = noop;
|
||||
writeUserAgents = noop;
|
||||
writeProcessNames = noop;
|
||||
writeProcessPaths = noop;
|
||||
@@ -78,8 +78,8 @@ export class SurgeRuleSet extends BaseWriteStrategy {
|
||||
appendSetElementsToArray(this.result, keyword, i => `DOMAIN-KEYWORD,${i}`);
|
||||
}
|
||||
|
||||
writeDomainWildcards(wildcard: Set<string>): void {
|
||||
appendSetElementsToArray(this.result, wildcard, i => `DOMAIN-WILDCARD,${i}`);
|
||||
writeDomainWildcard(wildcard: string): void {
|
||||
this.result.push(`DOMAIN-WILDCARD,${wildcard}`);
|
||||
}
|
||||
|
||||
writeUserAgents(userAgent: Set<string>): void {
|
||||
@@ -176,7 +176,7 @@ export class SurgeMitmSgmodule extends BaseWriteStrategy {
|
||||
writeDomainSuffix = noop;
|
||||
|
||||
writeDomainKeywords = noop;
|
||||
writeDomainWildcards = noop;
|
||||
writeDomainWildcard = noop;
|
||||
writeUserAgents = noop;
|
||||
writeProcessNames = noop;
|
||||
writeProcessPaths = noop;
|
||||
|
||||
Reference in New Issue
Block a user