-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (56 loc) · 2.04 KB
/
index.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
// function savelead(){
// }
//how to store array in local storage using json
// let myleads=`["www.eample.com"]`;
// myleads=JSON.parse(myleads);//converts string into array
// myleads.push("www.vibhu.com");
// console.log(myleads);
// let myleads=["www.index.com","www.indes.com"];
// myleads=JSON.stringify(myleads);//converts arrays into sring
// console.log( typeof myleads);
let myleads=[];
const inputel=document.getElementById("input-el");
const ulel=document.getElementById("ul");
// localStorage.setItem("setlinks","www.example.com");
//conosle.log( localStorage.getItem("setlinks"));
// localStorage.clear();
let savetab=document.getElementById("savetab");
savetab.addEventListener("click",function(){
// console.log(tabs[0])
chrome.tabs.query({active:true,currentWindow:true},function(tabs){
myleads.push(tabs[0].url);
localStorage.setItem("mylinks",JSON.stringify(myleads));
renderlead(myleads);
}) ;
})
const leadsfromlocalstroage= JSON.parse(localStorage.getItem("mylinks"))
let doubleclk=document.getElementById("deleteall");
if(leadsfromlocalstroage){
myleads=leadsfromlocalstroage;
renderlead(myleads);
}
const inputbtn = document.getElementById("input-btn");
function renderlead(leads){
let list_items="";
for( let i=0;i<leads.length;i++){
list_items += "<li><a target='_blank' href='#'>"+ leads[i];+ "</a></li>";
// const li=document.createElement("li")
// li.textContent=myleads[i]; alternative
// ulel.append(li);
}
ulel.innerHTML=list_items;
}
inputbtn.addEventListener("click",function (){
myleads.push(inputel.value);
renderlead(myleads);
inputel.value="";
localStorage.setItem("mylinks",JSON.stringify(myleads));
// console.log(localStorage.getItem("mylinks"))
})
doubleclk.addEventListener('dblclick',function(){
localStorage.clear();
myleads=[];
renderlead(myleads);
})
//null->how you signalize emptiness
//undefimed->how js signalize emptiness