-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
66 lines (56 loc) · 1.48 KB
/
extension.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
//ARRAY OF DATA
let myLeads=[]
let ishidden=true
//VARIABLES
const buttonEl=document.getElementById('press')
const inputEl=document.getElementById('input-el')
let showEl=document.getElementById("show-btn")
let ulEl=document.getElementById('ul-el')
let leadsFromLocalStorage=JSON.parse(localStorage.getItem('myLeads'))
let delBtn=document.getElementById('del-btn')
if (leadsFromLocalStorage){
myLeads=leadsFromLocalStorage
console.log(myLeads)
}
//FUNCTIONS
function Pressed(){
myLeads.push(inputEl.value)
inputEl.value=''
// MAKING myLeads A STRING TO SAVE IN LOCAL STORAGE
localStorage.setItem("myLeads", JSON.stringify(myLeads))
console.log(localStorage.getItem("myLeads"))
}
buttonEl.addEventListener("click", Pressed)
function Show(){
ulEl.textContent=''
for(let i=0; i<myLeads.length; i++){
ulEl.innerHTML+=`<li>
<a target='_blank' href=${myLeads[i]}> ${myLeads[i]}
</a>
</li>`
showEl.textContent="Hide Sites"
showEl.removeEventListener('click', Show)
showEl.addEventListener("click", hide)
ishidden=false
}
}
function hide(){
ulEl.textContent=''
showEl.textContent="Show Sites"
showEl.removeEventListener('click',hide)
showEl.addEventListener("click", Show)
ishidden=true
}
showEl.addEventListener('click', function (){
if(ishidden){
Show ()
}
else{
hide()
}
})
function Delete() {
ulEl.textContent=""
localStorage.clear()
}
delBtn.addEventListener("click", Delete)