From 4dea888769ef153806bc5275616fd3c9d3e0a32b Mon Sep 17 00:00:00 2001 From: WengHeng Date: Tue, 8 Mar 2022 10:47:18 +0800 Subject: [PATCH] Improve handling of the hostname url query Also add related info into README --- README.md | 13 ++++++++++++- src/store/app.ts | 11 ++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 59aa388..c86e548 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,24 @@ > Yet Another [Clash](https://github.com/Dreamacro/clash) [Dashboard](https://github.com/Dreamacro/clash-dashboard) +## Usage + The site [http://yacd.haishan.me](http://yacd.haishan.me) is served with HTTP not HTTPS is because many browsers block requests to HTTP resources from a HTTPS website. If you think it's not safe, you could just download the [zip of the gh-pages](https://github.com/haishanh/yacd/archive/gh-pages.zip), unzip and serve those static files with a web server(like Nginx). -Docker image +**Docker image** - Docker Hub [`haishanh/yacd`](https://hub.docker.com/r/haishanh/yacd) - GitHub Container Registry [`ghcr.io/haishanh/yacd`](https://github.com/haishanh/yacd/pkgs/container/yacd) +**Supported URL query params** + +| Param | Description | +| -------- | ---------------------------------------------------------------------------------- | +| hostname | Hostname of the clash backend API (usually the host part of `external-controller`) | +| port | Port of the clash backend API (usually the port part of `external-controller`) | +| secret | Clash API secret (`secret` in your config.yaml) | +| theme | UI color scheme (dark, light, auto) | + ## Development ```sh diff --git a/src/store/app.ts b/src/store/app.ts index e5594a3..6680e6e 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -95,6 +95,7 @@ export function updateClashAPIConfig({ baseURL, secret }) { const rootEl = document.querySelector('html'); type ThemeType = 'dark' | 'light' | 'auto'; + function setTheme(theme: ThemeType = 'dark') { if (theme === 'auto') { rootEl.setAttribute('data-theme', 'auto'); @@ -152,7 +153,7 @@ export function updateCollapsibleIsOpen(prefix: string, name: string, v: boolean const defaultClashAPIConfig = { baseURL: document.getElementById('app')?.getAttribute('data-base-url') ?? 'http://127.0.0.1:9090', secret: '', - addedAt: 0, + addedAt: 0 }; // type Theme = 'light' | 'dark'; const defaultState: StateApp = { @@ -169,7 +170,7 @@ const defaultState: StateApp = { proxySortBy: 'Natural', hideUnavailableProxies: false, autoCloseOldConns: false, - logStreamingPaused: false, + logStreamingPaused: false }; function parseConfigQueryString() { @@ -193,7 +194,11 @@ export function initialState() { if (conf) { const url = new URL(conf.baseURL); if (query.hostname) { - url.hostname = query.hostname; + if (query.hostname.indexOf('http') === 0) { + url.href = decodeURIComponent(query.hostname); + } else { + url.hostname = query.hostname; + } } if (query.port) { url.port = query.port;