-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavaScript.js
74 lines (44 loc) · 1.43 KB
/
JavaScript.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
let myLeads = []
const inputEl = document.getElementById("input")
const List = document.getElementById("list")
const deleteBtn = document.querySelector("#delete-btn")
const saveTab = document.querySelector("#save-tab")
let leadsFromLocalStorage = localStorage.getItem("myleads")
leadsFromLocalStorage = JSON.parse(leadsFromLocalStorage)
if (leadsFromLocalStorage) {
myLeads = leadsFromLocalStorage
renderleads(myLeads)
}
deleteBtn.addEventListener("dblclick", function () {
localStorage.clear()
myLeads = []
renderleads(myLeads)
})
let array = [{ url: " yumnakhan.com" }]
saveTab.addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
myLeads.push(tabs[0].url)
localStorage.setItem('myleads', JSON.stringify(myLeads))
renderleads(myLeads)
})
})
Save = document.getElementById("save")
Save.addEventListener("click", function () {
const value = document.querySelector("input").value;
myLeads.push(value)
document.querySelector('#input').value = '';
leads = JSON.stringify(myLeads)
localStorage.setItem("myleads", leads)
renderleads(myLeads)
})
function renderleads(leads) {
let listItems = []
for (let i = 0;i< leads.length; i += 1) {
listItems += `<li>
<a href=${leads[i]} target='_blank' >
${leads[i]}
</a>
</li>`
}
List.innerHTML = listItems
}