-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
377 lines (326 loc) · 11.6 KB
/
script.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
var myStorage = window.localStorage;
//myStorage.clear();
var luser;
var email_t;
function removeold(event)
{
document.getElementById("fP").style.display ='none';
const sp= document.getElementById("SP");
sp.style.display = 'block';
}
function removeold2(event)
{
document.getElementById("fP").style.display ='none';
const tp= document.getElementById("TP");
tp.style.display = 'block';
}
const fp = document.getElementById("fP");
const b = fp.getElementsByTagName("button");
b[0].addEventListener("click",removeold);
b[1].addEventListener("click",removeold2);
function saveuser(event)
{
let temp = [];
let temp2 = "{}";
let first_name = document.getElementById('fname').value;
let last_name = document.getElementById('lname').value;
let email = document.getElementById('email').value;
let password = document.getElementById('password').value;
temp = [first_name,last_name,password];
let check = document.getElementById("chkbox").checked;
if(check && first_name != "" && last_name != "" && email != "" && password != "")
{
myStorage.setItem(email,temp);
myStorage.setItem(password,temp2);
luser =password;
document.getElementById("SP").style.display ="none";
const fourp = document.getElementById("FourP");
fourp.style.display ='block';
}
else
{
alert("PLEASE FILL ALL INFORMATION");
}
email_t = email;
document.getElementById('fname').value="";
document.getElementById('lname').value="";
document.getElementById('email').value="";
document.getElementById('password').value="";
}
var count = 0;
var count1 = 0;
function uniqueid()
{
count = count +1;
return count;
}
function uniqueid1()
{
count1 = count1 +1;
return count1;
}
function login(event)
{
let email1 = document.getElementById('email1').value;
let password1 = document.getElementById('pass1').value;
if(email1 === "" || password1 ==="")
{
alert("please fill email/password ");
}
else
{
email_t = email1;
let temp_str = myStorage.getItem(email1);
if(temp_str === null)
{
alert("please fill correctly");
}
else
{
temp_str = temp_str.split(",");
let password2 = temp_str[2];
if(password1 === password2 )
{
luser = password1;
//console.log("login successfully");
document.getElementById("TP").style.display ="none";
const fourp= document.getElementById("FourP");
fourp.style.display ='block';
const list =myStorage.getItem(password1);
var json_obj = JSON.parse(list);
let divf = document.getElementById("first");
const alllis = divf.querySelectorAll(".list");
for(const prop of alllis)
{
divf.removeChild(prop);
}
for(let prop1 in json_obj)
{
let json_div = document.createElement("div");
let br1 = document.createElement("br");
json_div.id = uniqueid();
let h2= document.createElement("h2");
h2.innerText = prop1;
json_div.classList.add("list");
divf.appendChild(json_div);
json_div.appendChild(h2);
let buttonTemp2 = document.createElement("button");
buttonTemp2.id = `b${uniqueid1()}` ;
buttonTemp2.innerHTML=`<i class="fa fa-trash" aria-hidden="true"> DELETE LIST</i>`;
buttonTemp2.addEventListener("click",deletelist)
buttonTemp2.value=(`${prop1}`);
let buttonTemp5= document.createElement("button");
buttonTemp5.id = `b${uniqueid()}`;
buttonTemp5.innerHTML=`<i class="fa fa-plus" aria-hidden="true"> ADD LIST ITEM</i>`;
buttonTemp5.addEventListener("click",Newitem)
buttonTemp5.value=(`${prop1}`);
json_div.appendChild(buttonTemp5);
json_div.appendChild(buttonTemp2);
json_div.appendChild(br1);
json_div.appendChild(br1);
json_obj[prop1].forEach(function(d){
let chkbx = document.createElement("input");
chkbx.id = "chkbox" + uniqueid1();
chkbx.type = "checkbox";
let label = document.createElement("label");
label.id="lbchk"+ uniqueid1();
label.innerText= d;
label.for=chkbx.id;
let br = document.createElement("br");
let buttonTemp = document.createElement("button");
buttonTemp.id = `b${uniqueid1()}` ;
buttonTemp.innerHTML=`<i class="fa fa-trash" aria-hidden="true"></i>`;
buttonTemp.addEventListener("click",deleteitem)
buttonTemp.value=(`${prop1},${d}`);
let div = document.createElement("div");
json_div.appendChild(div);
div.appendChild(chkbx);
div.appendChild(label);
div.appendChild(buttonTemp);
json_div.append(br);});
}
}
}
}
document.getElementById('email1').value = "";
document.getElementById('pass1').value = "";
}
function newlist(event)
{
let fd1 = document.getElementById("third");
let text = fd1.getElementsByTagName("textarea");
let listname = text['txt'].value;
let list_real = myStorage.getItem(luser);
if(list_real ==="{}")
{
x={};
}
else
{
var x= JSON.parse(list_real);
}
if(!(listname in x) == true )
{
x[listname] =[];
let list_obj_str=JSON.stringify(x);
myStorage.setItem(luser,list_obj_str);
let divli = document.createElement("div");
divli.id = uniqueid();
let h2= document.createElement("h2");
h2.innerText = listname;
divli.classList.add("list");
let fd2 = document.getElementById("first");
fd2.appendChild(divli);
divli.appendChild(h2);
let buttonTemp3= document.createElement("button");
buttonTemp3.id = `b${uniqueid1()}` ;
buttonTemp3.innerHTML=`<i class="fa fa-trash" aria-hidden="true"> DELETE LIST</i>`;
buttonTemp3.addEventListener("click",deletelist)
buttonTemp3.value=(`${listname}`);
divli.appendChild(buttonTemp3);
let buttonTemp5= document.createElement("button");
buttonTemp5.id = `b${uniqueid()}`;
buttonTemp5.innerHTML=`<i class="fa fa-plus" aria-hidden="true"> ADD LIST ITEM</i>`;
buttonTemp5.addEventListener("click",Newitem)
buttonTemp5.value=(`${listname}`);
divli.appendChild(buttonTemp5);
let br1 = document.createElement("br");
divli.appendChild(br1);
divli.appendChild(br1);
}
}
function deletelist()
{
let list_real = myStorage.getItem(luser);
let arr= JSON.parse(list_real);
//console.log(arr);
let names = this.value;
//console.log(names[0],names[1]);
delete arr[names]
//console.log(arr[names[0]]);
let list_obj_str=JSON.stringify(arr);
myStorage.setItem(luser,list_obj_str);
this.parentNode.remove();
console.log(myStorage.getItem(luser));
}
function deleteitem()
{
let list_real = myStorage.getItem(luser);
let arr= JSON.parse(list_real);
//console.log(arr);
let names = this.value.split(",");
//console.log(names[0],names[1]);
let i = arr[names[0]];
position = i.indexOf(names[1]);
if(~position)
{arr[names[0]].splice(position, 1);}
//console.log(arr[names[0]]);
let list_obj_str=JSON.stringify(arr);
myStorage.setItem(luser,list_obj_str);
this.parentNode.remove();
}
function Newitem()
{
let d = document.getElementById("d");
let text = d.getElementsByTagName("textarea");
let div = document.createElement("div");
const listitem = text['txt1'].value;
if(listitem !="")
{
let list_real = myStorage.getItem(luser);
var x= JSON.parse(list_real);
x[this.value].push(listitem);
let list_obj_str=JSON.stringify(x);
let chkbx = document.createElement("input");
chkbx.id = "chkbox" + uniqueid1();
chkbx.type = "checkbox";
let label = document.createElement("label");
label.id="lbchk"+ uniqueid1();
label.innerText= listitem;
label.for=chkbx.id;
let br = document.createElement("br");
let buttonTemp = document.createElement("button");
buttonTemp.id = `b${uniqueid1()}` ;
buttonTemp.innerHTML=`<i class="fa fa-trash" aria-hidden="true"></i>`;
buttonTemp.addEventListener("click",deleteitem)
buttonTemp.value=(`${this.value},${listitem}`);
div.appendChild(chkbx);
div.appendChild(label);
div.appendChild(buttonTemp);
this.parentNode.appendChild(div);
this.parentNode.appendChild(br);
myStorage.setItem(luser,list_obj_str);
text['txt1'].value = "";
}
}
function fpp(event)
{
document.getElementById("FourP").style.display = 'none';
document.getElementById("fP").style.display = 'block';
}
function fpp1(event)
{
document.getElementById("FourP").style.display = 'none';
document.getElementById("fiveP").style.display = 'block';
let q = myStorage.getItem(email_t);
let q_parse= q.split(",");
document.getElementById("fname1").value = q_parse[0];
document.getElementById("lname1").value = q_parse[1];
document.getElementById("password1").value = q_parse[2];
document.getElementById("email2").value = email_t;
let p1 = myStorage.getItem(luser);
let p2=p1;
//console.log(myStorage);
function newchanges(event)
{
let temp1 = [];
let first_name1 = document.getElementById('fname1').value;
let last_name1 = document.getElementById('lname1').value;
let ee = document.getElementById('email2').value;
let pass = document.getElementById('password1').value;
temp1 = [first_name1,last_name1,pass];
if(first_name1 != "" && last_name1 != "" && ee != "" && pass != "")
{
myStorage.removeItem(email_t);
myStorage.removeItem(luser);
myStorage.setItem(ee,temp1);
myStorage.setItem(pass,p2);
//luser=pass;
document.getElementById("fiveP").style.display ="none";
const fp1= document.getElementById("fP");
fp1.style.display ='block';
}
else
{
alert("PLEASE FILL ALL INFORMATION");
}
}
const w = document.getElementById("fiveP");
const e = w.getElementsByTagName("button");
e[0].addEventListener("click",newchanges);
}
function back1(event)
{
document.getElementById("SP").style.display ="none";
document.getElementById("fP").style.display ="block";
}
function back(event)
{
document.getElementById("TP").style.display ="none";
document.getElementById("fP").style.display ="block";
}
const sp1 = document.getElementById("SP");
const b1 = sp1.getElementsByTagName("button");
b1['button1'].addEventListener("click", saveuser);
b1['w'].addEventListener("click", back1);
const tp1 = document.getElementById("TP");
const b2 = tp1.getElementsByTagName("button");
b2['button2'].addEventListener("click", login);
b2['q'].addEventListener("click",back);
const fd = document.getElementById("FourP");
const b3 = fd.getElementsByTagName("button");
b3['button3'].addEventListener("click",newlist);
const bd = document.getElementById("bdiv");
const b4 = bd.getElementsByTagName("button");
b4['b1'].addEventListener("click",fpp);
b4['b2'].addEventListener("click",fpp1);