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 = {};
|
2020-08-20 17:01:12 +00:00
|
|
|
var ext_api = chrome || browser;
|
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-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.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.';
|
2021-01-05 17:53:59 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
status.textContent = '';
|
|
|
|
}, 800);
|
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-11-24 16:12:47 +00:00
|
|
|
var labelEl;
|
2020-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.get({
|
2021-11-13 10:43:09 +00:00
|
|
|
sites: {},
|
|
|
|
sites_updated: {},
|
|
|
|
sites_custom: {},
|
|
|
|
sites_excluded: []
|
|
|
|
}, function (items) {
|
2017-07-08 17:40:29 +00:00
|
|
|
var sites = items.sites;
|
2021-11-13 10:43:09 +00:00
|
|
|
var sites_updated = items.sites_updated;
|
2021-12-16 16:28:18 +00:00
|
|
|
var sites_updated_domains_new = Object.values(sites_updated).filter(x => x.domain && !defaultSites_domains.includes(x.domain)).map(x => x.domain);
|
2021-11-13 10:43:09 +00:00
|
|
|
var sites_custom = items.sites_custom;
|
2021-12-15 16:44:52 +00:00
|
|
|
var sites_custom_domains = Object.values(sites_custom).filter(x => x.domain).map(x => x.domain);
|
|
|
|
|
2021-12-16 16:28:18 +00:00
|
|
|
var perm_origins = sites_custom_domains.concat(sites_updated_domains_new).map(x => '*://*.' + x + '/*');
|
2021-12-15 16:44:52 +00:00
|
|
|
var perm_custom = document.getElementById('perm-custom');
|
|
|
|
ext_api.permissions.contains({
|
|
|
|
origins: perm_origins
|
|
|
|
}, function (result) {
|
|
|
|
if (result) {
|
|
|
|
perm_custom.innerText = '';
|
|
|
|
} else {
|
|
|
|
perm_custom.textContent = ">> check permissions for custom/updated sites";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-05 17:53:59 +00:00
|
|
|
var sites_excluded = items.sites_excluded;
|
2017-07-08 17:40:29 +00:00
|
|
|
var sitesEl = document.getElementById('bypass_sites');
|
2021-11-13 10:43:09 +00:00
|
|
|
var site_types = {
|
|
|
|
"updated": {
|
|
|
|
sites: sites_updated,
|
2022-11-06 16:02:23 +00:00
|
|
|
title: '* Updated (new) sites (opt-in to custom sites)',
|
2021-11-13 10:43:09 +00:00
|
|
|
default_sites: false
|
|
|
|
},
|
|
|
|
"default": {
|
|
|
|
sites: defaultSites,
|
2022-11-06 16:02:23 +00:00
|
|
|
title: '* Default sites',
|
2021-11-13 10:43:09 +00:00
|
|
|
default_sites: true
|
|
|
|
},
|
|
|
|
"custom": {
|
|
|
|
sites: sites_custom,
|
2022-11-06 16:02:23 +00:00
|
|
|
title: '* Custom (new) sites',
|
2021-11-13 10:43:09 +00:00
|
|
|
default_sites: false
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
2021-11-13 10:43:09 +00:00
|
|
|
};
|
|
|
|
var first = true;
|
|
|
|
for (let site_type in site_types) {
|
|
|
|
if (!first)
|
|
|
|
labelEl.appendChild(document.createElement('hr'));
|
|
|
|
else
|
|
|
|
first = false;
|
2020-11-24 16:12:47 +00:00
|
|
|
labelEl = document.createElement('label');
|
2021-11-13 10:43:09 +00:00
|
|
|
labelEl.setAttribute('style', ' font-weight: bold;');
|
|
|
|
labelEl.appendChild(document.createTextNode(site_types[site_type].title));
|
2020-02-28 15:23:17 +00:00
|
|
|
sitesEl.appendChild(labelEl);
|
2022-04-13 06:13:00 +00:00
|
|
|
let sites_arr = site_types[site_type].sites;
|
|
|
|
for (let key in sites_arr) {
|
|
|
|
let domain = sites_arr[key]['domain'];
|
|
|
|
if (!domain || (!site_types[site_type].default_sites && (defaultSites.hasOwnProperty(key) || defaultSites_domains.includes(domain))))
|
|
|
|
continue;
|
|
|
|
labelEl = document.createElement('label');
|
|
|
|
let inputEl = document.createElement('input');
|
|
|
|
inputEl.type = 'checkbox';
|
|
|
|
inputEl.dataset.key = key;
|
|
|
|
inputEl.dataset.value = domain;
|
|
|
|
inputEl.checked = Object.keys(sites).some(title => compareKey(title, key)) && !sites_excluded.includes(domain);
|
|
|
|
if (domain !== '###') {
|
|
|
|
labelEl.appendChild(inputEl);
|
|
|
|
} else {
|
|
|
|
labelEl.appendChild(document.createElement('hr'));
|
|
|
|
labelEl.setAttribute('style', ' font-weight: bold;');
|
2021-11-13 10:43:09 +00:00
|
|
|
}
|
2022-04-13 06:13:00 +00:00
|
|
|
labelEl.appendChild(document.createTextNode(' ' + key));
|
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
}
|
2020-07-02 10:43:12 +00:00
|
|
|
}
|
2021-01-05 17:53:59 +00:00
|
|
|
// excluded
|
|
|
|
labelEl.appendChild(document.createElement('hr'));
|
|
|
|
labelEl = document.createElement('label');
|
|
|
|
labelEl.setAttribute('style', ' font-weight: bold;');
|
|
|
|
labelEl.appendChild(document.createTextNode('* Excluded Sites (ignored when checked in list)'));
|
2021-11-13 10:43:09 +00:00
|
|
|
sitesEl.appendChild(labelEl);
|
2021-01-05 17:53:59 +00:00
|
|
|
labelEl = document.createElement('label');
|
|
|
|
labelEl.appendChild(document.createTextNode(sites_excluded.join()));
|
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
save_options();
|
2017-07-08 17:40:29 +00:00
|
|
|
});
|
2021-02-17 18:11:27 +00:00
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
|
|
|
|
function selectAll() {
|
|
|
|
var inputEls = Array.from(document.querySelectorAll('input'));
|
2021-03-26 12:05:20 +00:00
|
|
|
inputEls = inputEls.filter(function (input) {
|
2021-11-07 07:47:42 +00:00
|
|
|
return (!input.dataset.value.match(/^#options_(disable|optin)_/));
|
2021-03-26 12:05:20 +00:00
|
|
|
});
|
2021-01-05 17:53:59 +00:00
|
|
|
inputEls.forEach(function (inputEl) {
|
2017-07-08 17:40:29 +00:00
|
|
|
inputEl.checked = true;
|
|
|
|
});
|
2021-01-05 17:53:59 +00:00
|
|
|
// Update status to let user know all sites are selected.
|
|
|
|
var status = document.getElementById('status');
|
|
|
|
status.textContent = 'All sites selected.';
|
|
|
|
setTimeout(function () {
|
|
|
|
status.textContent = '';
|
|
|
|
}, 800);
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function selectNone() {
|
|
|
|
var inputEls = Array.from(document.querySelectorAll('input'));
|
|
|
|
inputEls.forEach(function(inputEl) {
|
|
|
|
inputEl.checked = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-10 17:15:18 +00:00
|
|
|
function closeButton() {
|
2022-01-10 18:08:33 +00:00
|
|
|
window.close();
|
2020-11-10 17:15:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 17:02:07 +00:00
|
|
|
function check_sites_updated() {
|
|
|
|
ext_api.runtime.sendMessage({request: 'check_sites_updated'});
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
2023-07-25 05:21:11 +00:00
|
|
|
function clear_sites_updated() {
|
|
|
|
ext_api.runtime.sendMessage({request: 'clear_sites_updated'});
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
|
2021-08-29 17:59:07 +00:00
|
|
|
function compareKey(firstStr, secondStr) {
|
|
|
|
return firstStr.toLowerCase().replace(/\s\(.*\)/, '') === secondStr.toLowerCase().replace(/\s\(.*\)/, '');
|
2021-08-29 13:15:40 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 17:40:29 +00: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 17:15:18 +00:00
|
|
|
document.getElementById("button-close").addEventListener('click', closeButton);
|
2023-07-25 05:21:11 +00:00
|
|
|
document.getElementById('check_sites_updated').addEventListener('click', check_sites_updated);
|
|
|
|
document.getElementById('clear_sites_updated').addEventListener('click', clear_sites_updated);
|