-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
103 lines (98 loc) · 3.09 KB
/
Copy pathscript.js
File metadata and controls
103 lines (98 loc) · 3.09 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
//Script works on Loading website(contains saved data)
window.onload = function () {
let arr = [];
let str = "";
console.log("Loading");
arrStr = localStorage.getItem('items');
arr = JSON.parse(arrStr);
let tb = document.getElementById("tb");
if (localStorage.getItem('items') == null) {
let str = "";
} else {
arr.forEach((element, index) => {
str += ` <tr>
<th>${index + 1}</th>
<th>${element[0]}</th>
<th>${element[1]}</th>
<th><button id="clc" onclick="clc(${index})">Delete</button></th>
</tr>`
});
}
tb.innerHTML = str;
};
//Script for Date and Time
let d, date, state, arr = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
let t = document.getElementById('t');
setInterval(function () {
d = new Date();
date = d.toLocaleDateString(undefined, arr);
if (d.getHours() >= 12) {
state = 'PM';
}
else {
state = 'AM';
}
t.innerHTML = date + '<br>' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds() + state;
}, 100);
//Script For adding data
add = document.getElementById('add');
add.addEventListener("click", () => {
console.log("Adding Item")
let arr = [];
let t = document.getElementById('title').value;
let d = document.getElementById('desc').value;
if (localStorage.getItem('items') == null) {
arr.push([t, d]);
localStorage.setItem('items', JSON.stringify(arr));
}
else {
arrStr = localStorage.getItem('items');
arr = JSON.parse(arrStr);
arr.push([t, d]);
localStorage.setItem('items', JSON.stringify(arr));
}
let tb = document.getElementById("tb");
let str = "";
arr.forEach((element, index) => {
str += ` <tr>
<th>${index + 1}</th>
<th>${element[0]}</th>
<th>${element[1]}</th>
<th><button id="clc" onclick="clc(${index})">Delete</button></th>
</tr>`
});
tb.innerHTML = str;
location.reload();
});
//Script for Deleting the data
function clc(ind) {
location.reload();
console.log("Deleting");
arrStr = localStorage.getItem('items');
arr = JSON.parse(arrStr);
arr.splice(ind, 1);
localStorage.setItem('items', JSON.stringify(arr));
let tb = document.getElementById("td");
let str = "";
arr.forEach((element, index) => {
str += `<tr>
<td>${index + 1}</td>
<td>${element[0]}</td>
<td id="d">${element[1]}</td>
<td><button id="clc" onclick="clc(${index})">Delete</button></td>
</tr>`
});
tb.innerHTML = str;
};
//Script for Deleting complete list
clearstorage = document.getElementById('clearstorage');
clearstorage.addEventListener('click', function () {
localStorage.clear('items');
console.log("All Items Deleted");
arrStr = localStorage.getItem('items');
arr = JSON.parse(arrStr);
let tb = document.getElementById("tb");
let str = "";
tb.innerHTML = str;
location.reload();
});