-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (54 loc) · 1.79 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
let link = "";
let lead = JSON.parse(localStorage.getItem("link"));
const inputField = document.getElementById("inputField");
const inputFieldButton = document.getElementById("inputFieldButton");
const container = document.getElementById("container");
window.addEventListener("load", loadAndDisplay);
document.getElementById("inputFieldButton").addEventListener("click", saveLink);
document.getElementById("deleteFieldButton").addEventListener("dblclick", deleteLead);
document.getElementById("grabTabLink").addEventListener("click", grabTabLink);
function loadAndDisplay() {
if (lead == null) {
lead = [];
} else if (lead == "") {
document.getElementById("ulTag").innerHTML = "";
lead = [];
} else {
let list = "";
for (let i = 0; i < lead.length; i++) {
list += `<li>
<a target='_blank' href='${lead[i]}'>${lead[i]}</a>
</li>`
}
document.getElementById("ulTag").innerHTML = list;
}
}
async function grabTabLink() {
await chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
inputField.value = tabs[0].url;
link = inputField.value;
});
}
function saveLink() {
let list = "";
if (link != "") {
inputField.value = link;
link = "";
}
if (inputField.value != "") {
lead.push(inputField.value);
for (let i = 0; i < lead.length; i++) {
list += `<li>
<a target='_blank' href='${lead[i]}'>${lead[i]}</a>
</li>`
}
document.getElementById("ulTag").innerHTML = list;
localStorage.setItem("link", JSON.stringify(lead));
inputField.value = "";
}
}
function deleteLead() {
localStorage.clear();
lead = "";
loadAndDisplay();
}