-
-
Save gaecoli/1a80092de9afb7539a683414b69449f5 to your computer and use it in GitHub Desktop.
Clash Parser Add Custom Rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _rules = [ | |
'IP-CIDR,172.31.0.0/16,OfficeNet', | |
'IP-CIDR,172.30.0.0/16,OfficeNet', | |
'DOMAIN-SUFFIX,python.org,Proxy', | |
'DOMAIN-SUFFIX,readthedocs.io,Proxy', | |
'DOMAIN-SUFFIX,discourse-cdn.com,Proxy', | |
'DOMAIN-SUFFIX,13.225.143.34,Proxy', | |
] | |
const _proxies = [ | |
{ | |
name: 'officeAR', | |
type: 'ss', | |
server: 'x.x.x.x', | |
port: 8888, | |
udp: true, | |
cipher: 'aes-256-cfb', | |
password: 'password', | |
}, | |
] | |
const _groups = [ | |
{ | |
name: 'OfficeNet', | |
type: 'select', | |
proxies: [ | |
'officeAR', 'REJECT', 'DIRECT' | |
] | |
}, | |
] | |
module.exports.parse = (raw, {yaml, notify}) => { | |
notify("Clash for windows", "profile has been modified.", true) | |
const rawObj = yaml.parse(raw) | |
const {'rules': rules = [], 'proxy-groups': groups = [], 'proxies': proxies = []} = rawObj | |
delete rawObj['rules'] | |
delete rawObj['proxy-groups'] | |
delete rawObj['proxies'] | |
if (_rules.length > 0) { | |
let lastProxyIndex = rules.length - 1 | |
while (lastProxyIndex > 0 && !rules[lastProxyIndex].endsWith(",Proxy")) --lastProxyIndex; | |
rules.splice(lastProxyIndex + 1, 1, ..._rules) | |
} | |
if (_proxies.length > 0) { | |
proxies.push(..._proxies) | |
} | |
if (_groups.length > 0) { | |
groups.push(..._groups) | |
} | |
return yaml.stringify({...rawObj, proxies, 'proxy-groups': groups, rules}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment