feat: support parse port and secret in query string

This commit is contained in:
Haishan 2018-12-29 13:09:42 +08:00
parent 4be0aca6c1
commit 5c4a7da719
3 changed files with 21 additions and 2 deletions

View file

@ -27,7 +27,7 @@
"keywords": [ "keywords": [
"react" "react"
], ],
"author": "Han Haishan <haishanhan@gmail.com> (htttp://haishan.me)", "author": "Haishan <haishanhan@gmail.com> (https://haishan.me)",
"private": true, "private": true,
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {

View file

@ -13,7 +13,7 @@
.content { .content {
flex-grow: 1; flex-grow: 1;
overflow: scroll; overflow: auto;
// background: #202020; // background: #202020;
// $w: 7px; // $w: 7px;

View file

@ -60,11 +60,30 @@ const defaultState = {
theme: 'dark' 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() { function getInitialState() {
let s = loadState(StorageKey); let s = loadState(StorageKey);
if (!s) s = defaultState; if (!s) s = defaultState;
// TODO flat clashAPIConfig? // 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 // set initial theme
setTheme(s.theme); setTheme(s.theme);
return s; return s;