2020-02-25 21:47:05 +00:00
|
|
|
// defaultSites are loaded from sites.js at installation extension (and are saved to local storage)
|
|
|
|
// var defaultSites = {};
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2020-03-25 18:31:28 +00:00
|
|
|
// Saves options to ext_api.storage
|
2017-07-08 17:40:29 +00:00
|
|
|
function save_options() {
|
|
|
|
var gh_url = document.getElementById('bypass_sites').value;
|
|
|
|
var inputEls = document.querySelectorAll('#bypass_sites input');
|
|
|
|
var sites = {};
|
|
|
|
|
|
|
|
var sites = Array.from(inputEls).reduce(function(memo, inputEl) {
|
|
|
|
if (inputEl.checked) {
|
|
|
|
memo[inputEl.dataset.key] = inputEl.dataset.value;
|
|
|
|
}
|
|
|
|
return memo;
|
|
|
|
}, {});
|
|
|
|
|
2020-03-25 18:31:28 +00:00
|
|
|
ext_api.storage.sync.set({
|
2017-07-08 17:40:29 +00:00
|
|
|
sites: sites
|
|
|
|
}, function() {
|
|
|
|
// Update status to let user know options were saved.
|
|
|
|
var status = document.getElementById('status');
|
2020-03-09 20:11:38 +00:00
|
|
|
status.textContent = 'Options saved.';
|
2017-07-08 17:40:29 +00:00
|
|
|
setTimeout(function() {
|
2020-02-28 15:23:17 +00:00
|
|
|
status.textContent = '';
|
2017-07-08 17:40:29 +00:00
|
|
|
window.close();
|
2020-02-28 15:23:17 +00:00
|
|
|
}, 800);
|
2017-07-08 17:40:29 +00:00
|
|
|
});
|
2020-02-19 17:26:52 +00:00
|
|
|
|
|
|
|
// Refresh the current tab
|
2020-03-25 18:31:28 +00:00
|
|
|
ext_api.tabs.query({
|
2020-03-04 17:19:35 +00:00
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2020-03-25 18:31:28 +00:00
|
|
|
if (tabs[0].url && tabs[0].url.indexOf("http") !== -1) {
|
|
|
|
ext_api.tabs.update(tabs[0].id, {
|
2020-03-04 17:19:35 +00:00
|
|
|
url: tabs[0].url
|
|
|
|
});
|
2020-03-09 20:11:38 +00:00
|
|
|
}
|
2020-03-04 17:19:35 +00:00
|
|
|
});
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 18:31:28 +00:00
|
|
|
// Restores checkbox input states using the preferences stored in ext_api.storage.
|
2020-02-25 21:47:05 +00:00
|
|
|
function renderOptions() {
|
2020-03-25 18:31:28 +00:00
|
|
|
ext_api.storage.sync.get({
|
2020-02-28 15:23:17 +00:00
|
|
|
sites: {}, sites_custom: {}
|
2017-07-08 17:40:29 +00:00
|
|
|
}, function(items) {
|
|
|
|
var sites = items.sites;
|
|
|
|
var sitesEl = document.getElementById('bypass_sites');
|
|
|
|
for (var key in defaultSites) {
|
|
|
|
if (!defaultSites.hasOwnProperty(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var value = defaultSites[key];
|
|
|
|
var labelEl = document.createElement('label');
|
|
|
|
var inputEl = document.createElement('input');
|
|
|
|
inputEl.type = 'checkbox';
|
|
|
|
inputEl.dataset.key = key;
|
|
|
|
inputEl.dataset.value = value;
|
2019-11-05 17:13:46 +00:00
|
|
|
inputEl.checked = (key in sites) || (key.replace(/\s\(.*\)/, '') in sites);
|
2020-02-29 19:08:32 +00:00
|
|
|
if (value !== '###') {
|
2020-01-14 19:02:04 +00:00
|
|
|
labelEl.appendChild(inputEl);
|
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
labelEl.appendChild(document.createTextNode(' '+key));
|
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
}
|
2020-02-28 15:23:17 +00:00
|
|
|
// custom
|
|
|
|
var labelEl = document.createElement('label');
|
|
|
|
labelEl.appendChild(document.createTextNode(' ——— Custom Sites ———'));
|
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
var sites_custom = items.sites_custom;
|
|
|
|
for (var key in sites_custom) {
|
|
|
|
if (defaultSites.hasOwnProperty(key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var value = sites_custom[key]['domain'];
|
|
|
|
var labelEl = document.createElement('label');
|
|
|
|
var inputEl = document.createElement('input');
|
|
|
|
inputEl.type = 'checkbox';
|
|
|
|
inputEl.dataset.key = key;
|
|
|
|
inputEl.dataset.value = value;
|
|
|
|
inputEl.checked = (key in sites) || (key.replace(/\s\(.*\)/, '') in sites);
|
2020-02-29 19:08:32 +00:00
|
|
|
if (value !== '' && value !== '###') {
|
2020-02-28 15:23:17 +00:00
|
|
|
labelEl.appendChild(inputEl);
|
|
|
|
}
|
|
|
|
labelEl.appendChild(document.createTextNode(' '+key));
|
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectAll() {
|
|
|
|
var inputEls = Array.from(document.querySelectorAll('input'));
|
|
|
|
inputEls.forEach(function(inputEl) {
|
|
|
|
inputEl.checked = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectNone() {
|
|
|
|
var inputEls = Array.from(document.querySelectorAll('input'));
|
|
|
|
inputEls.forEach(function(inputEl) {
|
|
|
|
inputEl.checked = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', renderOptions);
|
|
|
|
document.getElementById('save').addEventListener('click', save_options);
|
|
|
|
document.getElementById('select-all').addEventListener('click', selectAll);
|
|
|
|
document.getElementById('select-none').addEventListener('click', selectNone);
|