Created
January 22, 2024 08:25
-
-
Save John-Chan/d6cdcd75d108c3f4f146ed1f74b103f5 to your computer and use it in GitHub Desktop.
Clash-Verg-Rev Profiles Enhanced Mode 增强模式脚本
This file contains hidden or 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
| // This script used to enhance clash rules | |
| // rules maintained by yourself | |
| const local_rules = [ | |
| "DOMAIN-SUFFIX,example.local,DIRECT,no-resolve" | |
| ]; | |
| // copy from https://github.com/Loyalsoldier/clash-rules | |
| const extra_rules = [ | |
| "RULE-SET,applications,DIRECT", | |
| "DOMAIN,clash.razord.top,DIRECT", | |
| "DOMAIN,yacd.haishan.me,DIRECT", | |
| "RULE-SET,private,DIRECT", | |
| "RULE-SET,reject,REJECT", | |
| "RULE-SET,icloud,DIRECT", | |
| "RULE-SET,apple,DIRECT", | |
| "RULE-SET,google,DIRECT", | |
| "RULE-SET,proxy,PROXY", | |
| "RULE-SET,direct,DIRECT", | |
| "RULE-SET,lancidr,DIRECT", | |
| "RULE-SET,cncidr,DIRECT", | |
| "RULE-SET,telegramcidr,PROXY", | |
| "GEOIP,LAN,DIRECT", | |
| "GEOIP,CN,DIRECT", | |
| "MATCH,PROXY" | |
| ]; | |
| // copy from https://github.com/Loyalsoldier/clash-rules | |
| const extra_providers = { | |
| "reject": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt", | |
| "path": "./ruleset/reject.yaml", | |
| "interval": 86400 | |
| }, | |
| "icloud": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/icloud.txt", | |
| "path": "./ruleset/icloud.yaml", | |
| "interval": 86400 | |
| }, | |
| "apple": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/apple.txt", | |
| "path": "./ruleset/apple.yaml", | |
| "interval": 86400 | |
| }, | |
| "google": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/google.txt", | |
| "path": "./ruleset/google.yaml", | |
| "interval": 86400 | |
| }, | |
| "proxy": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt", | |
| "path": "./ruleset/proxy.yaml", | |
| "interval": 86400 | |
| }, | |
| "direct": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt", | |
| "path": "./ruleset/direct.yaml", | |
| "interval": 86400 | |
| }, | |
| "private": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/private.txt", | |
| "path": "./ruleset/private.yaml", | |
| "interval": 86400 | |
| }, | |
| "gfw": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/gfw.txt", | |
| "path": "./ruleset/gfw.yaml", | |
| "interval": 86400 | |
| }, | |
| "tld-not-cn": { | |
| "type": "http", | |
| "behavior": "domain", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/tld-not-cn.txt", | |
| "path": "./ruleset/tld-not-cn.yaml", | |
| "interval": 86400 | |
| }, | |
| "telegramcidr": { | |
| "type": "http", | |
| "behavior": "ipcidr", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/telegramcidr.txt", | |
| "path": "./ruleset/telegramcidr.yaml", | |
| "interval": 86400 | |
| }, | |
| "cncidr": { | |
| "type": "http", | |
| "behavior": "ipcidr", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/cncidr.txt", | |
| "path": "./ruleset/cncidr.yaml", | |
| "interval": 86400 | |
| }, | |
| "lancidr": { | |
| "type": "http", | |
| "behavior": "ipcidr", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/lancidr.txt", | |
| "path": "./ruleset/lancidr.yaml", | |
| "interval": 86400 | |
| }, | |
| "applications": { | |
| "type": "http", | |
| "behavior": "classical", | |
| "url": "https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/applications.txt", | |
| "path": "./ruleset/applications.yaml", | |
| "interval": 86400 | |
| } | |
| }; | |
| function apply_rules(params){ | |
| /// merge rule-providers | |
| const original_providers = params['rule-providers'] || {}; | |
| params['rule-providers'] = { ...original_providers, ...extra_providers}; | |
| /// append rules | |
| const original_rules = params['rules'] || []; | |
| params['rules'] = [...local_rules, ...original_rules,...extra_rules]; | |
| return params; | |
| } | |
| function enhance(params){ | |
| console.log(`check rules`); | |
| // if no proxies,skip | |
| let proxy_names = (params['proxies'] || []).map((o) => o['name']).filter((str) => str !== ''); | |
| if(proxy_names.length === 0){ | |
| console.log('proxies is empty, skip'); | |
| return params; | |
| } | |
| console.log(`found ${proxy_names.length} proxies,add rules`); | |
| /// makesure the 'PROXY' proxy group exists | |
| let default_group = (params['proxy-groups'] || []).find((o) => o['name'] ==='PROXY'); | |
| if(!default_group){ | |
| default_group = { name: "PROXY", type: "select", proxies: proxy_names }; | |
| params['proxy-groups'] = [default_group,...params['proxy-groups']]; | |
| } | |
| return apply_rules(params); | |
| } | |
| // The entry function used by clash-verg-rev | |
| function main(params) { | |
| //console.log(JSON.stringify(params)); | |
| try{ | |
| const ret = enhance(params); | |
| console.log('process completed'); | |
| return ret; | |
| }catch(e){ | |
| console.log(`error: ${JSON.stringify(e)}`); | |
| return params; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment