From c41f60587b11d291f31831b281253799802345b5 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Wed, 1 Nov 2023 17:13:20 +0100 Subject: [PATCH] JSON import snippet from somewhere --- brown-wall.html | 6 +++++- main.js | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/brown-wall.html b/brown-wall.html index 706772c..f398f02 100644 --- a/brown-wall.html +++ b/brown-wall.html @@ -10,9 +10,13 @@

Brown Wall

A wall which has been hit with a considerable amount of faeces.

- + + + +
diff --git a/main.js b/main.js index cf082c3..2287c21 100644 --- a/main.js +++ b/main.js @@ -20,4 +20,22 @@ menus.forEach( menu =>{ menu.items.forEach(item =>{ dropdownSelect.append(Object.assign(document.createElement('option'), {id:item.toLowerCase(), innerHTML:item})) }) -}) \ No newline at end of file +}) + +document.getElementById('import').onclick = function() { + const files = document.getElementById('selectFiles').files; + if (files.length <= 0) { + return false; + } + + var fr = new FileReader(); + + fr.onload = function(e) { + console.log(e); + var result = JSON.parse(e.target.result); + var formatted = JSON.stringify(result, null, 2); + document.getElementById('result').value = formatted; + } + + fr.readAsText(files.item(0)); +};