-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
executable file
·52 lines (46 loc) · 1.62 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
45
46
47
48
49
50
51
52
var siteOptions = chrome.runtime.getManifest().content_scripts[0].matches.map(function(pattern){return pattern.match(/[^\*\.\:\/]+\.[^\s\/]{2,}/)[0]});
function save_options() {
var debug = document.getElementById('debug').checked;
var enabledSites = [];
for (site of siteOptions) {
var siteElement = document.getElementById(site);
if (siteElement.checked === true) {
enabledSites.push(site);
}
}
chrome.storage.sync.set({
debug: debug,
enabledSites: enabledSites
}, function() {
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
function restore_options() {
var sitesContainer = document.getElementById('sites-container');
for (site of siteOptions) {
var siteElement = document.createElement('label');
siteElement.textContent = site;
var siteCheckbox = document.createElement('input');
siteCheckbox.type = 'checkbox';
siteCheckbox.id = site;
siteElement.insertBefore(siteCheckbox, siteElement.firstChild);
sitesContainer.appendChild(siteElement);
sitesContainer.appendChild(document.createElement('br'));
}
chrome.storage.sync.get({
debug: false,
enabledSites: siteOptions
}, function(items) {
document.getElementById('debug').checked = items.debug;
for (site of items.enabledSites) {
var siteElement = document.getElementById(site);
siteElement.checked = true;
}
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);