Chore: maintainance
Some checks are pending
Build / Build (push) Waiting to run
Build / Diff output (push) Blocked by required conditions
Build / Deploy to Cloudflare Pages (push) Blocked by required conditions
Build / Deploy to GitHub and GitLab (push) Blocked by required conditions

This commit is contained in:
SukkaW
2025-02-07 17:52:36 +08:00
parent 6a7f7cc5e8
commit d354c5e988
252 changed files with 21086 additions and 124 deletions

View File

@@ -0,0 +1,113 @@
'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;

View File

@@ -0,0 +1,63 @@
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const base=require('../../../_virtual/base2.cjs'),createFile=require('../create-file.cjs');var hasRequiredBase;
function requireBase () {
if (hasRequiredBase) return base.__exports;
hasRequiredBase = 1;
(function (exports) {
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "BaseWriteStrategy", {
enumerable: true,
get: function() {
return BaseWriteStrategy;
}
});
const _createfile = /*@__PURE__*/ createFile.__require();
class BaseWriteStrategy {
outputDir;
/**
* Sometimes a ruleset will create extra files (e.g. reject-url-regex w/ mitm.sgmodule),
* and doesn't share the same filename and id. This property is used to overwrite the filename.
*/ overwriteFilename;
withFilename(filename) {
this.overwriteFilename = filename;
return this;
}
constructor(outputDir){
this.outputDir = outputDir;
this.overwriteFilename = null;
}
static domainWildCardToRegex = (domain)=>{
let result = '^';
for(let i = 0, len = domain.length; i < len; i++){
switch(domain[i]){
case '.':
result += String.raw`\.`;
break;
case '*':
result += String.raw`[\w.-]*?`;
break;
case '?':
result += String.raw`[\w.-]`;
break;
default:
result += domain[i];
}
}
result += '$';
return result;
};
output(span, title, description, date, filePath) {
if (!this.result) {
return;
}
return (0, _createfile.compareAndWriteFile)(span, this.withPadding(title, description, date, this.result), filePath);
}
get content() {
return this.result;
}
}
} (base.__exports));
return base.__exports;
}exports.__require=requireBase;

View File

