-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (47 loc) · 1.49 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
let myUrl = []
const inputEl = document.querySelector("#input-el")
const inputBtn = document.querySelector("#input-btn")
const saveBtn = document.querySelector("#save-btn")
const deleteBtn = document.querySelector("#delete-btn")
const fromLocalStorage = JSON.parse( localStorage.getItem("myUrl"))
const outputEl = document.querySelector("#output-el")
let render = (leads) => {
let listitems = ""
myUrl.push(inputEl.value)//getting the text from the input text area
for (let x = 0; x < leads.length; x++) {
listitems += `
<li>
<a target = "_blank" href="${leads[x]}">
${leads[x]}
</a>
</li>
<br/>
`
}/**takes the arrays and adds them to this element
before passing it to the outputEl**/
outputEl.innerHTML = listitems
inputEl.value = ""
localStorage.clear()
}
saveBtn.addEventListener("click", () => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
myUrl.push(tabs[0].url)
localStorage.setItem("myUrl", JSON.stringify(myUrl))
render(myUrl)
})
})
if (fromLocalStorage) {
myUrl = fromLocalStorage
render(myUrl)
}
deleteBtn.addEventListener("dblclick", () => {
localStorage.clear()
myUrl = []
render(myUrl)
})
inputBtn.addEventListener("click", () => {
myUrl.push(inputEl.value)
inputEl.value = ""
localStorage.setItem("myUrl", JSON.stringify(myUrl))
render(myUrl)
})