feat: support parse port and secret in query string
This commit is contained in:
parent
4be0aca6c1
commit
5c4a7da719
3 changed files with 21 additions and 2 deletions
|
@ -27,7 +27,7 @@
|
|||
"keywords": [
|
||||
"react"
|
||||
],
|
||||
"author": "Han Haishan <haishanhan@gmail.com> (htttp://haishan.me)",
|
||||
"author": "Haishan <haishanhan@gmail.com> (https://haishan.me)",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
.content {
|
||||
flex-grow: 1;
|
||||
overflow: scroll;
|
||||
overflow: auto;
|
||||
// background: #202020;
|
||||
|
||||
// $w: 7px;
|
||||
|
|
|
@ -60,11 +60,30 @@ const defaultState = {
|
|||
theme: 'dark'
|
||||
};
|
||||
|
||||
function parseConfigQueryString() {
|
||||
const { search } = location;
|
||||
const collector = {};
|
||||
if (typeof search !== 'string' || search === '') return collector;
|
||||
const qs = search.replace(/^\?/, '').split('&');
|
||||
for (let i = 0; i < qs.length; i++) {
|
||||
const [k, v] = qs[i].split('=');
|
||||
collector[k] = encodeURIComponent(v);
|
||||
}
|
||||
return collector;
|
||||
}
|
||||
|
||||
function getInitialState() {
|
||||
let s = loadState(StorageKey);
|
||||
if (!s) s = defaultState;
|
||||
// TODO flat clashAPIConfig?
|
||||
|
||||
const configQuery = parseConfigQueryString();
|
||||
if (configQuery.port) {
|
||||
s.clashAPIConfig.port = configQuery.port;
|
||||
}
|
||||
if (configQuery.secret) {
|
||||
s.clashAPIConfig.secret = configQuery.secret;
|
||||
}
|
||||
// set initial theme
|
||||
setTheme(s.theme);
|
||||
return s;
|
||||
|
|
Loading…
Reference in a new issue