@@ -0,0 +1,172 @@
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const clash=require('../../../_virtual/clash.cjs'),require$$0=require('foxts/append-set-elements-to-array'),base=require('./base.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs'),dir=require('../../constants/dir.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs');var hasRequiredClash;
function requireClash () {
if (hasRequiredClash) return clash.__exports;
hasRequiredClash = 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, {
ClashClassicRuleSet: function() {
return ClashClassicRuleSet;
},
ClashDomainSet: function() {
return ClashDomainSet;
},
ClashIPSet: function() {
return ClashIPSet;
}
});
const _appendsetelementstoarray = require$$0;
const _base = /*@__PURE__*/ base.__require();
const _noop = require$$2;
const _misc = /*@__PURE__*/ misc.__require();
const _dir = /*@__PURE__*/ dir.__require();
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
class ClashDomainSet extends _base.BaseWriteStrategy {
outputDir;
// readonly type = 'domainset';
fileExtension;
type;
result;
constructor(outputDir = _dir.OUTPUT_CLASH_DIR){
super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'domainset', this.result = [
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
], this.withPadding = _misc.withBannerArray, this.writeDomainKeywords = _noop.noop, this.writeDomainWildcards = _noop.noop, this.writeUserAgents = _noop.noop, this.writeProcessNames = _noop.noop, this.writeProcessPaths = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeIpCidrs = _noop.noop, this.writeIpCidr6s = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeSourceIpCidrs = _noop.noop, this.writeSourcePorts = _noop.noop, this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop;
}
withPadding;
writeDomain(domain) {
this.result.push(domain);
}
writeDomainSuffix(domain) {
this.result.push('+.' + domain);
}
writeDomainKeywords;
writeDomainWildcards;
writeUserAgents;
writeProcessNames;
writeProcessPaths;
writeUrlRegexes;
writeIpCidrs;
writeIpCidr6s;
writeGeoip;
writeIpAsns;
writeSourceIpCidrs;
writeSourcePorts;
writeDestinationPorts;
writeOtherRules;
}
class ClashIPSet extends _base.BaseWriteStrategy {
outputDir;
// readonly type = 'domainset';
fileExtension;
type;
result;
constructor(outputDir = _dir.OUTPUT_CLASH_DIR){
super(outputDir), this.outputDir = outputDir, this.fileExtension = 'txt', this.type = 'ip', this.result = [], this.withPadding = _misc.withBannerArray, this.writeDomain = (0, _misc.notSupported)('writeDomain'), this.writeDomainSuffix = (0, _misc.notSupported)('writeDomainSuffix'), this.writeDomainKeywords = (0, _misc.notSupported)('writeDomainKeywords'), this.writeDomainWildcards = (0, _misc.notSupported)('writeDomainWildcards'), this.writeUserAgents = (0, _misc.notSupported)('writeUserAgents'), this.writeProcessNames = (0, _misc.notSupported)('writeProcessNames'), this.writeProcessPaths = (0, _misc.notSupported)('writeProcessPaths'), this.writeUrlRegexes = (0, _misc.notSupported)('writeUrlRegexes'), this.writeGeoip = (0, _misc.notSupported)('writeGeoip'), this.writeIpAsns = (0, _misc.notSupported)('writeIpAsns'), this.writeSourceIpCidrs = (0, _misc.notSupported)('writeSourceIpCidrs'), this.writeSourcePorts = (0, _misc.notSupported)('writeSourcePorts'), this.writeDestinationPorts = _noop.noop, this.writeOtherRules = _noop.noop;
}
withPadding;
writeDomain;
writeDomainSuffix;
writeDomainKeywords;
writeDomainWildcards;
writeUserAgents;
writeProcessNames;
writeProcessPaths;
writeUrlRegexes;
writeIpCidrs(ipCidr) {
(0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr);
}
writeIpCidr6s(ipCidr6) {
(0, _appendarrayinplace.appendArrayInPlace)(this.result, ipCidr6);
}
writeGeoip;
writeIpAsns;
writeSourceIpCidrs;
writeSourcePorts;
writeDestinationPorts;
writeOtherRules;
}
class ClashClassicRuleSet extends _base.BaseWriteStrategy {
type;
outputDir;
fileExtension;
result;
constructor(type/* | (string & {}) */ , outputDir = _dir.OUTPUT_CLASH_DIR){
super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'txt', this.result = [
'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
], this.withPadding = _misc.withBannerArray, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeOtherRules = _noop.noop;
}
withPadding;
writeDomain(domain) {
this.result.push('DOMAIN,' + domain);
}
writeDomainSuffix(domain) {
this.result.push('DOMAIN-SUFFIX,' + domain);
}
writeDomainKeywords(keyword) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`);
}
writeDomainWildcards(wildcard) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-REGEX,${ClashClassicRuleSet.domainWildCardToRegex(i)}`);
}
writeUserAgents;
writeProcessNames(processName) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`);
}
writeProcessPaths(processPath) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-PATH,${i}`);
}
writeUrlRegexes;
writeIpCidrs(ipCidr, noResolve) {
for(let i = 0, len = ipCidr.length; i < len; i++){
this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`);
}
}
writeIpCidr6s(ipCidr6, noResolve) {
for(let i = 0, len = ipCidr6.length; i < len; i++){
this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`);
}
}
writeGeoip(geoip, noResolve) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`);
}
writeIpAsns(asns, noResolve) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`);
}
writeSourceIpCidrs(sourceIpCidr) {
for(let i = 0, len = sourceIpCidr.length; i < len; i++){
const value = sourceIpCidr[i];
if (value.includes('/')) {
this.result.push(`SRC-IP-CIDR,${value}`);
continue;
}
const v = (0, _misc.fastIpVersion)(value);
if (v === 4) {
this.result.push(`SRC-IP-CIDR,${value}/32`);
continue;
}
if (v === 6) {
this.result.push(`SRC-IP-CIDR6,${value}/128`);
continue;
}
}
}
writeSourcePorts(port) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`);
}
writeDestinationPorts(port) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DST-PORT,${i}`);
}
writeOtherRules;
}
} (clash.__exports));
return clash.__exports;
}exports.__require=requireClash;

View File

