2020-02-25 22:35:21 +01:00
|
|
|
// defaultSites are loaded from sites.js at installation extension (and are saved to local storage)
|
|
|
|
// var defaultSites = {};
|
2020-08-20 19:00:57 +02:00
|
|
|
var ext_api = chrome || browser;
|
2017-07-08 14:16:27 -07:00
|
|
|
|
2020-03-25 19:27:07 +01:00
|
|
|
// Saves options to ext_api.storage
|
2017-07-08 14:16:27 -07: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-10-31 20:05:21 +01:00
|
|
|
ext_api.storage.local.set({
|
2017-07-08 14:16:27 -07:00
|
|
|
sites: sites
|
|
|
|
}, function() {
|
|
|
|
// Update status to let user know options were saved.
|
|
|
|
var status = document.getElementById('status');
|
|
|
|
status.textContent = 'Options saved.';
|
2020-02-20 21:59:10 +01:00
|
|
|
});
|
2017-07-08 14:16:27 -07:00
|
|
|
}
|
|
|
|
|
2020-03-25 19:27:07 +01:00
|
|
|
// Restores checkbox input states using the preferences stored in ext_api.storage.
|
2019-12-20 14:41:41 +01:00
|
|
|
function renderOptions() {
|
2020-10-31 20:05:21 +01:00
|
|
|
ext_api.storage.local.get({
|
2020-02-27 22:51:31 +01:00
|
|
|
sites: {}, sites_custom: {}
|
2017-07-08 14:16:27 -07:00
|
|
|
}, function(items) {
|
|
|
|
var sites = items.sites;
|
|
|
|
var sitesEl = document.getElementById('bypass_sites');
|
2020-07-02 12:42:39 +02:00
|
|
|
var clean_key;
|
2017-07-08 14:16:27 -07:00
|
|
|
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;
|
2020-07-02 12:42:39 +02:00
|
|
|
clean_key = key.replace(/\s\(.*\)/, '');
|
|
|
|
inputEl.checked = Object.keys(sites).some(title => (title.replace(/\s\(.*\)/, '') === clean_key));
|
2020-03-09 21:09:42 +01:00
|
|
|
if (value !== '###') {
|
2020-07-02 12:42:39 +02:00
|
|
|
labelEl.appendChild(inputEl);
|
2019-12-21 14:58:32 +01:00
|
|
|
}
|
2020-07-02 12:42:39 +02:00
|
|
|
labelEl.appendChild(document.createTextNode(' ' + key));
|
2017-07-08 14:16:27 -07:00
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
}
|
2020-07-02 12:42:39 +02:00
|
|
|
// custom
|
2020-02-27 22:51:31 +01:00
|
|
|
var labelEl = document.createElement('label');
|
|
|
|
labelEl.appendChild(document.createTextNode(' ——— Custom Sites ———'));
|
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
var sites_custom = items.sites_custom;
|
2020-08-20 19:00:57 +02:00
|
|
|
var defaultSites_domains = ext_api.extension.getBackgroundPage().defaultSites_domains;
|
2020-07-02 12:42:39 +02:00
|
|
|
for (var key in sites_custom) {
|
2020-08-20 19:00:57 +02:00
|
|
|
var domain = sites_custom[key]['domain'];
|
|
|
|
if (defaultSites.hasOwnProperty(key) || defaultSites_domains.includes(domain)) {
|
2020-02-27 22:51:31 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var labelEl = document.createElement('label');
|
|
|
|
var inputEl = document.createElement('input');
|
|
|
|
inputEl.type = 'checkbox';
|
|
|
|
inputEl.dataset.key = key;
|
2020-08-20 19:00:57 +02:00
|
|
|
inputEl.dataset.value = domain;
|
2020-07-02 12:42:39 +02:00
|
|
|
clean_key = key.replace(/\s\(.*\)/, '');
|
|
|
|
inputEl.checked = Object.keys(sites).some(title => (title.replace(/\s\(.*\)/, '') === clean_key));
|
|
|
|
if (value !== '' && value !== '###') {
|
2020-02-27 22:51:31 +01:00
|
|
|
labelEl.appendChild(inputEl);
|
|
|
|
}
|
|
|
|
labelEl.appendChild(document.createTextNode(' '+key));
|
|
|
|
sitesEl.appendChild(labelEl);
|
2020-07-02 12:42:39 +02:00
|
|
|
}
|
2017-07-08 14:16:27 -07: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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-10 18:14:47 +01:00
|
|
|
function closeButton() {
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
|
2017-07-08 14:16:27 -07:00
|
|
|
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);
|
2020-11-10 18:14:47 +01:00
|
|
|
document.getElementById("button-close").addEventListener('click', closeButton);
|