From b69f42cb7ef141e1ea38fc6bc7d2334ab151fa90 Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Fri, 10 Apr 2020 21:20:14 +0200 Subject: [PATCH] frontend side of handling specific games --- frontend/www/games.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/frontend/www/games.ts b/frontend/www/games.ts index f460fb9..46ba352 100644 --- a/frontend/www/games.ts +++ b/frontend/www/games.ts @@ -4,28 +4,30 @@ import { ConfigIniParser } from 'config-ini-parser' const OPTIONS = document.getElementById("options"); - const game_location = LOCATION + "static/games/mod.ini"; -if (OPTIONS) { - fetch(game_location) - .then((r) => r.text()) - .then((response) => { - parse_ini(response); - }).catch(console.error); -} else { - const options = document.getElementsByClassName("options"); - if (options[0]) { - const options_div = options[0]; - if (options_div.children[0]) { - setTimeout( - () => options_div.children[0].dispatchEvent(new Event('click')), - 200, - ); +async function on_load() { + if (OPTIONS) { + const r = await fetch(game_location); + const response = await r.text(); + parse_ini(response); + } else { + const options = document.getElementsByClassName("options"); + const urlVars = new URLSearchParams(window.location.search); + + if (urlVars.get("game") && urlVars.get("name")) { + handle(urlVars.get("game"),urlVars.get("name")) + } else if (options[0]) { + const options_div = options[0]; + if (options_div.children[0]) { + options_div.children[0].dispatchEvent(new Event('click')); + } } } } +window.addEventListener("load", on_load); + export function handle(location, name: string) { set_loading(true);