diff --git a/assets/script/all.js b/assets/script/all.js index 57d1d99..93415be 100644 --- a/assets/script/all.js +++ b/assets/script/all.js @@ -21,6 +21,18 @@ class Element { return document.querySelector('#input-export-import'); } + static getFileExportButton() { + return document.querySelector('#export-file'); + } + + static getFileImportButton() { + return document.querySelector('#import-file-button'); + } + + static getFileImportFileInput() { + return document.querySelector('#import-file'); + } + /** * Get the product list element * @returns {HTMLElement} @@ -703,4 +715,33 @@ const cartManager = new CartManager(); const productManager = new ProductManager(); const tabManager = new TabManager(); const themeManager = new ThemeManager(); -const cartHistoryManager = new CartHistoryManager(); \ No newline at end of file +const cartHistoryManager = new CartHistoryManager(); + + +Element.getFileExportButton().addEventListener('click', () => { + const blob = new Blob([Element.getImportExportTextarea().value], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = 'products.json'; + document.body.appendChild(a); + a.click(); + setTimeout(() => { + URL.revokeObjectURL(url); + a.remove(); + }, 0); +}); + +Element.getFileImportButton().addEventListener('click', () => { + let inputJsonFile = Element.getFileImportFileInput(); + let fileContent = inputJsonFile.files[0]; + if (fileContent) { + const reader = new FileReader(); + reader.onload = async (e) => { + const json = JSON.parse(e.target.result); + await productManager.convertAndSaveProductImages(json); + location.reload(); + }; + reader.readAsText(fileContent); + } +}) \ No newline at end of file diff --git a/index.html b/index.html index 9595fea..83d2f8a 100644 --- a/index.html +++ b/index.html @@ -117,6 +117,24 @@ lädt die Software das Bild herunter und speichert es in der JSON-Datei als Base64-kodierte Version. Die ursprüngliche URL wird dabei nicht mehr gespeichert.

+ + +
+ + + | + + + + + +
+ +