-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (52 loc) · 1.61 KB
/
script.js
File metadata and controls
65 lines (52 loc) · 1.61 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
let myLeads = []
const inputEl = document.getElementById("input-el")
const inputbtn = document.getElementById("input-btn")
const alertBtn = document.getElementById("alertbtn")
const ulEl = document.getElementById("ul-el")
const deleteBtn = document.getElementById("del-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)
})
})
function render(leads){
let listItems = ""
for (let i=0; i< leads.length; i++) {
listItems += `
<li>
<a target='_blank' href='${myLeads[i]}'>
${leads[i]}
</a>
</li>
`
}
ulEl.innerHTML= listItems
}
deleteBtn.addEventListener("dblclick",function(){
localStorage.clear()
myLeads= []
render(myLeads)
})
inputbtn.addEventListener("click", function() {
alertBtn.textContent = ""
const inputValue = inputEl.value
const netInput = inputValue.split(" ").join("")
if (netInput==="") {
alertBtn.textContent = "Please Input Your Link!"
inputEl.value=""
}else {
myLeads.push(netInput)
inputEl.value=""
localStorage.setItem("myLeads",JSON.stringify(myLeads))
render(myLeads)
console.log(localStorage.getItem("myLeads"))
}
})