Bela Lubkin 1c3d8d622c Merge 'bypass-paywalls-firefox' extension into 'bypass-paywalls-chrome'
- include the best versions of everything (to the best of my ability...)
- include all supported sites
- update docs to always point to 'bypass-paywalls-chrome' repository
- update docs to be -- not browser-agnostic, but poly-browser
- (tested the 1st 11 sites in alphabetical order, plus WSJ -- using Opera)
- cen.acs.org: retain localstorage ('cookie warning' accepted)
- cen.acs.org: remove .meteredBar '2/3 articles remaining' bar
- XXX centralwesterndaily.com.au: not working (article window-shaded)
- all others tested seem fine (intentionally provoked failures w/ bypass
  disabled, demonstrated success when enabled)
- (end of alphabetical testing)
- move defaultSites{} from background.js & options.js to common.js
- uncertain whether FF contentScript.js code for businessinsider.com,
  haaretz.co.il, wsj.com was helpful, I left them commented out
- use browser-agnostic 'extension_api.*' in place of browser.*, chrome.*
- use 'comma-on-last-item' syntax to allow insertion & sorting without
  breaking structures, minimize commit footprints
- replace 'location.whatever' refs with consistent 'window.location.whatever'
- break structure inits into multi-line format where appropriate
- convert TABs to spaces (background.js had 2-space tabs, manifest.json 4!)
- remove trailing spaces
- sort tables which ought to be sorted, consistently using Linux `LANG=C sort`
  (strict ASCII ordering)
- XXX use of window.location.href.indexOf() considered harmful: for instance,
  'ft.com' will match 'loft.com', or 'ibm.co' (Columbia) matches 'ibm.com';
  intend to replace with something like hostDomainIs('ft.com') -- not now
- XXX Firefox completely untested; I believe a *.xpi with manifest-ff.json
  in place of manifest.json will work, but have not tried
- XXX did not attempt to update updates.json (FF), updates.xml (Chrome)
- XXX why do bypass.svg, *_screenshot.png exist?  At least should not be
  included in *.crx, *.xpi
- XXX same Google Analytics code now in FF build, not sure if this is OK
- version arbitrarily slammed to '1.7.0' (could be '2.0.0')
- code delta -283 lines (mainly defaultSites{}); or -1585 + 3 binaries,
  counting prospective retirement of 'bypass-paywalls-firefox'
- should have been something like 20 separate commits, but got out of hand...

(note 'XXX' problem areas)
2020-03-19 11:04:17 -07:00

73 lines
2.2 KiB
JavaScript

// Saves options to extension_api.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;
}, {});
extension_api.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);
});
}
// Restores checkbox input states using the preferences
// stored in extension_api.storage.
function renderOptions() {
extension_api.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;
inputEl.checked = (key in sites) || (key.replace(/\s\(.*\)/, '') in sites);
labelEl.appendChild(inputEl);
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);