2017-07-08 19:40:29 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var defaultSites = {
|
2019-10-14 14:52:27 +02:00
|
|
|
'Algemeen Dagblad': 'ad.nl',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Baltimore Sun': 'baltimoresun.com',
|
2017-09-15 07:17:10 +02:00
|
|
|
'Barron\'s': 'barrons.com',
|
2018-05-06 02:53:07 +02:00
|
|
|
'Bloomberg': 'bloomberg.com',
|
2019-10-06 19:28:35 +02:00
|
|
|
'Bloomberg Quint': 'bloombergquint.com',
|
2018-07-08 00:11:09 +02:00
|
|
|
'Business Insider': 'businessinsider.com',
|
2018-07-16 06:43:40 +02:00
|
|
|
'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',
|
2018-10-29 05:17:36 +01:00
|
|
|
'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',
|
2019-11-17 17:06:30 +01:00
|
|
|
'DeMorgen': 'demorgen.be',
|
2018-07-05 03:46:28 +02:00
|
|
|
'Denver Post': 'denverpost.com',
|
2019-02-02 23:52:20 +01:00
|
|
|
'De Tijd': 'tijd.be',
|
2019-10-14 14:52:27 +02:00
|
|
|
'De Groene Amsterdammer': 'groene.nl',
|
2019-04-06 23:47:59 +02:00
|
|
|
'de Volkskrant': 'volkskrant.nl',
|
2019-12-08 06:49:23 +01:00
|
|
|
'ET Prime': 'prime.economictimes.indiatimes.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'The Economist': 'economist.com',
|
2019-10-14 14:52:27 +02:00
|
|
|
'Eindhovens Dagblad': 'ed.nl',
|
2018-10-02 03:52:35 +02:00
|
|
|
'Examiner': 'examiner.com.au',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Financial Times': 'ft.com',
|
2018-11-12 00:42:17 +01:00
|
|
|
'Foreign Policy': 'foreignpolicy.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
'Glassdoor': 'glassdoor.com',
|
2018-12-02 05:33:21 +01:00
|
|
|
'Haaretz': 'haaretz.co.il',
|
2018-04-23 11:20:40 +02:00
|
|
|
'Haaretz English': 'haaretz.com',
|
2019-04-06 23:47:59 +02:00
|
|
|
'Handelsblatt': 'handelsblatt.com',
|
2019-12-07 19:28:19 +01:00
|
|
|
'Harper\'s Magazine': 'harpers.org',
|
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',
|
2018-12-06 22:23:04 +01:00
|
|
|
'La Repubblica': 'repubblica.it',
|
2019-11-02 12:07:01 +01:00
|
|
|
'Le Monde': 'lemonde.fr',
|
2019-12-10 20:08:01 +01:00
|
|
|
'Le Parisien': 'leparisien.fr',
|
2017-09-15 07:17:10 +02:00
|
|
|
'Le Temps': 'letemps.ch',
|
2019-12-03 11:53:30 +01:00
|
|
|
'London Review of Books': 'lrb.co.uk',
|
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',
|
2019-04-06 23:47:59 +02:00
|
|
|
'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',
|
2019-12-07 22:26:58 +01:00
|
|
|
'NK News': 'nknews.org',
|
2017-07-08 19:40:29 +02:00
|
|
|
'NRC': 'nrc.nl',
|
2019-06-27 05:26:30 +02:00
|
|
|
'New Zealand Herald': 'nzherald.co.nz',
|
2018-10-29 05:44:18 +01:00
|
|
|
'Orange County Register': 'ocregister.com',
|
|
|
|
'Orlando Sentinel': 'orlandosentinel.com',
|
|
|
|
'Palo Alto Online': 'paloaltoonline.com',
|
2019-10-14 14:52:27 +02:00
|
|
|
'Parool': 'parool.nl',
|
2019-09-30 03:18:59 +02:00
|
|
|
'Quartz': 'qz.com',
|
2018-10-29 05:44:18 +01:00
|
|
|
'Quora': 'quora.com',
|
2019-11-01 18:25:06 +01:00
|
|
|
'Scientific American': 'scientificamerican.com',
|
2019-07-11 19:48:40 +02:00
|
|
|
'Statista': 'statista.com',
|
2018-10-29 05:44:18 +01:00
|
|
|
'SunSentinel': 'sun-sentinel.com',
|
2019-11-01 18:25:06 +01:00
|
|
|
'Telegraaf': 'telegraaf.nl',
|
2018-10-02 03:52:35 +02:00
|
|
|
'The Advocate': 'theadvocate.com.au',
|
2019-04-07 01:34:30 +02:00
|
|
|
'The Age': 'theage.com.au',
|
2019-09-30 02:47:26 +02:00
|
|
|
'The Atlantic': 'theatlantic.com',
|
2019-04-07 01:34:30 +02:00
|
|
|
'The Australian': 'theaustralian.com.au',
|
2018-12-18 08:45:33 +01:00
|
|
|
'The Australian Financial Review': 'afr.com',
|
2019-09-30 02:27:24 +02:00
|
|
|
'The Boston Globe': 'bostonglobe.com',
|
2018-06-30 21:48:40 +02:00
|
|
|
'The Business Journals': 'bizjournals.com',
|
2019-05-13 01:40:27 +02:00
|
|
|
'The Diplomat': 'thediplomat.com',
|
2018-06-23 04:58:07 +02:00
|
|
|
'The Globe and Mail': 'theglobeandmail.com',
|
2018-10-29 05:17:36 +01:00
|
|
|
'The Herald': 'theherald.com.au',
|
2019-11-02 12:20:28 +01:00
|
|
|
'The Hindu': 'thehindu.com',
|
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',
|
2019-10-29 00:25:53 +01:00
|
|
|
'The Mercury Tasmania': 'themercury.com.au',
|
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',
|
2019-12-08 19:34:26 +01:00
|
|
|
'The Philadelphia Inquirer': 'inquirer.com',
|
2019-02-02 23:52:20 +01:00
|
|
|
'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',
|
2019-10-23 13:06:43 +02:00
|
|
|
'The Telegraph': 'telegraph.co.uk',
|
2019-04-07 01:34:30 +02:00
|
|
|
'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',
|
2019-12-05 21:32:20 +01:00
|
|
|
'Times Literary Supplement': 'the-tls.co.uk',
|
2018-07-23 04:22:07 +02:00
|
|
|
'Towards Data Science': 'towardsdatascience.com',
|
2019-10-14 14:52:27 +02:00
|
|
|
'Trouw': 'trouw.nl',
|
2018-06-23 04:58:07 +02:00
|
|
|
'Vanity Fair': 'vanityfair.com',
|
2019-10-14 14:52:27 +02:00
|
|
|
'Vrij Nederland': 'vn.nl',
|
2019-12-08 18:30:05 +01:00
|
|
|
'Wired': 'wired.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
};
|
|
|
|
|
2018-01-31 06:08:11 +01:00
|
|
|
const restrictions = {
|
2019-12-16 20:24:04 +01:00
|
|
|
'barrons.com': /.+barrons\.com\/articles\/.+/,
|
|
|
|
'prime.economictimes.indiatimes.com': /.+prime\.economictimes\.indiatimes\.com\/news\/[0-9]{8}\/.+/,
|
|
|
|
'wsj.com': /.+wsj\.com\/articles\/.+/
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't remove cookies before page load
|
2018-01-31 06:08:11 +01:00
|
|
|
const allow_cookies = [
|
2019-10-23 13:06:43 +02:00
|
|
|
'ad.nl',
|
2017-07-08 19:40:29 +02:00
|
|
|
'asia.nikkei.com',
|
2019-09-30 02:27:24 +02:00
|
|
|
'bostonglobe.com',
|
2019-10-29 14:05:40 +01:00
|
|
|
'cen.acs.org',
|
|
|
|
'chicagobusiness.com',
|
2019-11-17 17:06:30 +01:00
|
|
|
'demorgen.be',
|
2018-07-05 03:46:28 +02:00
|
|
|
'denverpost.com',
|
2019-10-23 13:06:43 +02:00
|
|
|
'economist.com',
|
|
|
|
'ed.nl',
|
2018-10-07 07:18:34 +02:00
|
|
|
'examiner.com.au',
|
2019-10-23 13:06:43 +02:00
|
|
|
'ft.com',
|
|
|
|
'hacked.com',
|
2019-12-07 19:28:19 +01:00
|
|
|
'harpers.org',
|
2019-02-11 00:43:12 +01:00
|
|
|
'hbr.org',
|
2019-10-23 13:06:43 +02:00
|
|
|
'lemonde.fr',
|
|
|
|
'letemps.ch',
|
|
|
|
'medium.com',
|
|
|
|
'mercurynews.com',
|
|
|
|
'newstatesman.com',
|
2019-02-19 02:25:35 +01:00
|
|
|
'nymag.com',
|
2019-10-23 13:06:43 +02:00
|
|
|
'nytimes.com',
|
|
|
|
'ocregister.com',
|
2019-10-14 14:52:27 +02:00
|
|
|
'parool.nl',
|
2019-10-23 13:52:04 +02:00
|
|
|
'qz.com',
|
2019-11-01 18:25:06 +01:00
|
|
|
'scientificamerican.com',
|
2019-10-23 13:06:43 +02:00
|
|
|
'spectator.co.uk',
|
2019-10-14 14:52:27 +02:00
|
|
|
'telegraaf.nl',
|
2019-10-23 13:06:43 +02:00
|
|
|
'theadvocate.com.au',
|
2019-10-29 14:05:40 +01:00
|
|
|
'theage.com.au',
|
2019-11-13 12:35:23 +01:00
|
|
|
'theatlantic.com',
|
2019-10-23 13:06:43 +02:00
|
|
|
'theaustralian.com.au',
|
2019-10-29 14:05:40 +01:00
|
|
|
'thediplomat.com',
|
2019-10-29 00:25:53 +01:00
|
|
|
'themercury.com.au',
|
2019-10-23 13:06:43 +02:00
|
|
|
'thestar.com',
|
|
|
|
'towardsdatascience.com',
|
2019-10-14 14:52:27 +02:00
|
|
|
'trouw.nl',
|
|
|
|
'vn.nl',
|
2019-10-23 13:06:43 +02:00
|
|
|
'volkskrant.nl',
|
|
|
|
'washingtonpost.com',
|
|
|
|
'wsj.com',
|
2017-07-08 19:40:29 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
// Removes cookies after page load
|
2018-01-31 06:08:11 +01:00
|
|
|
const remove_cookies = [
|
2019-10-23 13:06:43 +02:00
|
|
|
'ad.nl',
|
2017-07-08 19:40:29 +02:00
|
|
|
'asia.nikkei.com',
|
2019-12-08 18:30:05 +01:00
|
|
|
'bloombergquint.com',
|
2019-09-30 02:27:24 +02:00
|
|
|
'bostonglobe.com',
|
2019-10-29 14:05:40 +01:00
|
|
|
'cen.acs.org',
|
|
|
|
'chicagobusiness.com',
|
2019-11-17 17:06:30 +01:00
|
|
|
'demorgen.be',
|
2018-07-05 03:46:28 +02:00
|
|
|
'denverpost.com',
|
2019-10-23 13:06:43 +02:00
|
|
|
'economist.com',
|
|
|
|
'ed.nl',
|
|
|
|
'examiner.com.au',
|
|
|
|
'ft.com',
|
2018-07-16 06:43:40 +02:00
|
|
|
'hacked.com',
|
2019-12-07 19:28:19 +01:00
|
|
|
'harpers.org',
|
2019-10-23 13:06:43 +02:00
|
|
|
'hbr.org',
|
|
|
|
'letemps.ch',
|
|
|
|
'medium.com',
|
|
|
|
'mercurynews.com',
|
2018-07-23 04:04:27 +02:00
|
|
|
'newstatesman.com',
|
2019-10-23 13:06:43 +02:00
|
|
|
'nymag.com',
|
|
|
|
'nytimes.com',
|
|
|
|
'ocregister.com',
|
2019-10-23 13:52:04 +02:00
|
|
|
'qz.com',
|
2019-11-01 18:25:06 +01:00
|
|
|
'scientificamerican.com',
|
2018-07-23 04:22:07 +02:00
|
|
|
'spectator.co.uk',
|
2019-10-23 13:06:43 +02:00
|
|
|
'telegraaf.nl',
|
2018-09-28 16:39:45 +02:00
|
|
|
'theadvocate.com.au',
|
2019-10-29 14:05:40 +01:00
|
|
|
'theage.com.au',
|
2019-11-13 12:35:23 +01:00
|
|
|
'theatlantic.com',
|
2019-10-29 14:05:40 +01:00
|
|
|
'thediplomat.com',
|
2018-10-29 05:17:36 +01:00
|
|
|
'thestar.com',
|
2019-10-23 13:06:43 +02:00
|
|
|
'towardsdatascience.com',
|
|
|
|
'vn.nl',
|
2019-12-08 18:30:05 +01:00
|
|
|
'washingtonpost.com'
|
2017-07-08 19:40:29 +02:00
|
|
|
]
|
|
|
|
|
2019-10-25 15:00:08 +02:00
|
|
|
// select specific cookie(s) to hold from remove_cookies domains
|
|
|
|
const remove_cookies_select_hold = {
|
2019-12-13 14:24:28 +01:00
|
|
|
'washingtonpost.com': ['wp_gdpr'],
|
|
|
|
'qz.com': ['gdpr']
|
2019-10-25 15:00:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// select only specific cookie(s) to drop from remove_cookies domains
|
|
|
|
const remove_cookies_select_drop = {
|
2019-11-17 20:26:29 +01:00
|
|
|
'ad.nl': ['temptationTrackingId'],
|
2019-12-07 18:33:38 +01:00
|
|
|
'bostonglobe.com': ['FMPaywall'],
|
2019-11-17 20:26:29 +01:00
|
|
|
'demorgen.be': ['TID_ID'],
|
2019-12-06 16:15:49 +01:00
|
|
|
'economist.com': ['rvuuid'],
|
2019-11-17 20:26:29 +01:00
|
|
|
'ed.nl': ['temptationTrackingId'],
|
|
|
|
'nrc.nl': ['counter']
|
2019-10-25 15:00:08 +02:00
|
|
|
}
|
|
|
|
|
2019-05-12 22:44:03 +02:00
|
|
|
// Override User-Agent with Googlebot
|
|
|
|
const use_google_bot = [
|
2019-10-22 14:37:02 +02:00
|
|
|
'barrons.com',
|
2019-11-02 12:07:01 +01:00
|
|
|
'lemonde.fr',
|
2019-10-22 14:37:02 +02:00
|
|
|
'nytimes.com',
|
2019-10-29 19:27:54 +01:00
|
|
|
'quora.com',
|
2019-05-12 22:44:03 +02:00
|
|
|
'telegraph.co.uk',
|
2019-10-22 14:37:02 +02:00
|
|
|
'theaustralian.com.au',
|
2019-10-29 00:25:53 +01:00
|
|
|
'themercury.com.au',
|
2019-05-12 22:44:03 +02:00
|
|
|
'thetimes.co.uk',
|
2019-12-07 22:26:58 +01:00
|
|
|
'wsj.com',
|
2019-11-21 22:22:09 +01:00
|
|
|
'haaretz.co.il',
|
2019-11-23 19:50:46 +01:00
|
|
|
'haaretz.com',
|
|
|
|
'themarker.com',
|
2019-12-07 22:26:58 +01:00
|
|
|
'nknews.org',
|
2019-12-08 06:35:33 +01:00
|
|
|
'prime.economictimes.indiatimes.com'
|
2019-05-12 22:44:03 +02:00
|
|
|
]
|
|
|
|
|
2017-07-08 19:40:29 +02:00
|
|
|
function setDefaultOptions() {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
sites: defaultSites
|
|
|
|
}, function() {
|
|
|
|
browser.runtime.openOptionsPage();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-27 19:23:00 +01:00
|
|
|
// to block external script also add domain to manifest.json (permissions)
|
|
|
|
const blockedRegexes = {
|
|
|
|
'chicagotribune.com': /.+:\/\/.+\.tribdss\.com\//,
|
|
|
|
'thenation.com': /thenation\.com\/.+\/paywall-script\.php/,
|
|
|
|
'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/,
|
|
|
|
'nzherald.co.nz': /nzherald\.co\.nz\/.+\/headjs\/.+\.js/,
|
2019-12-03 11:53:30 +01:00
|
|
|
'economist.com': /.+\.tinypass\.com\/.+/,
|
2019-12-07 18:33:38 +01:00
|
|
|
'lrb.co.uk': /.+\.tinypass\.com\/.+/,
|
2019-12-08 18:46:06 +01:00
|
|
|
'bostonglobe.com': /meter\.bostonglobe\.com\/js\/.+/,
|
2019-12-08 19:34:26 +01:00
|
|
|
'foreignpolicy.com': /.+\.tinypass\.com\/.+/,
|
2019-12-13 14:14:55 +01:00
|
|
|
'inquirer.com': /.+\.tinypass\.com\/.+/,
|
|
|
|
'spectator.co.uk': /.+\.tinypass\.com\/.+/
|
2019-11-27 19:23:00 +01:00
|
|
|
};
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2019-04-07 01:34:30 +02:00
|
|
|
const userAgentDesktop = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
|
|
|
|
const userAgentMobile = "Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)"
|
|
|
|
|
2017-07-08 19:40:29 +02:00
|
|
|
var enabledSites = [];
|
|
|
|
|
|
|
|
// Get the enabled sites
|
|
|
|
browser.storage.sync.get({
|
|
|
|
sites: {}
|
|
|
|
}, function(items) {
|
|
|
|
var sites = items.sites;
|
|
|
|
enabledSites = Object.keys(items.sites).map(function(key) {
|
|
|
|
return items.sites[key];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Listen for changes to options
|
|
|
|
browser.storage.onChanged.addListener(function(changes, namespace) {
|
|
|
|
var key;
|
|
|
|
for (key in changes) {
|
|
|
|
var storageChange = changes[key];
|
|
|
|
if (key === 'sites') {
|
|
|
|
var sites = storageChange.newValue;
|
|
|
|
enabledSites = Object.keys(sites).map(function(key) {
|
|
|
|
return sites[key];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Set and show default options on install
|
2019-05-12 22:44:03 +02:00
|
|
|
browser.runtime.onInstalled.addListener(function(details) {
|
2017-07-08 19:40:29 +02:00
|
|
|
if (details.reason == "install") {
|
|
|
|
setDefaultOptions();
|
|
|
|
} else if (details.reason == "update") {
|
|
|
|
// User updated extension
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-13 01:31:18 +02:00
|
|
|
// Disable javascript for these sites
|
|
|
|
chrome.webRequest.onBeforeRequest.addListener(function(details) {
|
|
|
|
if (!isSiteEnabled(details) || details.url.indexOf("mod=rsswn") !== -1) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-21 15:50:50 +02:00
|
|
|
return {cancel: true};
|
2019-05-13 01:31:18 +02:00
|
|
|
},
|
|
|
|
{
|
2019-12-07 18:33:38 +01:00
|
|
|
urls: ["*://*.theglobeandmail.com/*", "*://*.thestar.com/*", "*://*.newstatesman.com/*", "*://*.afr.com/*"],
|
2019-05-13 01:31:18 +02:00
|
|
|
types: ["script"]
|
|
|
|
},
|
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2019-02-11 00:43:12 +01:00
|
|
|
browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
2019-11-27 19:23:00 +01:00
|
|
|
var requestHeaders = details.requestHeaders;
|
|
|
|
|
|
|
|
var header_referer = '';
|
|
|
|
for (var n in requestHeaders) {
|
|
|
|
if (requestHeaders[n].name.toLowerCase() == 'referer') {
|
|
|
|
header_referer = requestHeaders[n].value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
|
|
|
|
for (var domain in blockedRegexes) {
|
2019-12-10 19:02:16 +01:00
|
|
|
if ((isSiteEnabled({url: '.'+ domain}) || isSiteEnabled({url: header_referer})) && details.url.match(blockedRegexes[domain])) {
|
2019-11-27 19:23:00 +01:00
|
|
|
if (details.url.indexOf(domain) !== -1 || header_referer.indexOf(domain) !== -1) {
|
2019-12-10 19:02:16 +01:00
|
|
|
// allow BG paywall-script to set cookies in homepage/sections (else no article-text)
|
|
|
|
if (details.url.indexOf('meter.bostonglobe.com/js/') !== -1 && (header_referer === 'https://www.bostonglobe.com/'
|
|
|
|
|| header_referer.indexOf('/?p1=BGHeader_') !== -1 || header_referer.indexOf('/?p1=BGMenu_') !== -1)) {
|
|
|
|
break;
|
|
|
|
}
|
2019-11-27 19:23:00 +01:00
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
|
|
|
|
2019-11-27 19:23:00 +01:00
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
2018-11-24 23:10:21 +01:00
|
|
|
}
|
|
|
|
|
2017-07-08 19:40:29 +02:00
|
|
|
var tabId = details.tabId;
|
2019-11-27 19:23:00 +01:00
|
|
|
|
2019-04-07 01:34:30 +02:00
|
|
|
var useUserAgentMobile = false;
|
2017-07-08 19:40:29 +02:00
|
|
|
var setReferer = false;
|
|
|
|
|
|
|
|
// if referer exists, set it to google
|
2019-05-12 22:44:03 +02:00
|
|
|
requestHeaders = requestHeaders.map(function(requestHeader) {
|
2017-07-08 19:40:29 +02:00
|
|
|
if (requestHeader.name === 'Referer') {
|
2019-02-13 10:33:45 +01:00
|
|
|
if (details.url.indexOf("cooking.nytimes.com/api/v1/users/bootstrap") !== -1) {
|
|
|
|
// this fixes images not being loaded on cooking.nytimes.com main page
|
|
|
|
// referrer has to be *nytimes.com otherwise returns 403
|
|
|
|
requestHeader.value = 'https://cooking.nytimes.com';
|
2019-02-21 04:37:08 +01:00
|
|
|
} else if (details.url.indexOf("wsj.com") !== -1 || details.url.indexOf("ft.com") !== -1) {
|
2019-02-13 10:33:45 +01:00
|
|
|
requestHeader.value = 'https://www.facebook.com/';
|
|
|
|
} else {
|
|
|
|
requestHeader.value = 'https://www.google.com/';
|
|
|
|
}
|
|
|
|
setReferer = true;
|
|
|
|
}
|
2019-04-07 01:34:30 +02:00
|
|
|
if (requestHeader.name === 'User-Agent') {
|
|
|
|
useUserAgentMobile = requestHeader.value.toLowerCase().includes("mobile");
|
|
|
|
}
|
|
|
|
|
2019-02-13 10:33:45 +01:00
|
|
|
return requestHeader;
|
|
|
|
});
|
2017-07-08 19:40:29 +02:00
|
|
|
|
|
|
|
// otherwise add it
|
|
|
|
if (!setReferer) {
|
|
|
|
if (details.url.indexOf("wsj.com") !== -1) {
|
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
|
|
|
value: 'https://www.facebook.com/'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
|
|
|
value: 'https://www.google.com/'
|
|
|
|
});
|
|
|
|
}
|
2019-04-07 01:34:30 +02:00
|
|
|
}
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2019-05-12 22:44:03 +02:00
|
|
|
// override User-Agent to use Googlebot
|
|
|
|
var useGoogleBot = use_google_bot.filter(function(item) {
|
2019-09-21 15:50:50 +02:00
|
|
|
return typeof item == 'string' && details.url.indexOf(item) > -1;
|
2019-05-12 22:44:03 +02:00
|
|
|
}).length > 0;
|
|
|
|
|
|
|
|
if (useGoogleBot) {
|
2019-04-07 01:34:30 +02:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "User-Agent",
|
|
|
|
"value": useUserAgentMobile ? userAgentMobile : userAgentDesktop
|
|
|
|
})
|
2019-05-12 22:44:03 +02:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "X-Forwarded-For",
|
|
|
|
"value": "66.249.66.1"
|
|
|
|
})
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove cookies before page load
|
|
|
|
requestHeaders = requestHeaders.map(function(requestHeader) {
|
|
|
|
for (var siteIndex in allow_cookies) {
|
|
|
|
if (details.url.indexOf(allow_cookies[siteIndex]) !== -1) {
|
|
|
|
return requestHeader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (requestHeader.name === 'Cookie') {
|
|
|
|
requestHeader.value = '';
|
|
|
|
}
|
|
|
|
return requestHeader;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (tabId !== -1) {
|
|
|
|
// run contentScript inside tab
|
|
|
|
browser.tabs.executeScript(tabId, {
|
|
|
|
file: 'contentScript.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function(res) {
|
|
|
|
if (browser.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return { requestHeaders: requestHeaders };
|
|
|
|
}, {
|
|
|
|
urls: ['<all_urls>']
|
|
|
|
}, ['blocking', 'requestHeaders']);
|
|
|
|
|
|
|
|
// remove cookies after page load
|
|
|
|
browser.webRequest.onCompleted.addListener(function(details) {
|
|
|
|
for (var domainIndex in remove_cookies) {
|
|
|
|
var domainVar = remove_cookies[domainIndex];
|
|
|
|
if (!enabledSites.includes(domainVar) || details.url.indexOf(domainVar) === -1) {
|
|
|
|
continue; // don't remove cookies
|
|
|
|
}
|
|
|
|
browser.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
for (var i=0; i<cookies.length; i++) {
|
2018-10-19 06:28:29 +02:00
|
|
|
var cookie = {
|
|
|
|
url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path,
|
|
|
|
name: cookies[i].name,
|
|
|
|
storeId: cookies[i].storeId
|
|
|
|
};
|
|
|
|
if (cookies[i].firstPartyDomain !== undefined) {
|
|
|
|
cookie.firstPartyDomain = cookies[i].firstPartyDomain;
|
|
|
|
}
|
2019-10-25 15:00:08 +02:00
|
|
|
|
|
|
|
var cookie_domain = cookies[i].domain;
|
2019-11-17 20:26:29 +01:00
|
|
|
var rc_domain = cookie_domain.replace(/^(\.?www\.|\.)/, '');
|
2019-10-25 15:00:08 +02:00
|
|
|
// hold specific cookie(s) from remove_cookies domains
|
2019-11-17 20:26:29 +01:00
|
|
|
if ((rc_domain in remove_cookies_select_hold) && remove_cookies_select_hold[rc_domain].includes(cookies[i].name)){
|
2019-10-25 15:00:08 +02:00
|
|
|
continue; // don't remove specific cookie
|
|
|
|
}
|
|
|
|
// drop only specific cookie(s) from remove_cookies domains
|
2019-11-17 20:26:29 +01:00
|
|
|
if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookies[i].name))){
|
2019-10-25 15:00:08 +02:00
|
|
|
continue; // only remove specific cookie
|
|
|
|
}
|
2018-10-19 06:28:29 +02:00
|
|
|
browser.cookies.remove(cookie);
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
urls: ["<all_urls>"]
|
2018-08-29 01:15:23 +02:00
|
|
|
});
|
2019-02-11 00:43:12 +01:00
|
|
|
|
|
|
|
function isSiteEnabled(details) {
|
|
|
|
var isEnabled = enabledSites.some(function(enabledSite) {
|
2019-12-13 13:57:04 +01:00
|
|
|
var useSite = (details.url.indexOf("." + enabledSite) !== -1 || details.url.indexOf("/" + enabledSite) !== -1);
|
2019-02-11 00:43:12 +01:00
|
|
|
if (enabledSite in restrictions) {
|
2019-12-16 20:24:04 +01:00
|
|
|
return useSite && details.url.match(restrictions[enabledSite]);
|
2019-02-11 00:43:12 +01:00
|
|
|
}
|
|
|
|
return useSite;
|
|
|
|
});
|
|
|
|
return isEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getParameterByName(name, url) {
|
|
|
|
if (!url) url = window.location.href;
|
|
|
|
name = name.replace(/[\[\]]/g, '\\$&');
|
|
|
|
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
|
|
|
|
results = regex.exec(url);
|
|
|
|
if (!results) return null;
|
|
|
|
if (!results[2]) return '';
|
|
|
|
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
|
|
|
}
|