diff --git a/index.html b/index.html
index c615be3..4d8f399 100644
--- a/index.html
+++ b/index.html
@@ -5,10 +5,8 @@
-
+
+
Clash
diff --git a/src/lib/request.ts b/src/lib/request.ts
index 61a10b2..5d3cd92 100644
--- a/src/lib/request.ts
+++ b/src/lib/request.ts
@@ -110,10 +110,19 @@ export async function getExternalControllerConfig () {
}
}
- const hostname = getLocalStorageItem('externalControllerAddr', '127.0.0.1')
- const port = getLocalStorageItem('externalControllerPort', '9090')
- const secret = getLocalStorageItem('secret', '')
- const protocol = hostname === '127.0.0.1' ? 'http:' : window.location.protocol
+ let url: URL | undefined;
+ {
+ const meta = document.querySelector('meta[name="external-controller"]')
+ if (meta?.content?.match(/^https?:/)) {
+ // [protocol]://[secret]@[hostname]:[port]
+ url = new URL(meta.content)
+ }
+ }
+
+ const hostname = getLocalStorageItem('externalControllerAddr', url?.hostname ?? '127.0.0.1')
+ const port = getLocalStorageItem('externalControllerPort', url?.port ?? '9090')
+ const secret = getLocalStorageItem('secret', url?.username ?? '')
+ const protocol = hostname === '127.0.0.1' ? 'http:' : (url?.protocol ?? window.location.protocol)
if (!hostname || !port) {
throw new Error('can\'t get hostname or port')