-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (53 loc) · 2.06 KB
/
script.js
File metadata and controls
62 lines (53 loc) · 2.06 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
let notes = JSON.parse(localStorage.getItem("notes") || "[]");
const notesContainer = document.getElementById("notes-container");
const modal = document.getElementById("modal");
const addBtn = document.getElementById("add-btn");
const search = document.getElementById("search");
function renderNotes() {
notesContainer.innerHTML = "";
notes.forEach((note, i) => {
const div = document.createElement("div");
div.className = "note glass";
div.innerHTML = `<h3>${note.title}</h3><p>${note.text}</p>`;
div.onclick = () => openFullscreen(note.title, note.text);
notesContainer.appendChild(div);
});
localStorage.setItem("notes", JSON.stringify(notes));
}
function saveNote() {
const title = document.getElementById("note-title").value.trim();
const text = document.getElementById("note-text").value.trim();
if (!title && !text) return;
notes.unshift({ title, text, date: Date.now() });
modal.classList.remove("show");
renderNotes();
}
function openFullscreen(title, text) {
document.getElementById("fullscreen-title").innerText = title;
document.getElementById("fullscreen-text").innerText = text;
document.getElementById("fullscreen-view").classList.add("show");
}
function closeFullscreen() {
document.getElementById("fullscreen-view").classList.remove("show");
}
function sortNotes(type) {
if (type === "newest") notes.sort((a,b)=>b.date-a.date);
if (type === "oldest") notes.sort((a,b)=>a.date-b.date);
if (type === "title") notes.sort((a,b)=>a.title.localeCompare(b.title));
renderNotes();
}
function clearNotes() {
if (confirm("Delete all notes?")) {
notes = [];
renderNotes();
}
}
search.addEventListener("input", () => {
const query = search.value.toLowerCase();
document.querySelectorAll(".note").forEach(note => {
note.style.display = note.innerText.toLowerCase().includes(query) ? "block" : "none";
});
});
addBtn.onclick = () => modal.classList.add("show");
window.onclick = e => { if(e.target===modal) modal.classList.remove("show"); };
renderNotes();