JSON import snippet from somewhere
This commit is contained in:
parent
9d0f09df78
commit
c41f60587b
|
@ -10,9 +10,13 @@
|
||||||
<main>
|
<main>
|
||||||
<h1>Brown Wall</h1>
|
<h1>Brown Wall</h1>
|
||||||
<h3>A wall which has been hit with a considerable amount of faeces.</h3>
|
<h3>A wall which has been hit with a considerable amount of faeces.</h3>
|
||||||
<noscript>Enable JS to use this application.</noscript>
|
|
||||||
<div id="menu-container" class="menu-container">
|
<div id="menu-container" class="menu-container">
|
||||||
|
<noscript>Enable JS to use this application.</noscript>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<input type="file" id="selectFiles" value="Import"/>
|
||||||
|
<button id="import">Import</button>
|
||||||
|
<textarea id="result" cols="30" rows="10"></textarea>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
<script src="main.js"></script>
|
<script src="main.js"></script>
|
||||||
|
|
18
main.js
18
main.js
|
@ -21,3 +21,21 @@ menus.forEach( menu =>{
|
||||||
dropdownSelect.append(Object.assign(document.createElement('option'), {id:item.toLowerCase(), innerHTML:item}))
|
dropdownSelect.append(Object.assign(document.createElement('option'), {id:item.toLowerCase(), innerHTML:item}))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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));
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue