frontend side of handling specific games

This commit is contained in:
ajuvercr 2020-04-10 21:20:14 +02:00
parent e3bb2f5d8c
commit b69f42cb7e

View file

@ -4,27 +4,29 @@ import { ConfigIniParser } from 'config-ini-parser'
const OPTIONS = document.getElementById("options"); const OPTIONS = document.getElementById("options");
const game_location = LOCATION + "static/games/mod.ini"; const game_location = LOCATION + "static/games/mod.ini";
async function on_load() {
if (OPTIONS) { if (OPTIONS) {
fetch(game_location) const r = await fetch(game_location);
.then((r) => r.text()) const response = await r.text();
.then((response) => {
parse_ini(response); parse_ini(response);
}).catch(console.error);
} else { } else {
const options = document.getElementsByClassName("options"); const options = document.getElementsByClassName("options");
if (options[0]) { 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 = <HTMLDivElement> options[0]; const options_div = <HTMLDivElement> options[0];
if (options_div.children[0]) { if (options_div.children[0]) {
setTimeout( options_div.children[0].dispatchEvent(new Event('click'));
() => options_div.children[0].dispatchEvent(new Event('click')),
200,
);
} }
} }
} }
}
window.addEventListener("load", on_load);
export function handle(location, name: string) { export function handle(location, name: string) {
set_loading(true); set_loading(true);