Last active
November 12, 2022 07:47
-
-
Save xWTF/e690a5a9079c6cc2fcc8f937c5695d29 to your computer and use it in GitHub Desktop.
Surge LAN override script: Module & Outbound
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
// Setup your SSIDs here | |
const LAN_SSID = ['My SSID 1', 'My SSID 2']; | |
const api = (method, path, submit = null) => new Promise(resolve => $httpAPI(method, path, submit, data => resolve(data))); | |
async function ensureModuleStatus(module, status) { | |
const data = await api('GET', 'v1/modules'); | |
if (status != data.enabled.includes(module)) { | |
await api('POST', 'v1/modules', { [module]: status }); | |
} | |
} | |
(async function () { | |
if ($persistentStore.read() == $network.wifi.ssid) { | |
return; | |
} | |
$persistentStore.write($network.wifi.ssid); | |
const IS_LAN_SSID = LAN_SSID.includes($network.wifi.ssid); | |
// Example: Toggle module based on LAN status | |
await ensureModuleStatus('My Module', IS_LAN_SSID); | |
// Example: Toggle outbound (global / rule) based on LAN status | |
await api('POST', 'v1/outbound', { mode: IS_LAN_SSID ? 'proxy' : 'rule' }); | |
// Example: Use specified global proxy (e.g. clash running on your router) for LAN | |
if (IS_LAN_SSID) { | |
await api('POST', 'v1/outbound/global', { policy: 'My LAN Proxy Server' }); | |
} | |
// Example: Toggle direct / rule, in case of your router redirects all traffic | |
// await api('POST', 'v1/outbound', { mode: IS_LAN_SSID ? 'direct' : 'rule' }); | |
})().finally($done); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment