bypass-paywalls-firefox/options.js

166 lines
5.5 KiB
JavaScript
Raw Permalink Normal View History

2017-07-08 10:40:29 -07:00
var defaultSites = {
'Algemeen Dagblad': 'ad.nl',
2017-07-08 10:40:29 -07:00
'Baltimore Sun': 'baltimoresun.com',
'Barron\'s': 'barrons.com',
2018-05-05 17:53:07 -07:00
'Bloomberg': 'bloomberg.com',
2019-10-06 10:28:35 -07:00
'Bloomberg Quint': 'bloombergquint.com',
2018-07-07 15:11:09 -07:00
'Business Insider': 'businessinsider.com',
'Caixin': 'caixinglobal.com',
2019-01-05 11:39:45 -08:00
'Chemical & Engineering News': 'cen.acs.org',
2017-07-08 10:40:29 -07:00
'Chicago Tribune': 'chicagotribune.com',
'Central Western Daily': 'centralwesterndaily.com.au',
'Crain\'s Chicago Business': 'chicagobusiness.com',
2018-04-05 23:22:58 -07:00
'Corriere Della Sera': 'corriere.it',
2017-07-08 10:40:29 -07:00
'Daily Press': 'dailypress.com',
'DeMorgen': 'demorgen.be',
2018-07-04 18:46:28 -07:00
'Denver Post': 'denverpost.com',
'De Groene Amsterdammer': 'groene.nl',
'De Tijd': 'tijd.be',
'de Volkskrant': 'volkskrant.nl',
2019-05-12 17:16:58 -07:00
'The Economist (javascript disabled)': 'economist.com',
'Eindhovens Dagblad': 'ed.nl',
2018-10-01 19:03:00 -07:00
'Examiner': 'examiner.com.au',
2017-07-08 10:40:29 -07:00
'Financial Times': 'ft.com',
'Foreign Policy': 'foreignpolicy.com',
2017-07-08 10:40:29 -07:00
'Glassdoor': 'glassdoor.com',
'Haaretz': 'haaretz.co.il',
2018-04-23 02:20:40 -07:00
'Haaretz English': 'haaretz.com',
'Handelsblatt': 'handelsblatt.com',
2017-07-08 10:40:29 -07:00
'Hartford Courant': 'courant.com',
'Harvard Business Review': 'hbr.org',
'Inc.com': 'inc.com',
2019-03-10 13:03:53 -07:00
'Investors Chronicle': 'investorschronicle.co.uk',
2018-12-06 13:23:04 -08:00
'La Repubblica': 'repubblica.it',
'Le Monde': 'lemonde.fr',
'Le Temps': 'letemps.ch',
2017-07-08 10:40:29 -07:00
'Los Angeles Times': 'latimes.com',
2018-01-30 21:08:11 -08:00
'Medium': 'medium.com',
2017-07-08 10:40:29 -07:00
'Medscape': 'medscape.com',
'MIT Technology Review': 'technologyreview.com',
2018-10-28 21:44:18 -07:00
'Mountain View Voice': 'mv-voice.com',
'National Post': 'nationalpost.com',
'New Statesman (javascript disabled)': 'newstatesman.com',
2019-02-18 17:25:35 -08:00
'New York Magazine': 'nymag.com',
2019-06-26 20:26:30 -07:00
'New Zealand Herald': 'nzherald.co.nz',
2017-07-08 10:40:29 -07:00
'Nikkei Asian Review': 'asia.nikkei.com',
'NRC': 'nrc.nl',
2018-10-28 21:44:18 -07:00
'Orange County Register': 'ocregister.com',
'Orlando Sentinel': 'orlandosentinel.com',
'Palo Alto Online': 'paloaltoonline.com',
'Parool': 'parool.nl',
2019-09-29 18:18:59 -07:00
'Quartz': 'qz.com',
2018-10-28 21:44:18 -07:00
'Quora': 'quora.com',
2019-11-01 10:40:39 -07:00
'Scientific American': 'scientificamerican.com',
2019-07-11 10:48:40 -07:00
'Statista': 'statista.com',
2018-10-28 21:44:18 -07:00
'SunSentinel': 'sun-sentinel.com',
'Telegraaf': 'telegraaf.nl',
2018-10-01 19:03:00 -07:00
'The Advocate': 'theadvocate.com.au',
'The Age': 'theage.com.au',
2019-09-29 17:47:26 -07:00
'The Atlantic': 'theatlantic.com',
'The Australian': 'theaustralian.com.au',
2019-09-29 17:34:16 -07:00
'The Australian Financial Review (javascript disabled)': 'afr.com',
2019-09-29 17:27:24 -07:00
'The Boston Globe (javascript disabled)': 'bostonglobe.com',
2018-06-30 12:48:40 -07:00
'The Business Journals': 'bizjournals.com',
2019-05-12 16:40:27 -07:00
'The Diplomat': 'thediplomat.com',
'The Globe and Mail (javascript disabled)': 'theglobeandmail.com',
'The Herald': 'theherald.com.au',
2019-11-02 04:20:28 -07:00
'The Hindu': 'thehindu.com',
2018-09-09 13:21:36 -07:00
'The Japan Times': 'japantimes.co.jp',
2018-10-28 21:44:18 -07:00
'TheMarker': 'themarker.com',
2018-01-30 21:08:11 -08:00
'The Mercury News': 'mercurynews.com',
2019-10-31 18:31:54 -07:00
'The Mercury Tasmania': 'themercury.com.au',
2017-07-08 10:40:29 -07:00
'The Morning Call': 'mcall.com',
'The Nation': 'thenation.com',
'The New York Times': 'nytimes.com',
'The New Yorker': 'newyorker.com',
2019-01-05 11:39:45 -08:00
'The News-Gazette': 'news-gazette.com',
'The Saturday Paper': 'thesaturdaypaper.com.au',
2018-07-22 19:04:27 -07:00
'The Spectator': 'spectator.co.uk',
2017-07-08 10:40:29 -07:00
'The Seattle Times': 'seattletimes.com',
'The Sydney Morning Herald': 'smh.com.au',
'The Telegraph': 'telegraph.co.uk',
'The Times': 'thetimes.co.uk',
2019-06-21 21:12:14 -07:00
'The Toronto Star (javascript disabled)': 'thestar.com',
2017-07-08 10:40:29 -07:00
'The Washington Post': 'washingtonpost.com',
2018-06-03 11:23:04 -07:00
'The Wall Street Journal': 'wsj.com',
'Towards Data Science': 'towardsdatascience.com',
'Trouw': 'trouw.nl',
'Vanity Fair': 'vanityfair.com',
'Vrij Nederland': 'vn.nl',
2018-10-01 19:03:00 -07:00
'Wired': 'wired.com'
2017-07-08 10:40:29 -07:00
};
// Saves options to browser.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;
}, {});
browser.storage.sync.set({
sites: sites
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
2018-10-06 22:18:34 -07:00
status.textContent = 'Options saved.';
2017-07-08 10:40:29 -07:00
setTimeout(function() {
// status.textContent = '';
window.close();
}, 500);
});
}
// Restores checkbox input states using the preferences
// stored in browser.storage.
function renderOptions() {
browser.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);
2017-07-08 10:40:29 -07:00
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);