-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (59 loc) · 2.09 KB
/
script.js
File metadata and controls
66 lines (59 loc) · 2.09 KB
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
const saveBtn = document.querySelector('#save-btn');
const urlInput = document.querySelector('#url-input');
const urlEl = document.querySelector('#url-list');
const clearBtn = document.querySelector('#clear-btn');
const saveTabEl = document.querySelector('#save-tab-btn');
let urlList = JSON.parse(localStorage.getItem('urlList')) || [];
if (urlList.length === 0) {
urlEl.style.visibility = 'hidden';
} else {
urlEl.style.visibility = 'visible';
}
let urls = ``;
for (let i = 0; i < urlList.length; i++) {
urls += `<li><a href="${urlList[i]}" target="_blank"> ${urlList[i]} </a></li>`;
}
urlEl.innerHTML += urls;
saveBtn.addEventListener('click', function() {
let currenturl = urlInput.value;
if (!currenturl) {
return;
}
urlEl.style.visibility = 'visible';
urlList.push(currenturl);
localStorage.setItem('urlList', JSON.stringify(urlList));
urlEl.innerHTML += `<li><a href="${currenturl}" target="_blank"> ${currenturl} </a></li>`
urlInput.value = '';
});
urlInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
let currenturl = urlInput.value;
if (!currenturl) {
return;
}
urlEl.style.visibility = 'visible';
urlList.push(currenturl);
localStorage.setItem('urlList', JSON.stringify(urlList));
urlEl.innerHTML += `<li><a href="${currenturl}" target="_blank"> ${currenturl} </a></li>`
urlInput.value = '';
}
});
clearBtn.addEventListener('dblclick', function() {
localStorage.clear();
urlList = [];
urlEl.innerHTML = '';
urlEl.style.visibility = 'hidden';
});
saveTabEl.addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
let currenturl = tabs[0].url;
if (!currenturl) {
return;
}
urlEl.style.visibility = 'visible';
urlList.push(currenturl);
localStorage.setItem('urlList', JSON.stringify(urlList));
urlEl.innerHTML += `<li><a href="${currenturl}" target="_blank"> ${currenturl} </a></li>`
urlInput.value = '';
})
});