From c75bfb511f0585dd1ad27cc6d69704734d9cc2b0 Mon Sep 17 00:00:00 2001 From: inventionpro <109528211+inventionpro@users.noreply.github.com> Date: Wed, 1 May 2024 13:15:30 +0200 Subject: [PATCH] Update script.js --- script.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index f796c41..b1c1ed8 100644 --- a/script.js +++ b/script.js @@ -69,7 +69,14 @@ function file_i() { document.getElementById('upload').addEventListener("change", function(){ const reader = new FileReader(); reader.onload = (evt) => { - console.log('File load: '+evt.target.result); + let con = evt.target.result; + try { + let json = JSON.parse(con); + if (!Array.isArray(json)) throw new Error('Not a array'); + localStorage.setItem('todo', con); + } catch(err) { + alert('Not a valid file') + } }; reader.readAsText(this.files[0]); });