bypass-paywalls-firefox-clean/options.js

150 lines
4.9 KiB
JavaScript
Raw Normal View History

2017-07-08 19:40:29 +02:00
var defaultSites = {
'Baltimore Sun': 'baltimoresun.com',
'Barron\'s': 'barrons.com',
2018-05-06 02:53:07 +02:00
'Bloomberg': 'bloomberg.com',
2018-07-08 00:11:09 +02:00
'Business Insider': 'businessinsider.com',
'Caixin': 'caixinglobal.com',
2019-01-05 20:39:45 +01:00
'Chemical & Engineering News': 'cen.acs.org',
2017-07-08 19:40:29 +02:00
'Chicago Tribune': 'chicagotribune.com',
'Central Western Daily': 'centralwesterndaily.com.au',
'Crain\'s Chicago Business': 'chicagobusiness.com',
2018-04-06 08:22:58 +02:00
'Corriere Della Sera': 'corriere.it',
2017-07-08 19:40:29 +02:00
'Daily Press': 'dailypress.com',
2018-07-05 03:46:28 +02:00
'Denver Post': 'denverpost.com',
'De Tijd': 'tijd.be',
'de Volkskrant': 'volkskrant.nl',
2017-07-08 19:40:29 +02:00
'The Economist': 'economist.com',
2018-10-02 04:03:00 +02:00
'Examiner': 'examiner.com.au',
2017-07-08 19:40:29 +02:00
'Financial Times': 'ft.com',
'Foreign Policy': 'foreignpolicy.com',
2017-07-08 19:40:29 +02:00
'Glassdoor': 'glassdoor.com',
'Haaretz': 'haaretz.co.il',
2018-04-23 11:20:40 +02:00
'Haaretz English': 'haaretz.com',
'Handelsblatt': 'handelsblatt.com',
2017-07-08 19:40:29 +02:00
'Hartford Courant': 'courant.com',
'Harvard Business Review': 'hbr.org',
'Inc.com': 'inc.com',
2019-03-10 21:03:53 +01:00
'Investors Chronicle': 'investorschronicle.co.uk',
'Irish Times': 'irishtimes.com',
2018-12-06 22:23:04 +01:00
'La Repubblica': 'repubblica.it',
'Le Temps': 'letemps.ch',
2017-07-08 19:40:29 +02:00
'Los Angeles Times': 'latimes.com',
2018-01-31 06:08:11 +01:00
'Medium': 'medium.com',
2017-07-08 19:40:29 +02:00
'Medscape': 'medscape.com',
'MIT Technology Review': 'technologyreview.com',
2018-10-29 05:44:18 +01:00
'Mountain View Voice': 'mv-voice.com',
'National Post': 'nationalpost.com',
2018-07-23 03:55:35 +02:00
'New Statesman': 'newstatesman.com',
2019-02-19 02:25:35 +01:00
'New York Magazine': 'nymag.com',
2017-07-08 19:40:29 +02:00
'Nikkei Asian Review': 'asia.nikkei.com',
'NRC': 'nrc.nl',
2018-10-29 05:44:18 +01:00
'Orange County Register': 'ocregister.com',
'Orlando Sentinel': 'orlandosentinel.com',
'Palo Alto Online': 'paloaltoonline.com',
'Quora': 'quora.com',
'SunSentinel': 'sun-sentinel.com',
2019-03-10 21:00:00 +01:00
'Tech in Asia': 'techinasia.com',
2018-10-02 04:03:00 +02:00
'The Advocate': 'theadvocate.com.au',
'The Age': 'theage.com.au',
'The Australian': 'theaustralian.com.au',
2018-12-18 08:45:33 +01:00
'The Australian Financial Review': 'afr.com',
2018-01-31 06:08:11 +01:00
'The Boston Globe': 'bostonglobe.com',
2018-06-30 21:48:40 +02:00
'The Business Journals': 'bizjournals.com',
'The Globe and Mail (javascript disabled)': 'theglobeandmail.com',
'The Herald': 'theherald.com.au',
2018-09-09 22:21:36 +02:00
'The Japan Times': 'japantimes.co.jp',
2018-10-29 05:44:18 +01:00
'TheMarker': 'themarker.com',
2018-01-31 06:08:11 +01:00
'The Mercury News': 'mercurynews.com',
2017-07-08 19:40:29 +02:00
'The Morning Call': 'mcall.com',
'The Nation': 'thenation.com',
'The New York Times': 'nytimes.com',
'The New Yorker': 'newyorker.com',
2019-01-05 20:39:45 +01:00
'The News-Gazette': 'news-gazette.com',
'The Saturday Paper': 'thesaturdaypaper.com.au',
2018-07-23 04:04:27 +02:00
'The Spectator': 'spectator.co.uk',
2017-07-08 19:40:29 +02:00
'The Seattle Times': 'seattletimes.com',
'The Sydney Morning Herald': 'smh.com.au',
'The Telegraph': 'telegraph.co.uk',
'The Times': 'thetimes.co.uk',
2018-08-29 01:15:23 +02:00
'The Toronto Star': 'thestar.com',
2017-07-08 19:40:29 +02:00
'The Washington Post': 'washingtonpost.com',
2018-06-03 20:23:04 +02:00
'The Wall Street Journal': 'wsj.com',
'Towards Data Science': 'towardsdatascience.com',
'Vanity Fair': 'vanityfair.com',
2018-10-02 04:03:00 +02:00
'Wired': 'wired.com'
2017-07-08 19:40:29 +02: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-07 07:18:34 +02:00
status.textContent = 'Options saved.';
2017-07-08 19:40:29 +02: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;
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);