-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (77 loc) · 2.45 KB
/
main.js
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
function new_refresh() {
const not_nme = prompt("Enter name of note", "Note");
if (not_nme != null) {
if (localStorage.getItem('notes') == null) {
notesarr = [];
notesarr.push(not_nme);
localStorage.setItem('notes', JSON.stringify(notesarr));
}
else {
notesarr_str = localStorage.getItem('notes');
notesarr = JSON.parse(notesarr_str);
notesarr.push(not_nme);
localStorage.setItem('notes', JSON.stringify(notesarr));
}
}
refresh();
}
function refresh() {
if (localStorage.getItem('notes') == null) {
notesarr = [];
localStorage.setItem('notes', JSON.stringify(notesarr));
}
else {
notesarr_str = localStorage.getItem('notes');
notesarr = JSON.parse(notesarr_str);
}
let list = document.getElementById("list");
let str = "";
notesarr.forEach((element, index) => {
str += `
<li id="list">
<div id="menu">
<h3 class="nme">${element}</h3>
<ul>
<li id="tasks"></li>
</ul>
<div class="btns">
<button class="addtsk" id="addtsk" onclick="tsk(event)">Add task</button>
<button class="deltsk" onclick="del(${index})">Del list</button>
</div>
</div>
</li>`;
});
list.innerHTML = str;
}
function add() {
new_refresh();
}
function del(iindex) {
console.log("del");
notesarr_str = localStorage.getItem('notes');
notesarr = JSON.parse(notesarr_str);
notesarr.splice(iindex, 1);
localStorage.setItem('notes', JSON.stringify(notesarr));
refresh();
}
function tsk(event) {
const tsk_nme = prompt("Enter name of task");
if (tsk_nme != null) {
if (localStorage.getItem('ele') == null) {
elemarr = [];
elemarr.push(tsk_nme);
localStorage.setItem('ele', JSON.stringify(elemarr));
}
else {
elemarr = JSON.parse(localStorage.getItem('ele'));
elemarr.push(tsk_nme);
localStorage.setItem('ele', JSON.stringify(elemarr));
}
let s = "";
elemarr.forEach(element => {
s += `<li>${element}<button id="edit"><i class="material-icons">edit</i></button> <button id="trash"><i
class="material-icons">delete</i></button></li>`;
});
event.target.parentElement.previousElementSibling.innerHTML = s;
}
}