function main(config) { if (!config.proxies) return config; // 创建一个新的数组用于存储 name 包含 "香港"、"日本" 和 "美国" 的 proxy 的名称 let allProxies = []; let hongKongProxies = []; let taiwanProxies = []; let japanProxies = []; let singaporeProxies = []; let koreaProxies = []; let americaProxies = []; config.proxies.forEach((proxy) => { // 设置 WebSocket 选项 if ( proxy.network === "ws" && (proxy["ws-path"] || proxy["ws-headers"]) ) { const opts = (proxy["ws-opts"] = proxy["ws-opts"] || {}); opts.path = proxy["ws-path"]; opts.headers = proxy["ws-headers"]; delete proxy["ws-path"]; delete proxy["ws-headers"]; } // 总是将代理名称加入到所有代理列表中 allProxies.push(proxy.name); // 通过正则表达式匹配来简化逻辑,一次性处理所有地区的代理 const regionRegexMap = [ { regex: /港/, exclude: /3x|X5/, proxiesList: hongKongProxies }, { regex: /台|湾/, proxiesList: taiwanProxies }, { regex: /日|东京/, proxiesList: japanProxies }, { regex: /新加坡|坡/, proxiesList: singaporeProxies }, { regex: /韩|首尔/, proxiesList: koreaProxies }, { regex: /美/, proxiesList: americaProxies }, ]; regionRegexMap.forEach(({ regex, exclude, proxiesList }) => { if ( regex.test(proxy.name) && (!exclude || !exclude.test(proxy.name)) ) { proxiesList.push(proxy.name); } }); }); // 为每个地区代理数组添加 "DIRECT",如果数组为空 [ hongKongProxies, taiwanProxies, japanProxies, singaporeProxies, koreaProxies, americaProxies, ].forEach((proxiesList) => { if (proxiesList.length === 0) { proxiesList.push("DIRECT"); } }); // 创建一个新的 proxy-groups 数组 const newProxyGroups = [ { name: "代理节点", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/Proxy.png", type: "select", proxies: [ "香港节点", "台湾节点", "日本节点", "星洲节点", "韩国节点", "美国节点", "手动选择", ], }, { name: "手动选择", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/Static.png", type: "select", proxies: allProxies, }, { name: "香港节点", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/Hong_Kong.png", interval: 1200, lazy: true, tolerance: 30, type: "url-test", url: "http://www.gstatic.com/generate_204", proxies: hongKongProxies, }, { name: "台湾节点", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/Taiwan.png", interval: 1200, lazy: true, tolerance: 30, type: "url-test", url: "http://www.gstatic.com/generate_204", proxies: taiwanProxies, }, { name: "日本节点", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/Japan.png", interval: 1200, lazy: true, tolerance: 30, type: "url-test", url: "http://www.gstatic.com/generate_204", proxies: japanProxies, }, { name: "星洲节点", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/Singapore.png", interval: 1200, lazy: true, tolerance: 30, type: "url-test", url: "http://www.gstatic.com/generate_204", proxies: singaporeProxies, }, { name: "韩国节点", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/Korea.png", interval: 1200, lazy: true, tolerance: 30, type: "url-test", url: "http://www.gstatic.com/generate_204", proxies: koreaProxies, }, { name: "美国节点", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/United_States.png", interval: 1200, lazy: true, tolerance: 30, type: "url-test", url: "http://www.gstatic.com/generate_204", proxies: americaProxies, }, { name: "OneDrive", icon: "https://fastly.jsdelivr.net/gh/Koolson/Qure/IconSet/Color/OneDrive.png", type: "select", proxies: ["DIRECT", "代理节点"], }, ]; // 将新的 proxy-groups 数组设置为 config 对象的 proxy-groups 属性 config["proxy-groups"] = newProxyGroups; // 替换 rules config.rules = [ "PROCESS-NAME,News,美国节点", "DOMAIN-SUFFIX,steamserver.net,DIRECT", "DOMAIN-SUFFIX,cm.steampowered.com,DIRECT", "RULE-SET,applenews,美国节点", "RULE-SET,claude,美国节点", "RULE-SET,gemini,美国节点", "RULE-SET,onedrive,OneDrive", "RULE-SET,openai,美国节点", "RULE-SET,scholar,DIRECT", "RULE-SET,steam,代理节点", "RULE-SET,streaming,美国节点", "RULE-SET,streamingdomain,美国节点", "RULE-SET,advertising,REJECT", "RULE-SET,advertisingdomain,REJECT", "RULE-SET,proxy,代理节点", "RULE-SET,proxydomain,代理节点", "RULE-SET,direct,DIRECT", "RULE-SET,lancidr,DIRECT", "GEOIP,LAN,DIRECT", "GEOIP,CN,DIRECT", "MATCH,代理节点", ]; // 替换 rule-providers config["rule-providers"] = { applenews: { // Apple News 相关的域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/AppleNews/AppleNews.yaml", path: "./ruleset/applenews.yaml", interval: 86400, }, claude: { // Claude 相关的域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Claude/Claude.yaml", path: "./ruleset/claude.yaml", interval: 86400, }, gemini: { // Gemini 相关的域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Gemini/Gemini.yaml", path: "./ruleset/gemini.yaml", interval: 86400, }, onedrive: { // OneDrive 域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/OneDrive/OneDrive.yaml", path: "./ruleset/onedrive.yaml", interval: 86400, }, openai: { // OpenAI 相关的域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/OpenAI/OpenAI.yaml", path: "./ruleset/openai.yaml", interval: 86400, }, scholar: { // 学术相关的域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Scholar/Scholar.yaml", path: "./ruleset/scholar.yaml", interval: 86400, }, steam: { // Steam 相关的域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Steam/Steam.yaml", path: "./ruleset/steam.yaml", interval: 86400, }, streaming: { // 流媒体相关的域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/GlobalMedia/GlobalMedia.yaml", path: "./ruleset/streaming.yaml", interval: 86400, }, streamingdomain: { // 流媒体相关的域名列表 type: "http", behavior: "domain", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/GlobalMedia/GlobalMedia_Domain.txt", path: "./ruleset/streamingdomain.yaml", format: "text", interval: 86400, }, advertising: { // 广告域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/AdvertisingLite/AdvertisingLite.yaml", path: "./ruleset/advertising.yaml", interval: 86400, }, advertisingdomain: { // 广告域名列表 type: "http", behavior: "domain", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/AdvertisingLite/AdvertisingLite_Domain.txt", path: "./ruleset/advertisingdomain.yaml", format: "text", interval: 86400, }, proxy: { // 代理域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Proxy/Proxy.yaml", path: "./ruleset/proxy.yaml", interval: 86400, }, proxydomain: { // 代理域名列表 type: "http", behavior: "domain", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Proxy/Proxy_Domain.txt", path: "./ruleset/proxydomain.yaml", format: "text", interval: 86400, }, direct: { // 直连域名列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Direct/Direct.yaml", path: "./ruleset/direct.yaml", interval: 86400, }, lancidr: { // 局域网 IP 及保留 IP 地址列表 type: "http", behavior: "classical", url: "https://cdn.jsdelivr.net/gh/blackmatrix7/ios_rule_script@master/rule/Clash/Lan/Lan.yaml", path: "./ruleset/lancidr.yaml", interval: 86400, }, }; return config; }