-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (55 loc) · 1.86 KB
/
script.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 acc = document.getElementsByClassName("accordion");
let i;
let links=[]
let delBtn=document.getElementById("deleteBtn")
let listContainer=document.getElementById("listUrl")
const leadsFromLocalStorage = JSON.parse( localStorage.getItem("links") )
const tabBtn = document.getElementById("tabBtn")
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
}
});
}
if (leadsFromLocalStorage) {
links = leadsFromLocalStorage
render(links)
}
tabBtn.addEventListener("click", function(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
links.push({"title":tabs[0].title,"url":tabs[0].url,"icon":tabs[0].favIconUrl})
localStorage.setItem("links", JSON.stringify(links) )
render(links)
})
})
delBtn.addEventListener("click", function() {
localStorage.clear()
links = []
render(links)
})
function render(listOFlinks){
let savedTabs=document.getElementById("savedTabs")
// savedTabs.innerHTML=`<a>${listOFlinks[0].title}</a>`
let listItems = ""
for (let i = 0; i < listOFlinks.length; i++) {
listItems += `
<div>
<a class="urlLink" target='_blank' href='${listOFlinks[i].url}'>
<img src="./images/newpin.svg" alt="" class="service-icon">
${listOFlinks[i].title}
</a>
</div>
`
// let linkBlock=document.createElement("div")
// let link=document.createElement("a")
// link.setAttribute("href",`${listOFlinks[i].url}`)
// linkBlock.appendChild(link)
// savedTabs.appendChild(linkBlock)
}
savedTabs.innerHTML = listItems
}