-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
44 lines (36 loc) · 1.07 KB
/
options.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
function getSiteName() {
return document.getElementById('name').value;
}
function getSiteUrl() {
return document.getElementById('url').value;
}
function refreshSitesList() {
chrome.storage.local.get(['sites'], function(result) {
if (result && result['sites']) {
result['sites'].forEach(site => {
li = document.createElement('li');
li.innerText = site.name + ' ' + site.url;
document.getElementById('siteList').appendChild(li);
});
}
});
}
function addSite(name, url, callback) {
chrome.storage.local.get(['sites'], function(result) {
var sitesData = result['sites'];
sitesData = sitesData || [];
console.log(result['sites']);
sitesData.push({'name': name, 'url': url});
chrome.storage.local.set({'sites': sitesData}, function() {
console.log('Save successfully for ' + name + ' ' + url);
if (callback) {
callback(name, url);
}
});
});
}
document.getElementById('btnAdd').onclick = function() {
addSite(getSiteName(), getSiteUrl(), function() {
refreshSitesList();
});
};