mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 13:50:29 +08:00
159 lines
5.5 KiB
JavaScript
159 lines
5.5 KiB
JavaScript
'use strict';const require$$0=require('foxts/escape-string-regexp'),base=require('./base.C13YY5P3.cjs'),require$$2=require('foxts/noop'),misc=require('./misc.BpcQjda1.cjs');var domainset = {};var adguardhome = {};var hasRequiredAdguardhome;
|
|
|
|
function requireAdguardhome () {
|
|
if (hasRequiredAdguardhome) return adguardhome;
|
|
hasRequiredAdguardhome = 1;
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "AdGuardHome", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return AdGuardHome;
|
|
}
|
|
});
|
|
const _escapestringregexp = require$$0;
|
|
const _base = /*@__PURE__*/ base.d();
|
|
const _noop = require$$2;
|
|
const _misc = /*@__PURE__*/ misc.r();
|
|
class AdGuardHome extends _base.BaseWriteStrategy {
|
|
// readonly type = 'domainset';
|
|
fileExtension = 'txt';
|
|
type = '';
|
|
result = [];
|
|
// eslint-disable-next-line @typescript-eslint/class-methods-use-this -- abstract method
|
|
withPadding(title, description, date, content) {
|
|
return [
|
|
`! Title: ${title}`,
|
|
'! Last modified: ' + date.toUTCString(),
|
|
'! Expires: 6 hours',
|
|
'! License: https://github.com/SukkaW/Surge/blob/master/LICENSE',
|
|
'! Homepage: https://github.com/SukkaW/Surge',
|
|
`! Description: ${description.join(' ')}`,
|
|
'!',
|
|
...content,
|
|
'! EOF'
|
|
];
|
|
}
|
|
writeDomain(domain) {
|
|
this.result.push(`|${domain}^`);
|
|
}
|
|
// const whitelistArray = sortDomains(Array.from(whitelist));
|
|
// for (let i = 0, len = whitelistArray.length; i < len; i++) {
|
|
// const domain = whitelistArray[i];
|
|
// if (domain[0] === '.') {
|
|
// results.push(`@@||${domain.slice(1)}^`);
|
|
// } else {
|
|
// results.push(`@@|${domain}^`);
|
|
// }
|
|
// }
|
|
writeDomainSuffix(domain) {
|
|
this.result.push(`||${domain}^`);
|
|
}
|
|
writeDomainKeywords(keywords) {
|
|
for (const keyword of keywords){
|
|
// Use regex to match keyword
|
|
this.result.push(`/${(0, _escapestringregexp.escapeStringRegexp)(keyword)}/`);
|
|
}
|
|
}
|
|
writeDomainWildcards(wildcards) {
|
|
for (const wildcard of wildcards){
|
|
const processed = wildcard.replaceAll('?', '*');
|
|
if (processed.startsWith('*.')) {
|
|
this.result.push(`||${processed.slice(2)}^`);
|
|
} else {
|
|
this.result.push(`|${processed}^`);
|
|
}
|
|
}
|
|
}
|
|
writeUserAgents = _noop.noop;
|
|
writeProcessNames = _noop.noop;
|
|
writeProcessPaths = _noop.noop;
|
|
writeUrlRegexes = _noop.noop;
|
|
writeIpCidrs(ipGroup, noResolve) {
|
|
if (noResolve) {
|
|
// When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked
|
|
// So we can't do noResolve
|
|
return;
|
|
}
|
|
for (const ipcidr of ipGroup){
|
|
if (ipcidr.endsWith('/32')) {
|
|
this.result.push(`||${ipcidr.slice(0, -3)}`);
|
|
/* else if (ipcidr.endsWith('.0/24')) {
|
|
results.push(`||${ipcidr.slice(0, -6)}.*`);
|
|
} */ } else {
|
|
this.result.push(`||${ipcidr}^`);
|
|
}
|
|
}
|
|
}
|
|
writeIpCidr6s(ipGroup, noResolve) {
|
|
if (noResolve) {
|
|
// When IP is provided to AdGuardHome, any domain resolve to those IP will be blocked
|
|
// So we can't do noResolve
|
|
return;
|
|
}
|
|
for (const ipcidr of ipGroup){
|
|
if (ipcidr.endsWith('/128')) {
|
|
this.result.push(`||${ipcidr.slice(0, -4)}`);
|
|
} else {
|
|
this.result.push(`||${ipcidr}`);
|
|
}
|
|
}
|
|
}
|
|
writeGeoip = (0, _misc.notSupported)('writeGeoip');
|
|
writeIpAsns = (0, _misc.notSupported)('writeIpAsns');
|
|
writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs');
|
|
writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts');
|
|
writeDestinationPorts = _noop.noop;
|
|
writeOtherRules = _noop.noop;
|
|
}
|
|
} (adguardhome));
|
|
return adguardhome;
|
|
}var hasRequiredDomainset;
|
|
|
|
function requireDomainset () {
|
|
if (hasRequiredDomainset) return domainset;
|
|
hasRequiredDomainset = 1;
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
AdGuardHomeOutput: function() {
|
|
return AdGuardHomeOutput;
|
|
},
|
|
DomainsetOutput: function() {
|
|
return DomainsetOutput;
|
|
}
|
|
});
|
|
const _adguardhome = /*@__PURE__*/ requireAdguardhome();
|
|
const _clash = /*@__PURE__*/ base.c();
|
|
const _singbox = /*@__PURE__*/ base.f();
|
|
const _surge = /*@__PURE__*/ base.e();
|
|
const _base = /*@__PURE__*/ base.b();
|
|
class DomainsetOutput extends _base.FileOutput {
|
|
strategies = [
|
|
new _surge.SurgeDomainSet(),
|
|
new _clash.ClashDomainSet(),
|
|
new _singbox.SingboxSource('domainset')
|
|
];
|
|
}
|
|
class AdGuardHomeOutput extends _base.FileOutput {
|
|
strategies;
|
|
constructor(span, id, outputDir){
|
|
super(span, id);
|
|
this.strategies = [
|
|
new _adguardhome.AdGuardHome(outputDir)
|
|
];
|
|
}
|
|
}
|
|
} (domainset));
|
|
return domainset;
|
|
}exports.r=requireDomainset; |