-
Notifications
You must be signed in to change notification settings - Fork 0
/
chrome.js
73 lines (53 loc) · 1.44 KB
/
chrome.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 lead = []
const inputEl = document.getElementById("input-el")
const inputBtn = document.getElementById("input-btn")
const tabBtn = document.getElementById("tab-btn")
const deleteBtn = document.getElementById("delete-btn")
const ulEl = document.getElementById("ul-el")
const leadFromLocal = JSON.parse(localStorage.getItem("leadStore"))
if (leadFromLocal)
{
lead = leadFromLocal
render(lead)
}
tabBtn.addEventListener("click", function ()
{
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
lead.push(tabs[0].url)
localStorage.setItem("leadStore",JSON.stringify(lead))
render(lead)
})
})
function render(lead)
{
let li = ""
for(let i=0; i< lead.length; i++)
{
li += `<li>
<a href="${lead[i]}" target="_blank">
${lead[i]}
</a>
</li>`
}
ulEl.innerHTML = li
}
inputBtn.addEventListener("click",function()
{
if (inputEl.value != "")
{
lead.push(inputEl.value)
inputEl.value= ""
localStorage.setItem("leadStore",JSON.stringify(lead))
render(lead)
}
})
deleteBtn.addEventListener("dblclick",function()
{
localStorage.clear()
ulEl.innerHTML = ""
lead = []
})
// localStorage.setItem("shak","sweety")
// console.log(localStorage.getItem("shak"))
// localStorage.clear()
// inputEl.value = localStorage.getItem("shak")