-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
50 lines (41 loc) · 1.24 KB
/
popup.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
function buildUI (sitesData) {
window.sitesData = sitesData;
if (!sitesData) {
console.log("No sites data is configured yet.");
span = document.createElement('span');
span.innerText = "Go to option page to add sites.";
document.appendChild(span);
return;
}
sitesData.forEach(site => {
li = document.createElement('li');
button = document.createElement('button');
button.className = 'gray light';
link = document.createElement('a');
link.href = site.url;
link.target = "_blank";
link.innerText = site.name;
li.appendChild(button);
li.appendChild(link);
document.getElementById("placeholder").appendChild(li);
});
}
function refreshPopup() {
chrome.storage.local.get(['sites'], function(result) {
if (result) {
console.log('value is ' + JSON.stringify(result['sites']));
buildUI(result['sites']);
}
else {
console.log("sites data not found");
}
});
}
function cleanAll() {
document.getElementById('placeholder').innerText = "";
}
window.onload = function() {
console.log("window.onload ...");
cleanAll();
refreshPopup();
}