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" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Clash web port"
|
||||
/>
|
||||
<meta name="description" content="Clash web port" />
|
||||
<!--meta name="external-controller" content="http://secret@example.com:9090"-->
|
||||
<title>Clash</title>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -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<HTMLMetaElement>('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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user