-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchromeExtensions.js
79 lines (58 loc) · 1.99 KB
/
chromeExtensions.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
74
75
76
77
let myLeads =[]
let button =document.querySelector("#input-btn")
let inputEl= document.querySelector("#input-el")
const ulEl = document.querySelector("#ul-el")
const deleteBtn =document.querySelector("#delete-btn")
const saveBtn=document.querySelector("#tab-btn")
// rendering the item from localstorage and appending to the page
const leadsFromLocalStorage= JSON.parse( localStorage.getItem("myLeads") )
// if (leadsFromLocalStorage){
// myLeads=leadsFromLocalStorage
// renderleads()
// }
saveBtn.addEventListener("click", function (){
// Grab URL of the current tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// since only one tab should be active and in the current window at once
// the return variable should only have one entry
myLeads.push(tabs[0].url)
localStorage.setItem("myLeads", JSON.stringify(myLeads) )
renderleads()
// console.log(tab[0].url)
});
})
button.addEventListener("click", function (){
myLeads.push(inputEl.value)
inputEl.value=""
// setting data in the local storage
localStorage.setItem("myLeads", JSON.stringify(myLeads) )
renderleads()
// console.log(localStorage.getItem("myLeads" ))
// the input fill is focussed
inputEl.focus()
})
renderleads=()=>{
let listItems = ""
for(let i=0; i<myLeads.length; i++){
listItems+=
`<li>
<a target='_blank' href='${myLeads[i]}' >
${myLeads[i]}
</a>
</li>`
}
ulEl.innerHTML=listItems
}
if (leadsFromLocalStorage){
myLeads=leadsFromLocalStorage
renderleads()
}
deleteBtn.addEventListener("click", function(){
// clearing the local storage using the delete button
localStorage.clear()
// setting the myLeads variable to an empty array
myLeads=[]
// calling the renderleads function after clearing it content
renderleads()
})
// -----------------------------------------------------------------------