-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.39 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
// chrome://Extensions
let myLeads = []
let oldLeads = []
const inputEl = document.getElementById("input-el")
const inputBtn = document.getElementById("input-btn")
const ulEL = document.getElementById("ul-el")
const deleteBtn = document.getElementById("delete-btn")
const fromLocalStorage = JSON.parse( localStorage.getItem("myLeads") )
let tabBtn = document.getElementById("tab-btn")
if (fromLocalStorage) {
myLeads = fromLocalStorage
render(myLeads)
}
tabBtn.addEventListener("click", function(){
// console.log(tabs[0].url)
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 (i = 0; i < Leads.length; i++) {
// listItems += "<li><a target='_blank' href='" + myLeads[i] + "'>" + myLeads[i] + "</a></li>"
listItems += `
<li>
<a target='_blank' href='${Leads[i]}'>
${Leads[i]}
</a>
</li>`
}
ulEL.innerHTML = listItems
}
deleteBtn.addEventListener("dblclick", function() {
localStorage.clear()
myLeads = []
render(myLeads)
})
inputBtn.addEventListener("click", function() {
myLeads.push(inputEl.value)
inputEl.value = ""
localStorage.setItem("myLeads", JSON.stringify(myLeads))
render(myLeads)
console.log(localStorage.getItem("myLeads"))
})