Created
October 12, 2025 21:00
-
-
Save QYG2297248353/71db733b9b7e5863dae6b17a0cb5eca6 to your computer and use it in GitHub Desktop.
FlClash 动态化配置脚本 高阶版
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
| // ============================================================ | |
| // 🔧 FIClash 动态配置融合版脚本 | |
| // 作者:萌森工作室 | |
| // 说明:Clash / FIClash 调用 main(config) 时自动执行 | |
| // ============================================================ | |
| // | |
| // ✅ 使用方法: | |
| // 每个分组对象支持以下字段: | |
| // { | |
| // name: "港湾", // 分组名称 | |
| // type: "select", // 类型(常见:select / url-test / fallback) | |
| // match: /(香港|台湾)/, // (可选)自动正则匹配节点名 | |
| // proxies: ["节点1", "节点2"], // (可选)手动添加的节点名 | |
| // rules: ["DOMAIN-SUFFIX,javdb.com,宝可梦港湾"] // (可选)该组的规则 | |
| // } | |
| // | |
| // 默认内置组(不会创建,但可附加规则): | |
| // DIRECT / REJECT / no-resolve | |
| // | |
| // ============================================================ | |
| // ======== 用户配置区 ======== | |
| const GROUPS = [ | |
| { | |
| name: "港湾节点", | |
| type: "select", | |
| match: /(香港|台湾)/, | |
| rules: [ | |
| "DOMAIN-SUFFIX,javdb.com,港湾节点", | |
| "DOMAIN-SUFFIX,bahamut.com.tw,港湾节点", | |
| ], | |
| }, | |
| { | |
| name: "新日韩节点", | |
| type: "select", | |
| match: /(新加坡|日本|韩国)/, | |
| rules: [ | |
| "DOMAIN-SUFFIX,dlsite.com,新日韩节点", | |
| "DOMAIN-SUFFIX,pixiv.net,新日韩节点", | |
| ], | |
| }, | |
| { | |
| name: "DIRECT", | |
| rules: [ | |
| "DOMAIN-SUFFIX,local,DIRECT", | |
| "DOMAIN-SUFFIX,lan,DIRECT", | |
| ], | |
| }, | |
| { | |
| name: "REJECT", | |
| rules: [ | |
| "DOMAIN-SUFFIX,ads.google.com,REJECT", | |
| "DOMAIN-SUFFIX,adservice.google.com,REJECT", | |
| ], | |
| }, | |
| ]; | |
| // ======== 核心逻辑部分(无需修改) ======== | |
| const DEFAULT_GROUPS = ["DIRECT", "REJECT", "no-resolve"]; | |
| const main = (config) => { | |
| console.log("🚀 FIClash 脚本执行开始"); | |
| // 确保关键字段存在 | |
| config.proxies ??= []; | |
| config["proxy-groups"] ??= []; | |
| config.rules ??= []; | |
| const allProxyNames = config.proxies.map(p => p.name); | |
| const groups = config["proxy-groups"]; | |
| const rules = config.rules; | |
| const upperRules = rules.map(r => r.toUpperCase().trim()); | |
| // 规则插入点 | |
| let insertIndex = rules.findIndex(r => { | |
| const u = r.toUpperCase(); | |
| return u.startsWith("MATCH") || u.startsWith("FINAL"); | |
| }); | |
| if (insertIndex === -1) insertIndex = rules.length; | |
| let totalAddedRules = 0; | |
| // === 处理分组 === | |
| for (const groupDef of GROUPS) { | |
| const { name, type = "select", match, proxies = [], rules: groupRules = [] } = groupDef; | |
| // 处理代理节点匹配 | |
| let matchedProxies = proxies.slice(); | |
| if (match instanceof RegExp) { | |
| const regexMatched = allProxyNames.filter(n => match.test(n)); | |
| matchedProxies.push(...regexMatched); | |
| } | |
| matchedProxies = [...new Set(matchedProxies)]; | |
| // === 默认组不创建,只添加规则 === | |
| if (!DEFAULT_GROUPS.includes(name)) { | |
| const exists = groups.some(g => g.name === name); | |
| if (!exists) { | |
| groups.push({ name, type, proxies: matchedProxies }); | |
| console.log(`✅ 新增代理组:${name}(${matchedProxies.length} 节点)`); | |
| } else { | |
| console.log(`⚠️ 已存在代理组:${name}`); | |
| } | |
| } else { | |
| console.log(`🔸 默认组跳过创建:${name}`); | |
| } | |
| // === 处理规则 === | |
| for (const rule of groupRules) { | |
| const upper = rule.toUpperCase().trim(); | |
| if (!upperRules.includes(upper)) { | |
| rules.splice(insertIndex, 0, rule); | |
| insertIndex++; | |
| upperRules.push(upper); | |
| totalAddedRules++; | |
| } | |
| } | |
| } | |
| console.log( | |
| totalAddedRules > 0 | |
| ? `✅ 添加规则 ${totalAddedRules} 条` | |
| : "⚠️ 无需添加规则(均已存在)" | |
| ); | |
| console.log("🎉 FIClash 配置融合脚本执行完毕"); | |
| return config; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment