mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Feat: AdGuard Home blocklist
This commit is contained in:
parent
c987b33ee2
commit
dc221f5269
@ -18,20 +18,23 @@ import { setAddFromArray } from './lib/set-add-from-array';
|
||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||
import { OUTPUT_INTERNAL_DIR, SOURCE_DIR } from './constants/dir';
|
||||
import { DomainsetOutput } from './lib/create-file';
|
||||
import { withBannerArray } from './lib/misc';
|
||||
|
||||
export const buildRejectDomainSet = task(require.main === module, __filename)(async (span) => {
|
||||
const rejectBaseDescription = [
|
||||
...SHARED_DESCRIPTION,
|
||||
'',
|
||||
'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining',
|
||||
'',
|
||||
'Build from:',
|
||||
...HOSTS.map(host => ` - ${host[0]}`),
|
||||
...DOMAIN_LISTS.map(domainList => ` - ${domainList[0]}`),
|
||||
...ADGUARD_FILTERS.map(filter => ` - ${Array.isArray(filter) ? filter[0] : filter}`)
|
||||
];
|
||||
|
||||
const rejectOutput = new DomainsetOutput(span, 'reject')
|
||||
.withTitle('Sukka\'s Ruleset - Reject Base')
|
||||
.withDescription([
|
||||
...SHARED_DESCRIPTION,
|
||||
'',
|
||||
'The domainset supports AD blocking, tracking protection, privacy protection, anti-phishing, anti-mining',
|
||||
'',
|
||||
'Build from:',
|
||||
...HOSTS.map(host => ` - ${host[0]}`),
|
||||
...DOMAIN_LISTS.map(domainList => ` - ${domainList[0]}`),
|
||||
...ADGUARD_FILTERS.map(filter => ` - ${Array.isArray(filter) ? filter[0] : filter}`)
|
||||
]);
|
||||
.withDescription(rejectBaseDescription);
|
||||
|
||||
const rejectExtraOutput = new DomainsetOutput(span, 'reject_extra')
|
||||
.withTitle('Sukka\'s Ruleset - Reject Extra')
|
||||
@ -156,6 +159,16 @@ export const buildRejectDomainSet = task(require.main === module, __filename)(as
|
||||
span,
|
||||
rejectDomainsStats,
|
||||
path.join(OUTPUT_INTERNAL_DIR, 'reject-stats.txt')
|
||||
),
|
||||
compareAndWriteFile(
|
||||
span,
|
||||
withBannerArray(
|
||||
'Sukka\'s Ruleset - Blocklist for AdGuardHome',
|
||||
rejectBaseDescription,
|
||||
new Date(),
|
||||
rejectOutput.adguardhome(filterRuleWhitelistDomainSets)
|
||||
),
|
||||
path.join(OUTPUT_INTERNAL_DIR, 'reject-adguardhome.txt')
|
||||
)
|
||||
]);
|
||||
});
|
||||
|
||||
@ -3,6 +3,7 @@ import createKeywordFilter from '../aho-corasick';
|
||||
import { buildParseDomainMap, sortDomains } from '../stable-sort-domain';
|
||||
import { RuleOutput } from './base';
|
||||
import type { SingboxSourceFormat } from '../singbox';
|
||||
import { appendArrayFromSet } from '../misc';
|
||||
|
||||
type Preprocessed = string[];
|
||||
|
||||
@ -86,4 +87,22 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
||||
}
|
||||
|
||||
mitmSgmodule = undefined;
|
||||
|
||||
adguardhome(whitelist: Set<string | `.${string}`>): string[] {
|
||||
const results: string[] = [];
|
||||
|
||||
// whitelist
|
||||
appendArrayFromSet(results, whitelist, i => (i[0] === '.' ? '@@||' + i.slice(1) + '^' : '@@|' + i + '^'));
|
||||
|
||||
for (let i = 0, len = this.$preprocessed.length; i < len; i++) {
|
||||
const domain = this.$preprocessed[i];
|
||||
if (domain[0] === '.') {
|
||||
results.push(`||${domain.slice(1)}^`);
|
||||
} else {
|
||||
results.push(`|${domain}^`);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user