-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (67 loc) · 1.95 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
let myLeads = [];
const inputEl = document.getElementById("input-el")
const inputBtn = document.getElementById("input-btn");
const ulEl = document.getElementById("ul-el");
const deleteBtn = document.getElementById("delete-btn");
const savetabBtn = document.getElementById("savetab-btn");
const leadsFromLocalStorage = JSON.parse(localStorage.getItem("myLeads"));
console.log(leadsFromLocalStorage);
if(leadsFromLocalStorage){
myLeads = leadsFromLocalStorage;
render(myLeads);
}
savetabBtn.addEventListener("click", saveTab);
function saveTab(){
chrome.tabs.query({active:true, currentWindow: true}, function(tabs){
myLeads.push(tabs[0].url)
localStorage.setItem("myLeads", JSON.stringify(myLeads))
render(myLeads)
})
}
function render(leads){
let listItems = "";
for(let i = 0; i < leads.length; i++ ){
//listItems += "<li><a href='" + myLeads[i] + "' target='_blank'>" + myLeads[i] + "</a></li>";
//using template strings instead
listItems += `
<li>
<a href='${leads[i]}' target='_blank'>
${ leads[i]}
</a>
</li>
`
//console.log(listItems);
}
ulEl.innerHTML = listItems;
}
deleteBtn.addEventListener("dblclick", clearLeads);
function clearLeads(){
localStorage.clear();
myLeads = [];
render(myLeads);
}
inputBtn.addEventListener("click", saveLead);
function saveLead(){
myLeads.push(inputEl.value);
inputEl.value = " ";
localStorage.setItem("myLeads", JSON.stringify(myLeads))
render(myLeads);
}
//dynamic functions
/*let welcomeEL = document.getElementById("welcome-el");
function greetUser (greeting, name){
welcomeEL.textContent = `${greeting}, ${name}`
}
greetUser("Welcome back ", "Suzan");
function add(num1, num2){
let result = num1 + num2;
return result;
}
console.log(add(3, 4));
console.log(add(9, 102));
let arrayList = ["suzan", "juliet", "samuel"];
function getFirst(arr){
return arr[0];
}
console.log(getFirst(arrayList));
*/