Skip to content

Commit

Permalink
Add alert if JSON is invalid (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF authored Nov 29, 2023
1 parent aa6b8fe commit 6b0401d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions web_ext/sseq_gui/interface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,18 @@ messageHandler.Error = m => {
document.getElementById('json-upload').addEventListener('change', () => {
const file = document.getElementById('json-upload').files[0];
const fileReader = new FileReader();

fileReader.onload = e => {
// Remove whitespace to shorten URL
const json = JSON.stringify(JSON.parse(e.target.result));
window.location = `?module_json=${encodeURIComponent(json)}`;
try {
// Remove whitespace to shorten URL
const json = JSON.stringify(JSON.parse(e.target.result));
window.location = `?module_json=${encodeURIComponent(json)}`;
} catch (error) {
alert('Invalid JSON file: ' + error.message);
console.error('Error parsing JSON:', error);
}
};

fileReader.readAsText(file, 'UTF-8');
});

Expand Down

0 comments on commit 6b0401d

Please sign in to comment.