@@ -0,0 +1,121 @@
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const singbox=require('../../../_virtual/singbox.cjs'),base=require('./base.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs'),require$$2=require('foxts/noop'),misc=require('../misc.cjs'),require$$4=require('json-stringify-pretty-compact'),dir=require('../../constants/dir.cjs');var hasRequiredSingbox;
function requireSingbox () {
if (hasRequiredSingbox) return singbox.__exports;
hasRequiredSingbox = 1;
(function (exports) {
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "SingboxSource", {
enumerable: true,
get: function() {
return SingboxSource;
}
});
const _base = /*@__PURE__*/ base.__require();
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
const _noop = require$$2;
const _misc = /*@__PURE__*/ misc.__require();
const _jsonstringifyprettycompact = /*#__PURE__*/ _interop_require_default(require$$4);
const _dir = /*@__PURE__*/ dir.__require();
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
class SingboxSource extends _base.BaseWriteStrategy {
type;
outputDir;
fileExtension;
static jsonToLines = (json)=>(0, _jsonstringifyprettycompact.default)(json).split('\n');
singbox;
get result() {
return SingboxSource.jsonToLines({
version: 2,
rules: [
this.singbox
]
});
}
constructor(/** Since sing-box only have one format that does not reflect type, we need to specify it */ type/* | (string & {}) */ , outputDir = _dir.OUTPUT_SINGBOX_DIR){
super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'json', this.singbox = {
domain: [
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
],
domain_suffix: [
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
]
}, this.withPadding = _misc.withIdentityContent, this.writeUserAgents = _noop.noop, this.writeUrlRegexes = _noop.noop, this.writeGeoip = _noop.noop, this.writeIpAsns = _noop.noop, this.writeOtherRules = _noop.noop;
}
withPadding;
writeDomain(domain) {
this.singbox.domain.push(domain);
}
writeDomainSuffix(domain) {
this.singbox.domain_suffix.push(domain);
}
writeDomainKeywords(keyword) {
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_keyword ??= [], Array.from(keyword));
}
writeDomainWildcards(wildcard) {
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.domain_regex ??= [], Array.from(wildcard, SingboxSource.domainWildCardToRegex));
}
writeUserAgents;
writeProcessNames(processName) {
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_name ??= [], Array.from(processName));
}
writeProcessPaths(processPath) {
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.process_path ??= [], Array.from(processPath));
}
writeUrlRegexes;
writeIpCidrs(ipCidr) {
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr);
}
writeIpCidr6s(ipCidr6) {
(0, _appendarrayinplace.appendArrayInPlace)(this.singbox.ip_cidr ??= [], ipCidr6);
}
writeGeoip;
writeIpAsns;
writeSourceIpCidrs(sourceIpCidr) {
this.singbox.source_ip_cidr ??= [];
for(let i = 0, len = sourceIpCidr.length; i < len; i++){
const value = sourceIpCidr[i];
if (value.includes('/')) {
this.singbox.source_ip_cidr.push(value);
continue;
}
const v = (0, _misc.fastIpVersion)(value);
if (v === 4) {
this.singbox.source_ip_cidr.push(`${value}/32`);
continue;
}
if (v === 6) {
this.singbox.source_ip_cidr.push(`${value}/128`);
continue;
}
}
}
writeSourcePorts(port) {
this.singbox.source_port ??= [];
for (const i of port){
const tmp = Number(i);
if (!Number.isNaN(tmp)) {
this.singbox.source_port.push(tmp);
}
}
}
writeDestinationPorts(port) {
this.singbox.port ??= [];
for (const i of port){
const tmp = Number(i);
if (!Number.isNaN(tmp)) {
this.singbox.port.push(tmp);
}
}
}
writeOtherRules;
}
} (singbox.__exports));
return singbox.__exports;
}exports.__require=requireSingbox;

View File

