-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (41 loc) · 1.15 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
let myleads=[]
const inputEl=document.getElementById("input-el")
let Button=document.getElementById("input-btn")
const ulEl=document.getElementById("like")
const deleteBtn=document.getElementById("delete-btn")
const leadsFromlocalStorage=JSON.parse(localStorage.getItem("myleads"))
const tabBtn=document.getElementById("tab-btn")
if(leadsFromlocalStorage){
myleads=leadsFromlocalStorage
render(myleads)
}
tabBtn.addEventListener("click",function(){
chrome.tabs.query({active:true,currentWindow:true},function(tabs){
myleads.push(tabs[0].url)
localStorage.setItem("myleads",JSON.stringify(myleads))
render(myleads)
})
})
deleteBtn.addEventListener("dblclick",function(){
localStorage.clear()
myleads=[]
render(myleads)
})
Button.addEventListener("click",function(){
myleads.push(inputEl.value);
inputEl.value=""
localStorage.setItem("myleads",JSON.stringify(myleads))
render(myleads)
})
function render(leads){
let listItems =""
for(let i=0;i<leads.length;i++){
listItems+= `
<li>
<a target='_blank' href='${leads[i]}'>
${leads[i]}
</a>
</li>`
}
ulEl.innerHTML=listItems
}