mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 14:01:56 +08:00
Feature: external controller from meta tag (#66)
This commit is contained in:
parent
8ed9368b3e
commit
d44c5472e4
@ -5,10 +5,8 @@
|
|||||||
<link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/Dreamacro/clash/docs/logo.png" />
|
<link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/Dreamacro/clash/docs/logo.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<meta name="theme-color" content="#000000" />
|
<meta name="theme-color" content="#000000" />
|
||||||
<meta
|
<meta name="description" content="Clash web port" />
|
||||||
name="description"
|
<!--meta name="external-controller" content="http://secret@example.com:9090"-->
|
||||||
content="Clash web port"
|
|
||||||
/>
|
|
||||||
<title>Clash</title>
|
<title>Clash</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -110,10 +110,19 @@ export async function getExternalControllerConfig () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hostname = getLocalStorageItem('externalControllerAddr', '127.0.0.1')
|
let url: URL | undefined;
|
||||||
const port = getLocalStorageItem('externalControllerPort', '9090')
|
{
|
||||||
const secret = getLocalStorageItem('secret', '')
|
const meta = document.querySelector<HTMLMetaElement>('meta[name="external-controller"]')
|
||||||
const protocol = hostname === '127.0.0.1' ? 'http:' : window.location.protocol
|
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) {
|
if (!hostname || !port) {
|
||||||
throw new Error('can\'t get hostname or port')
|
throw new Error('can\'t get hostname or port')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user