diff options
| author | David Skoland <davidskoland@gmail.com> | 2023-11-13 00:11:21 +0100 |
|---|---|---|
| committer | David Skoland <davidskoland@gmail.com> | 2023-11-13 00:11:21 +0100 |
| commit | ab396c71295f76e62739c01bc8e6a29f1896ba8c (patch) | |
| tree | a24ff12de80955903266a69820de7e99575dc0e0 /webAO/utils/queryParser.ts | |
| parent | 3b57ceff07be9fc86ee5ba73a0614ee754f8f8c6 (diff) | |
Use URLSearchParams and set default directly
Diffstat (limited to 'webAO/utils/queryParser.ts')
| -rw-r--r-- | webAO/utils/queryParser.ts | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/webAO/utils/queryParser.ts b/webAO/utils/queryParser.ts index 20863ca..c9c13cc 100644 --- a/webAO/utils/queryParser.ts +++ b/webAO/utils/queryParser.ts @@ -2,24 +2,19 @@ interface QueryParams { ip: string; - serverIP: string; mode: string; asset: string; theme: string; } -interface StringMap { - [key: string]: any; -} - const queryParser = (): QueryParams => { - const queryDict: StringMap = {}; - location.search - .substr(1) - .split("&") - .forEach((item) => { - queryDict[item.split("=")[0]] = item.split("=")[1]; - }); - return queryDict as QueryParams; + const urlParams = new URLSearchParams(window.location.search); + const queryParams = { + ip: urlParams.get("ip") || "", + mode: urlParams.get("mode") || "join", + asset: urlParams.get("asset") || "http://attorneyoffline.de/base/", + theme: urlParams.get("theme") || "default", + } + return queryParams as QueryParams; }; export default queryParser; |
