-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.js
More file actions
143 lines (130 loc) · 4.83 KB
/
notes.js
File metadata and controls
143 lines (130 loc) · 4.83 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
let addBtn = document.getElementById('addBtn');
shownotes();
addBtn.addEventListener(
"click",
(e) => {
let addHead = document.getElementById('addHead');
let head = localStorage.getItem("head")
let addTxt = document.getElementById('addText');
let notes = localStorage.getItem("notes")
if(notes == null && head == null)
{
headObj = [];
notesObj = [];
}
else{
headObj = JSON.parse(head)
notesObj = JSON.parse(notes)
}
headObj.push(addHead.value);
localStorage.setItem("head", JSON.stringify(headObj));
addHead.value = "";
notesObj.push(addTxt.value);
localStorage.setItem("notes", JSON.stringify(notesObj));
addTxt.value = "";
shownotes();
}
)
function shownotes() {
let show_notes = localStorage.getItem("notes");
let show_head = localStorage.getItem("head");
if (show_notes == null && show_head == null) {
notesObj = [];
headObj = [];
} else {
notesObj = JSON.parse(show_notes);
headObj = JSON.parse(show_head);
}
let html = "";
notesObj.forEach((element, index) => {
html += `
<div class="noteCard card" style="width: 18rem; height: 30vh; padding: 20px;">
<h4 class="card-header">${headObj[index]}</h4>
<div class="card-body" style="overflow: hidden; padding: 0 0 10px 0;">
<p class="card-text">${element}</p>
</div>
<button id="${index}" onclick="deletenote(this.id)" class="btn btn-primary" style="width: 20vh;">Delete note</button>
</div>`;
});
let noteselm = document.getElementById('notes');
if (notesObj.length != 0) {
noteselm.innerHTML = html;
} else {
noteselm.innerHTML = `You don't have any notes yet! Please add a note from the above section`;
}
}
function deletenote(index){
let notes = localStorage.getItem("notes")
if(notes == null)
{
notesObj = [];
}
else{
notesObj = JSON.parse(notes)
}
notesObj.splice(index, 1)
localStorage.setItem("notes", JSON.stringify(notesObj));
shownotes();
}
let search = document.getElementById('searchTxt')
search.addEventListener(
"input",
function (){
let inputval = search.value.toLowerCase();
let cardbody = document.getElementsByClassName('noteCard');
Array.from(cardbody).forEach(function(element){
let cardtxt = element.getElementsByTagName("p")[0].innerText;
if (cardtxt.includes(inputval)) {
element.style.display = "block";
}
else{
element.style.display = "none";
}
})
})
let darkmodeball = document.getElementById('darkmode-ball');
let darklightbtn = document.getElementById('dark-light-btn');
let mynote = document.querySelector('#mynote');
let addTet = document.getElementById('addText');
let addHead = document.getElementById('addHead');
let isDarkMode = false;
darklightbtn.addEventListener("click", () => {
// Toggle the dark mode status
isDarkMode = !isDarkMode;
// Update the margin based on the dark mode status
if (isDarkMode) {
document.body.style.backgroundColor = "#121212";
document.body.style.color = "#fff";
darkmodeball.style.margin = "0 0 0 20px"; // Turn on
darkmodeball.style.backgroundColor = "#fff";
darklightbtn.style.border = "1px solid #fff";
mynote.style.backgroundColor = "#1E1E1E";
mynote.style.color = "#fff";
addTet.style.backgroundColor = "#1E1E1E";
addTet.style.color = "#fff";
addHead.style.backgroundColor = "#1E1E1E";
addHead.style.color = "#fff";
} else {
darkmodeball.style.margin = "0 0 0 4px"; // Turn off
darkmodeball.style.backgroundColor = "#000";
document.body.style.backgroundColor = "#fff";
document.body.style.color = "#000";
darklightbtn.style.border = "1px solid #000";
mynote.style.backgroundColor = "#fff";
mynote.style.color = "#000";
addTet.style.backgroundColor = "#fff";
addTet.style.color = "#000";
addHead.style.backgroundColor = "#fff";
addHead.style.color = "#000";
}
let noteCards = document.querySelectorAll('.noteCard');
noteCards.forEach(noteCard => {
if (isDarkMode) {
noteCard.style.backgroundColor = "#1E1E1E"; // Dark mode color
noteCard.style.color = "#fff"; // Dark mode text color
} else {
noteCard.style.backgroundColor = "#fff"; // Light mode color
noteCard.style.color = "#000"; // Light mode text color
}
});
});