-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (55 loc) · 1.79 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
54
55
56
57
58
59
60
61
62
63
let myLeads = []
let oldLeads = []
const inputEl = document.getElementById("input-el")
const button = document.getElementById("input-btn")
const ulEl = document.getElementById("ul-el")
const deleteBtn = document.getElementById("delete-btn")
const saveTab = document.getElementById("save-btn")
const leadsFromLocalStorage = JSON.parse(localStorage.getItem("myLeads"))
if(leadsFromLocalStorage){
myLeads = leadsFromLocalStorage
renderLeads(myLeads)
}
// const tabs = [
// {url: "https://www.linkedin.com/in/pratham-goswami-331aa7240/"}
// ]
saveTab.addEventListener("click", function(){
chrome.tabs.query({active: true}, function(tabs){
myLeads.push(tabs[0].url)
localStorage.setItem("myLeads", JSON.stringify(myLeads))
renderLeads(myLeads)
})
})
function renderLeads(leads) {
let listItems = "" //variable to hold the list items
for (let i = 0; i < leads.length; i++) {
// listItems += "<li><a target='_blank' href = '" + myLeads[i] + "'>" + myLeads[i] + "</a></li>"
//Using Template on the next line
listItems += `
<li>
<a target='_blank' href = '${leads[i]}'>${leads[i]}</a>
</li> `
}
ulEl.innerHTML = listItems
}
//Approach one
// function save(){
// button.textContent = "Button Clicked!"
// console.log(button)
// }
deleteBtn.addEventListener("click", function(){
console.log("double clicked!")
localStorage.clear()
myLeads = []
renderLeads(myLeads)
})
//Approach two
button.addEventListener("click", function(){
// button.textContent = "Button Clicked!"
myLeads.push(inputEl.value)
inputEl.value = ""
localStorage.setItem("myLeads", JSON.stringify(myLeads))
//To check if it is working or not
console.log(localStorage.getItem("myLeads"))
renderLeads(myLeads)
})