diff --git a/html/editor.html b/html/editor.html index 4f6a44f..b7c4aa8 100644 --- a/html/editor.html +++ b/html/editor.html @@ -5,7 +5,7 @@ Editor -
+
diff --git a/js/editor.js b/js/editor.js index 8929eb8..260dacc 100644 --- a/js/editor.js +++ b/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();