-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (53 loc) · 1.31 KB
/
Copy pathscript.js
File metadata and controls
61 lines (53 loc) · 1.31 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
let notes = JSON.parse(localStorage.getItem("Notes")) || [];
display();
function save(){
const note=document.getElementById("input_notes").value.trim();
if(!note){
return;
}
document.getElementById("input_notes").value="";
const data={
text:note,
id:Date.now(),
time: new Date().toLocaleString()
};
notes.push(data);
storage();
display();
}
function delete_notes(id){
notes=notes.filter(x=>
x.id!==id
);
storage();
display();
}
function display(){
const list=document.querySelector("#div_id");
if(notes.length===0){
list.innerHTML=
`
<p class="text-light text-center">No Saved Notes yet !!!</p>
`
}
else{
list.innerHTML=notes.map(x=>
`
<div class="d-flex justify-content-center">
<div class="card mb-3 w-100">
<div class="card-body">
<p class="card-text">${DOMPurify.sanitize(x.text)}</p>
<small class="text-muted">Created on: ${x.time}</small>
<div class="mt-2">
<button onclick="delete_notes(${x.id})" class="btn btn-warning ">Delete</button>
</div>
</div>
</div>
</div>
`
).join("");
}
}
function storage(){
localStorage.setItem("Notes",JSON.stringify(notes));
}