Created
June 28, 2026 11:55
-
-
Save zhiyue/28cf0bb31e752d5f4b45a6230263c4c4 to your computer and use it in GitHub Desktop.
Surge: 根据 ISP 自动启停 TAG Profile 模块
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
| // 网络切换时自动启停 TAG Profile 模块 | |
| // 移动 ISP → 启用(走国内中转) | |
| // 其他 ISP → 禁用(直连海外,延迟更低) | |
| const MODULE_NAME = "TAG Profile"; | |
| const MOBILE_KEYWORDS = ["移动", "CMCC", "China Mobile"]; | |
| $httpClient.get( | |
| { url: "https://myip.ipip.net", timeout: 5 }, | |
| (error, _resp, body) => { | |
| if (error) { | |
| console.log("ISP 检测失败: " + error); | |
| $done(); | |
| return; | |
| } | |
| const shouldEnable = MOBILE_KEYWORDS.some((kw) => body.includes(kw)); | |
| $httpAPI("GET", "/v1/modules", null, (currentModules) => { | |
| const isEnabled = | |
| currentModules.enabled && | |
| currentModules.enabled.indexOf(MODULE_NAME) !== -1; | |
| if (isEnabled === shouldEnable) { | |
| console.log( | |
| "ISP 检测: " + body.trim() + " → " + MODULE_NAME + " 已是目标状态,跳过" | |
| ); | |
| $done(); | |
| return; | |
| } | |
| const moduleState = {}; | |
| moduleState[MODULE_NAME] = shouldEnable; | |
| const action = shouldEnable ? "启用" : "禁用"; | |
| $httpAPI("POST", "/v1/modules", moduleState, () => { | |
| console.log("ISP 检测: " + body.trim() + " → " + action + " " + MODULE_NAME); | |
| $notification.post( | |
| "TAG 模块自动切换", | |
| action + " " + MODULE_NAME, | |
| body.trim() | |
| ); | |
| $done(); | |
| }); | |
| }); | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment