-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
115 lines (97 loc) · 2.98 KB
/
script.js
File metadata and controls
115 lines (97 loc) · 2.98 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
let userKey = "";
let notes = [];
function enterVault() {
const username = document.getElementById("username").value.trim();
if (!username) return alert("Please enter name");
userKey = "vault_" + username.toLowerCase().replace(/\s+/g, "_");
notes = JSON.parse(localStorage.getItem(userKey)) || [];
if (!Array.isArray(notes)) notes = [];
document.getElementById("loginSection").style.display = "none";
document.getElementById("vault").style.display = "block";
document.getElementById("userDisplay").innerText = username;
showNotes();
}
function saveNotes() {
localStorage.setItem(userKey, JSON.stringify(notes));
}
function addNote() {
const text = document.getElementById("noteInput").value.trim();
if (!text) return;
const folder = prompt("📂 Enter folder name (optional):") || "";
const note = {
id: Date.now(),
text,
folder,
time: new Date().toLocaleString()
};
notes.unshift(note);
saveNotes();
document.getElementById("noteInput").value = "";
showNotes();
}
function showNotes(list = notes) {
const noteList = document.getElementById("noteList");
noteList.innerHTML = "";
list.forEach(note => {
const li = document.createElement("li");
li.innerHTML = `
<div><strong>${note.text}</strong></div>
<small>📂 ${note.folder || 'No Folder'} | 🕒 ${note.time}</small><br>
<div>
<button onclick="editNote(${note.id})">✏️</button>
<button onclick="deleteNote(${note.id})">🗑️</button>
</div>
`;
noteList.appendChild(li);
});
}
function editNote(id) {
const index = notes.findIndex(n => n.id === id);
if (index !== -1) {
const newText = prompt("Edit note:", notes[index].text);
const newFolder = prompt("Edit folder:", notes[index].folder || "");
if (newText !== null) {
notes[index].text = newText;
notes[index].folder = newFolder;
notes[index].time = new Date().toLocaleString();
saveNotes();
showNotes();
}
}
}
function deleteNote(id) {
if (!confirm("Delete this note?")) return;
notes = notes.filter(n => n.id !== id);
saveNotes();
showNotes();
}
function searchNotes() {
const q = document.getElementById("search").value.toLowerCase();
const filtered = notes.filter(n => n.text.toLowerCase().includes(q));
showNotes(filtered);
}
function exportNotes() {
const blob = new Blob([JSON.stringify(notes)], { type: "application/json" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = `${userKey}_notes.json`;
a.click();
}
function importNotes() {
const file = document.getElementById("importFile").files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = e => {
try {
const data = JSON.parse(e.target.result);
if (!Array.isArray(data)) return alert("Invalid file");
notes = data;
saveNotes();
showNotes();
alert("✅ Notes imported");
} catch {
alert("❌ Import failed");
}
};
reader.readAsText(file);
}