@@ -0,0 +1,246 @@
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const surge=require('../../../_virtual/surge.cjs'),require$$0=require('foxts/append-set-elements-to-array'),base=require('./base.cjs'),appendArrayInPlace=require('../append-array-in-place.cjs'),require$$2=require('foxts/noop'),require$$2$1=require('foxts/is-probably-ip'),require$$0$1=require('picocolors'),normalizeDomain=require('../normalize-domain.cjs'),dir=require('../../constants/dir.cjs'),misc=require('../misc.cjs');var hasRequiredSurge;
function requireSurge () {
if (hasRequiredSurge) return surge.__exports;
hasRequiredSurge = 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, {
SurgeDomainSet: function() {
return SurgeDomainSet;
},
SurgeMitmSgmodule: function() {
return SurgeMitmSgmodule;
},
SurgeRuleSet: function() {
return SurgeRuleSet;
}
});
const _appendsetelementstoarray = require$$0;
const _base = /*@__PURE__*/ base.__require();
const _appendarrayinplace = /*@__PURE__*/ appendArrayInPlace.__require();
const _noop = require$$2;
const _isprobablyip = require$$2$1;
const _picocolors = /*#__PURE__*/ _interop_require_default(require$$0$1);
const _normalizedomain = /*@__PURE__*/ normalizeDomain.__require();
const _dir = /*@__PURE__*/ dir.__require();
const _misc = /*@__PURE__*/ misc.__require();
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
class SurgeDomainSet extends _base.BaseWriteStrategy {
// readonly type = 'domainset';
fileExtension = 'conf';
type = 'domainset';
result = [
'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
];
constructor(outputDir = _dir.OUTPUT_SURGE_DIR){
super(outputDir);
}
withPadding = _misc.withBannerArray;
writeDomain(domain) {
this.result.push(domain);
}
writeDomainSuffix(domain) {
this.result.push('.' + domain);
}
writeDomainKeywords = _noop.noop;
writeDomainWildcards = _noop.noop;
writeUserAgents = _noop.noop;
writeProcessNames = _noop.noop;
writeProcessPaths = _noop.noop;
writeUrlRegexes = _noop.noop;
writeIpCidrs = _noop.noop;
writeIpCidr6s = _noop.noop;
writeGeoip = _noop.noop;
writeIpAsns = _noop.noop;
writeSourceIpCidrs = _noop.noop;
writeSourcePorts = _noop.noop;
writeDestinationPorts = _noop.noop;
writeOtherRules = _noop.noop;
}
class SurgeRuleSet extends _base.BaseWriteStrategy {
type;
outputDir;
fileExtension;
result;
constructor(/** Surge RULE-SET can be both ip or non_ip, so this needs to be specified */ type, outputDir = _dir.OUTPUT_SURGE_DIR){
super(outputDir), this.type = type, this.outputDir = outputDir, this.fileExtension = 'conf', this.result = [
'DOMAIN,this_ruleset_is_made_by_sukkaw.ruleset.skk.moe'
], this.withPadding = _misc.withBannerArray;
}
withPadding;
writeDomain(domain) {
this.result.push('DOMAIN,' + domain);
}
writeDomainSuffix(domain) {
this.result.push('DOMAIN-SUFFIX,' + domain);
}
writeDomainKeywords(keyword) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, keyword, (i)=>`DOMAIN-KEYWORD,${i}`);
}
writeDomainWildcards(wildcard) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, wildcard, (i)=>`DOMAIN-WILDCARD,${i}`);
}
writeUserAgents(userAgent) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, userAgent, (i)=>`USER-AGENT,${i}`);
}
writeProcessNames(processName) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processName, (i)=>`PROCESS-NAME,${i}`);
}
writeProcessPaths(processPath) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, processPath, (i)=>`PROCESS-NAME,${i}`);
}
writeUrlRegexes(urlRegex) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, urlRegex, (i)=>`URL-REGEX,${i}`);
}
writeIpCidrs(ipCidr, noResolve) {
for(let i = 0, len = ipCidr.length; i < len; i++){
this.result.push(`IP-CIDR,${ipCidr[i]}${noResolve ? ',no-resolve' : ''}`);
}
}
writeIpCidr6s(ipCidr6, noResolve) {
for(let i = 0, len = ipCidr6.length; i < len; i++){
this.result.push(`IP-CIDR6,${ipCidr6[i]}${noResolve ? ',no-resolve' : ''}`);
}
}
writeGeoip(geoip, noResolve) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, geoip, (i)=>`GEOIP,${i}${noResolve ? ',no-resolve' : ''}`);
}
writeIpAsns(asns, noResolve) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, asns, (i)=>`IP-ASN,${i}${noResolve ? ',no-resolve' : ''}`);
}
writeSourceIpCidrs(sourceIpCidr) {
for(let i = 0, len = sourceIpCidr.length; i < len; i++){
this.result.push(`SRC-IP,${sourceIpCidr[i]}`);
}
}
writeSourcePorts(port) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`SRC-PORT,${i}`);
}
writeDestinationPorts(port) {
(0, _appendsetelementstoarray.appendSetElementsToArray)(this.result, port, (i)=>`DEST-PORT,${i}`);
}
writeOtherRules(rule) {
(0, _appendarrayinplace.appendArrayInPlace)(this.result, rule);
}
}
class SurgeMitmSgmodule extends _base.BaseWriteStrategy {
// readonly type = 'domainset';
fileExtension = 'sgmodule';
type = '';
rules = new Set();
get result() {
if (this.rules.size === 0) {
return null;
}
return [
'#!name=[Sukka] Surge Reject MITM',
`#!desc=为 URL Regex 规则组启用 MITM (size: ${this.rules.size})`,
'',
'[MITM]',
'hostname = %APPEND% ' + Array.from(this.rules).join(', ')
];
}
withPadding = _misc.withIdentityContent;
constructor(moduleName, outputDir = _dir.OUTPUT_MODULES_DIR){
super(outputDir);
this.withFilename(moduleName);
}
writeDomain = _noop.noop;
writeDomainSuffix = _noop.noop;
writeDomainKeywords = _noop.noop;
writeDomainWildcards = _noop.noop;
writeUserAgents = _noop.noop;
writeProcessNames = _noop.noop;
writeProcessPaths = _noop.noop;
writeUrlRegexes(urlRegexes) {
const urlRegexResults = [];
const parsedFailures = [];
const parsed = [];
for (let urlRegex of urlRegexes){
if (urlRegex.startsWith('http://') || urlRegex.startsWith('^http://')) {
continue;
}
if (urlRegex.startsWith('^https?://')) {
urlRegex = urlRegex.slice(10);
}
if (urlRegex.startsWith('^https://')) {
urlRegex = urlRegex.slice(9);
}
const potentialHostname = urlRegex.split('/')[0]// pre process regex
.replaceAll(String.raw`\.`, '.').replaceAll('.+', '*').replaceAll(/([a-z])\?/g, '($1|)')// convert regex to surge hostlist syntax
.replaceAll('([a-z])', '?').replaceAll(String.raw`\d`, '?').replaceAll(/\*+/g, '*');
let processed = [
potentialHostname
];
const matches = [
...potentialHostname.matchAll(/\((?:([^()|]+)\|)+([^()|]*)\)/g)
];
if (matches.length > 0) {
const replaceVariant = (combinations, fullMatch, options)=>{
const newCombinations = [];
combinations.forEach((combination)=>{
options.forEach((option)=>{
newCombinations.push(combination.replace(fullMatch, option));
});
});
return newCombinations;
};
for(let i = 0; i < matches.length; i++){
const match = matches[i];
const [_, ...options] = match;
processed = replaceVariant(processed, _, options);
}
}
urlRegexResults.push({
origin: potentialHostname,
processed
});
}
for (const i of urlRegexResults){
for (const processed of i.processed){
if ((0, _normalizedomain.normalizeDomain)(processed.replaceAll('*', 'a').replaceAll('?', 'b'))) {
parsed.push([
i.origin,
processed
]);
} else if (!(0, _isprobablyip.isProbablyIpv4)(processed)) {
parsedFailures.push([
i.origin,
processed
]);
}
}
}
if (parsedFailures.length > 0) {
console.error(_picocolors.default.bold('Parsed Failed'));
console.table(parsedFailures);
}
for(let i = 0, len = parsed.length; i < len; i++){
this.rules.add(parsed[i][1]);
}
}
writeIpCidrs = _noop.noop;
writeIpCidr6s = _noop.noop;
writeGeoip = _noop.noop;
writeIpAsns = _noop.noop;
writeSourceIpCidrs = _noop.noop;
writeSourcePorts = _noop.noop;
writeDestinationPorts = _noop.noop;
writeOtherRules = _noop.noop;
}
} (surge.__exports));
return surge.__exports;
}exports.__require=requireSurge;