-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (51 loc) · 1.72 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
//CONSTANTS AND VARIABLE DECLARATIONS
let myLeads = [];
const textEl = document.getElementById("input-el");
const ulEl = document.getElementById("ul-el");
const saveEl = document.getElementById("save-btn");
const leadsFromLocalStorage = JSON.parse(localStorage.getItem("myLeads"));
const dltEl = document.getElementById("dlt-btn");
const savTabEl = document.getElementById("save-tab");
// const tabs = [{ url: "https://instagram.com/neergasm" }];
//fetching data from local storage and checking if it contains any values
if (leadsFromLocalStorage) {
myLeads = leadsFromLocalStorage;
render(myLeads);
} else {
}
//FUNTIONS AND EVENT LISTENERS
//event listener for save button
saveEl.addEventListener("click", function () {
let newText = textEl.value;
myLeads.push(newText);
textEl.value = "";
//text value is cleared or else bugs are appeared
render(myLeads);
localStorage.setItem("myLeads", JSON.stringify(myLeads));
});
//render function for rendering out HTML elements in the HTML document
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>`;
}
ulEl.innerHTML = listItems;
}
//event listener for delete button
dltEl.addEventListener("dblclick", function () {
localStorage.clear();
myLeads = [];
render(myLeads);
});
savTabEl.addEventListener("click", function () {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
console.log(tabs[0]);
myLeads.push(tabs[0].url);
localStorage.setItem("myLeads", JSON.stringify(myLeads));
render(myLeads);
});
});