mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 05:40:29 +08:00
113 lines
4.3 KiB
JavaScript
113 lines
4.3 KiB
JavaScript
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const adguardhome=require('../../../_virtual/adguardhome.cjs'),require$$0=require('foxts/escape-string-regexp'),base=require('./base.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs');var hasRequiredAdguardhome;
|
|
|
|
function requireAdguardhome () {
|
|
if (hasRequiredAdguardhome) return adguardhome.__exports;
|
|
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.__require();
|
|
const _noop = require$$2;
|
|
const _misc = /*@__PURE__*/ misc.__require();
|
|
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.__exports));
|
|
return adguardhome.__exports;
|
|
}exports.__require=requireAdguardhome; |