2019-12-30 21:09:44 +01:00
|
|
|
// defaultSites are loaded from sites(_custom).json at installation extension (and are saved to local storage)
|
|
|
|
var defaultSites = {};
|
2017-07-08 14:16:27 -07:00
|
|
|
|
|
|
|
// Saves options to chrome.storage
|
|
|
|
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;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
chrome.storage.sync.set({
|
|
|
|
sites: sites
|
|
|
|
}, function() {
|
|
|
|
// Update status to let user know options were saved.
|
|
|
|
var status = document.getElementById('status');
|
|
|
|
status.textContent = 'Options saved.';
|
|
|
|
setTimeout(function() {
|
|
|
|
status.textContent = '';
|
|
|
|
window.close();
|
|
|
|
}, 800);
|
|
|
|
});
|
2019-12-29 12:25:09 +01:00
|
|
|
|
|
|
|
// Refresh the current tab
|
|
|
|
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
|
|
|
chrome.tabs.update(tabs[0].id, {url: tabs[0].url});
|
|
|
|
});
|
2017-07-08 14:16:27 -07:00
|
|
|
}
|
|
|
|
|
Move local newspapers to custom & add special characters in sites.json
* special characters in sites.json
*Move to sites_custom.js: Orlando Sentinel (151,000 daily prints), Sun-Sentinel (163,000) San Diego Union-Tribune (121,000), The News-Gazette, The Morning Call, mexiconewsdaily, L.A. Business Journal, baltimore sun, Crain's Chicago Business, l'écho, Winston-Salem Journal, Eindhovens Dagblad, The Examiner, etc.
* remove the two screenshots & changelog.txt (obsolete)
* instructions for Opera/Vivaldi/Brave/Chromium browsers & link to Firefox
* Updates README.md
2020-01-01 20:27:05 +01:00
|
|
|
//Fetch sites.json & sites_custom.json
|
2019-12-20 14:41:41 +01:00
|
|
|
function renderOptions() {
|
2019-12-30 21:09:44 +01:00
|
|
|
const url_sites = chrome.runtime.getURL('sites.json');
|
2019-12-20 14:41:41 +01:00
|
|
|
fetch(url_sites)
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
2019-12-30 21:09:44 +01:00
|
|
|
var defaultSites_merge = {...defaultSites, ...json};
|
2019-12-20 14:41:41 +01:00
|
|
|
defaultSites = defaultSites_merge;
|
2019-12-30 21:09:44 +01:00
|
|
|
// add custom sites
|
|
|
|
const url_sites_custom = 'https://raw.githubusercontent.com/magnolia1234/bypass-paywalls-chrome/master/sites_custom.json';
|
|
|
|
fetch(url_sites_custom)
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
|
|
|
var defaultSites_merge = {...defaultSites, ...json};
|
|
|
|
defaultSites = defaultSites_merge;
|
|
|
|
renderOptions_default();
|
|
|
|
})
|
|
|
|
} else { renderOptions_default(); }
|
|
|
|
} );
|
2019-12-20 14:41:41 +01:00
|
|
|
})
|
|
|
|
} else { renderOptions_default(); }
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2017-07-08 14:16:27 -07:00
|
|
|
// Restores checkbox input states using the preferences
|
|
|
|
// stored in chrome.storage.
|
2019-12-20 14:41:41 +01:00
|
|
|
function renderOptions_default() {
|
2017-07-08 14:16:27 -07:00
|
|
|
chrome.storage.sync.get({
|
|
|
|
sites: {}
|
|
|
|
}, 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 18:11:18 +01:00
|
|
|
inputEl.checked = (key in sites) || (key.replace(/\s\(.*\)/, '') in sites);
|
2019-12-21 14:58:32 +01:00
|
|
|
if (value !=='') {
|
|
|
|
labelEl.appendChild(inputEl);
|
|
|
|
}
|
2017-07-08 14:16:27 -07:00
|
|
|
labelEl.appendChild(document.createTextNode(' '+key));
|
|
|
|
sitesEl.appendChild(labelEl);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|