-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
32 lines (26 loc) · 760 Bytes
/
options.js
File metadata and controls
32 lines (26 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function saveNotes() {
const blob = new Blob([localStorage.getItem("notes")], { type: 'text/plain' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = "notes.json";
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(link.href);
}
const fileInput = document.querySelector("#jsonFile");
function loadNotes() {
const file = fileInput.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (event) => {
const content = event.target.result;
try {
const parsed = JSON.parse(content);
localStorage.setItem("notes", JSON.stringify(parsed));
location.href = "index.html";
} catch {
alert("Invalid JSON data");
}
};
reader.readAsText(file);
}