Allow downloading input JSONs
This commit is contained in:
parent
d20af35c5b
commit
9574d1f3c5
@ -5,7 +5,7 @@
|
||||
<title>Editor</title>
|
||||
</head>
|
||||
<body>
|
||||
<input id="jsonUpload" type="file"><br>
|
||||
<input id="jsonUpload" type="file"> <button type="button" id="jsonInputDownload">Download input</button> <br>
|
||||
<form id="deckForm">
|
||||
<div> <label> Deck Name: <input type="text" id="deckName"></label> </div>
|
||||
<div>
|
||||
|
14
js/editor.js
14
js/editor.js
@ -1,7 +1,8 @@
|
||||
let deckJSON;
|
||||
let selected = 0;
|
||||
let deckName = window.location.pathname.split('/')[2];
|
||||
|
||||
document.title = "Editor|" + window.location.pathname.split('/')[2];
|
||||
document.title = "Editor|" + deckName;
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
// deck JSON uploader
|
||||
@ -12,6 +13,17 @@ window.addEventListener("load", () => {
|
||||
reader.readAsText(files[0]);
|
||||
});
|
||||
|
||||
// download input JSON
|
||||
document.querySelector('#jsonInputDownload').addEventListener('click', () => {
|
||||
let dl = document.createElement('a');
|
||||
dl.setAttribute('href', 'data:application/json;charset=utf-8,' +
|
||||
encodeURIComponent(JSON.stringify(deckJSON)));
|
||||
dl.setAttribute('download', deckName + '.input.json');
|
||||
document.body.appendChild(dl);
|
||||
dl.click();
|
||||
document.body.removeChild(dl);
|
||||
});
|
||||
|
||||
// handle changes to deck editor
|
||||
document.querySelector('#deckForm').addEventListener('input', event => {
|
||||
let prop = event.target.id.substring(4).toLowerCase();
|
||||
|
Loading…
Reference in New Issue
Block a user