-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (50 loc) · 1.62 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
71
72
73
let myLeads = []
const inputBtn = document.getElementById("input-btn")
const inputEl = document.getElementById("input-el")
const ulEL = document.getElementById("ul-el")
const deleteBtn = document.getElementById("delete-btn")
let 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("click", function(){
console.log("dblclick")
localStorage.clear()
myLeads = []
render(myLeads)
})
inputBtn.addEventListener("click", function(){
myLeads.push(inputEl.value)
//console.log(myLeads)
inputEl.value = ""
localStorage.setItem("myLeads",JSON.stringify(myLeads))
render(myLeads)
//console.log( localStorage.getItem("myLeads") )
})
function render(leads){
let listItems = ""
for ( let i = 0; i < myLeads.length; i++){
//ulEL.innerHTML += "<li>" + myLeads[i] + "</li>"
//let li = document.createElement("li")
//li.innerHTML = myLeads[i]
//ulEL.append(li)
//listItems += "<li>" + myLeads[i] + "</li>"
listItems += `
<li>
<a target='_blank' href='${leads[i]}'>
${leads[i]}
</a>
</li>
`
}
ulEL.innerHTML = listItems
}