forked from Souvik-Bhattacharya/ToDoList
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (115 loc) · 3.68 KB
/
script.js
File metadata and controls
121 lines (115 loc) · 3.68 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
setInterval(() => {
document.getElementById('time').innerHTML = new Date();
}, 1000);
show();
function addition() {
let txt = document.getElementById("inputTask");
let c = /[a-zA-Z]/g;
if (c.test(txt.value)) {
let tasks = localStorage.getItem("testTasks");
if (tasks == null) {
arr = [];
} else {
arr = JSON.parse(tasks);
}
let t = txt.value;
t = t.trim();
arr.push(t);
localStorage.setItem("testTasks", JSON.stringify(arr));
txt.value = "";
show();
} else {
alert("You have'nt entered any letters");
}
};
function sorting() {
let tasks = localStorage.getItem("testTasks");
arr = JSON.parse(tasks);
arr.sort();
localStorage.setItem("testTasks", JSON.stringify(arr));
show();
};
function show() {
let tasks = localStorage.getItem("testTasks");
if (tasks == null) {
arr = [];
} else {
arr = JSON.parse(tasks);
}
let imply = '';
arr.forEach(function (element, index) {
imply += `<div class="taskBox">
<h4>Task${index + 1}:</h4>
<p id="${index}">${element}</p>
<button id="bookmarkBtn" onclick = "bookmark(${index})">Bookmark</button>
<button onclick = "del(${index})">Delete Task</button>
</div>`;
});
let space = document.getElementById("myTasks");
if (arr.length == 0) {
space.innerHTML = 'Sorry! Your list is empty.'
let it = document.getElementById("lastEle");
it.style.display = "none";
let n = document.getElementById("num");
n.style.display = "none";
} else {
space.innerHTML = imply;
let it = document.getElementById("lastEle");
it.style.display = "block";
let n = document.getElementById("num");
n.style.display = "block";
document.getElementById('arrLen').innerHTML = arr.length;
arr.forEach(function (element, index) {
if (element.includes("*")) {
let e = document.getElementById(`${index}`);
e.style.backgroundColor = "rgb(133 255 133)";
}
});
}
};
function del(index) {
let tasks = localStorage.getItem("testTasks");
if (tasks == null) {
arr = [];
} else {
arr = JSON.parse(tasks);
}
arr.splice(index, 1);
localStorage.setItem("testTasks", JSON.stringify(arr));
show();
};
function delAll() {
let tasks = localStorage.getItem("testTasks");
if (tasks == null) {
arr = [];
} else {
arr = JSON.parse(tasks);
}
arr.splice(0, arr.length);
localStorage.setItem("testTasks", JSON.stringify(arr));
show();
};
function bookmark(index) {
let tasks = localStorage.getItem("testTasks");
arr = JSON.parse(tasks);
if (arr[index].includes("*")) {
alert("you have already bookmarked it!");
} else {
arr[index] += " *";
localStorage.setItem("testTasks", JSON.stringify(arr));
show();
}
};
let find = document.getElementById("findTxt");
find.addEventListener("input", function () {
let searchInput = find.value;
let fullTask = document.getElementsByClassName("taskBox");
Array.from(fullTask).forEach(function (element) {
let T = element.getElementsByTagName("p")[0].innerText;
if (T.includes(searchInput)) {
element.style.backgroundColor = "rgb(92 96 88)";
} else {
element.style.backgroundColor = "#343638";
}
});
});