From 578b46ca34a6de2abee114074beddb296321189f Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 19 Jul 2020 13:17:50 +0100 Subject: [PATCH] load game data from file; dedupe getElement calls --- script.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index a6ca354..b969815 100644 --- a/script.js +++ b/script.js @@ -29,6 +29,8 @@ async function run() { pageButton.addEventListener('touchend', pagination); } + const gameDataInput = document.getElementById("game-data"); + function new_game() { load_default_game_data(); // we don't need to look at the default game data, so skip ahead to the image page @@ -36,7 +38,7 @@ async function run() { } function clear_game() { - document.getElementById("game-data").innerHTML = ""; + gameDataInput.innerHTML = ""; } let new_game_button = document.getElementById("new"); @@ -61,6 +63,12 @@ async function run() { } } + document.getElementById("game").addEventListener("change", function() { + readFile(this, function (e) { + gameDataInput.innerHTML = e.target.result; + }, "text"); + }); + const preview = document.getElementById("preview"); preview.style.display = "none";