bypass-paywalls-firefox-clean/background.js

1274 lines
51 KiB
JavaScript
Raw Normal View History

/* Please respect alphabetical order when adding a site in any list */
2017-07-08 19:40:29 +02:00
'use strict';
var ext_api = (typeof browser === 'object') ? browser : chrome;
2020-10-20 17:00:14 +02:00
var ext_name = ext_api.runtime.getManifest().name;
2017-07-08 19:40:29 +02:00
2021-01-30 19:18:00 +01:00
const cs_limit_except = ['afr.com', 'discovermagazine.com', 'elcomercio.pe', 'elmercurio.com', 'elpais.com', 'faz.net', 'gestion.pe', 'harpers.org', 'inkl.com', 'jpost.com', 'la-croix.com', 'lescienze.it', 'lne.es', 'marketwatch.com', 'newleftreview.org', 'prospectmagazine.co.uk', 'techinasia.com', 'thepointmag.com'];
var currentTabUrl = '';
var csDone = false;
// Cookies from this list are blocked by default (obsolete)
// defaultSites are loaded from sites.js at installation extension
// var defaultSites = {};
2017-07-08 19:40:29 +02:00
2018-01-31 06:08:11 +01:00
const restrictions = {
2021-01-28 17:34:00 +01:00
'adweek.com': /^((?!\.adweek\.com\/(.+\/)?(amp|agencyspy|tvnewser|tvspy)\/).)*$/,
2020-12-15 17:03:17 +01:00
'barrons.com': /.+\.barrons\.com\/(amp\/)?article(s)?\/.+/,
2020-09-24 20:50:29 +02:00
'bloombergquint.com': /^((?!\.bloombergquint\.com\/bq-blue-exclusive\/).)*$/,
2020-11-11 17:19:13 +01:00
'elcomercio.pe': /.+\/elcomercio\.pe\/.+((\w)+(\-)+){3,}.+/,
2021-01-19 18:46:06 +01:00
'elpais.com': /(\/elpais\.com\/$|\/(.+\.)?elpais\.com\/.+\.html)/,
2021-01-11 18:49:09 +01:00
'faz.net': /^((?!\/.+\.faz\.net\/aktuell\/(\?switchfaznet)?$).)*$/,
2020-12-16 18:38:05 +01:00
'foreignaffairs.com': /.+\.foreignaffairs\.com\/(articles|fa-caching|interviews|reviews|sites)\/.+/,
'ft.com': /.+\.ft.com\/content\//,
2020-11-11 17:19:13 +01:00
'gestion.pe': /.+\/gestion\.pe\/.+((\w)+(\-)+){3,}.+/,
2020-10-20 19:40:42 +02:00
'globo.com': /^((?!\/valor\.globo\.com\/).)*$/,
'quora.com': /^((?!quora\.com\/search\?q=).)*$/,
2021-01-10 20:21:18 +01:00
'seekingalpha.com': /.+\/seekingalpha\.com\/($|(amp\/)?(article|news)\/|samw\/)/,
2020-12-15 17:03:17 +01:00
'techinasia.com': /.+\.techinasia\.com\/.+((\w)+(\-)+){3,}.+/,
'wsj.com': /^((?!\/cn\.wsj\.com\/).)*$/
2017-07-08 19:40:29 +02:00
}
// Don't remove cookies before page load
// allow_cookies are completed with domains in sites.js (default allow/remove_cookies)
2020-11-10 18:15:18 +01:00
var allow_cookies_default = [
'abc.es',
'belfasttelegraph.co.uk',
2020-12-12 13:15:50 +01:00
'berlingske.dk',
'bostonglobe.com',
'business-standard.com',
2020-12-04 16:25:11 +01:00
'charliehebdo.fr',
2021-01-11 21:00:41 +01:00
'cicero.de',
'clarin.com',
2021-01-20 20:26:35 +01:00
'cmjornal.pt',
'chronicle.com',
'df.cl',
'dn.se',
'dvhn.nl',
'editorialedomani.it',
2021-01-24 11:06:57 +01:00
'elconfidencial.com',
'elmercurio.com',
'elmundo.es',
'elpais.com',
2020-11-23 18:12:40 +01:00
'elperiodico.com',
'esprit.presse.fr',
2020-12-12 13:28:25 +01:00
'euobserver.com',
'eurekareport.com.au',
2020-12-24 14:14:29 +01:00
'expansion.com',
'faz.net',
2020-11-15 14:37:30 +01:00
'financialpost.com',
'folha.uol.com.br',
'ftm.nl',
'fortune.com',
2020-12-24 13:30:55 +01:00
'freiepresse.de',
2020-10-25 09:47:53 +01:00
'gelocal.it',
'gestion.pe',
2020-11-07 10:44:13 +01:00
'gva.be',
'haaretz.co.il',
'haaretz.com',
'handelsblatt.com',
2021-01-25 20:39:20 +01:00
'hilltimes.com',
'hs.fi',
'ilfattoquotidiano.it',
'ilrestodelcarlino.it',
'independent.ie',
'intelligentinvestor.com.au',
2021-01-26 21:27:43 +01:00
'jpost.com',
'knack.be',
'kurier.at',
2020-11-26 20:18:11 +01:00
'la-croix.com',
2020-12-31 09:45:01 +01:00
'lavanguardia.com',
'lc.nl',
'lejdd.fr',
'lesechos.fr',
'limesonline.com',
'lne.es',
'lrb.co.uk',
2021-01-24 10:25:55 +01:00
'marketwatch.com',
'medium.com',
'modernhealthcare.com',
'nationalgeographic.com',
2020-11-15 14:37:30 +01:00
'nationalpost.com',
'nationalreview.com',
2021-01-09 17:45:21 +01:00
'newleftreview.org',
'newrepublic.com',
'noordhollandsdagblad.nl',
2020-12-20 21:28:12 +01:00
'nouvelobs.com',
'nybooks.com',
'nytimes.com',
'nzz.ch',
2021-01-19 18:46:06 +01:00
'observador.pt',
2020-12-21 19:33:09 +01:00
'parismatch.com',
2020-12-19 16:27:30 +01:00
'piqd.de',
2021-01-22 13:58:54 +01:00
'prospectmagazine.co.uk',
'quotidiano.net',
'quora.com',
'repubblica.it',
'rollingstone.com',
2021-01-18 20:12:02 +01:00
'ruhrnachrichten.de',
2020-11-15 14:49:53 +01:00
'saechsische.de',
'scribd.com',
'seekingalpha.com',
'slader.com',
'startribune.com',
'stocknews.com',
2021-01-31 10:54:06 +01:00
'stratfor.com',
2021-01-16 10:58:06 +01:00
'sudouest.fr',
'sueddeutsche.de',
2021-01-14 19:26:20 +01:00
'svz.de',
'techinasia.com',
'the-american-interest.com',
'thehindu.com',
2020-11-25 17:29:48 +01:00
'thehindubusinessline.com',
'themarker.com',
'thewest.com.au',
'timeshighereducation.com',
'towardsdatascience.com',
2021-01-13 21:54:29 +01:00
'usinenouvelle.com',
'variety.com',
'washingtonpost.com',
2020-10-27 17:03:03 +01:00
'wiwo.de',
'worldpoliticsreview.com',
'zeit.de',
2020-11-10 18:15:18 +01:00
];
var allow_cookies = allow_cookies_default.slice();
2017-07-08 19:40:29 +02:00
// Removes cookies after page load
// remove_cookies are completed with domains of sites.js (default allow/remove_cookies)
var remove_cookies = [
2017-07-08 19:40:29 +02:00
]
// select specific cookie(s) to hold from remove_cookies domains
const remove_cookies_select_hold = {
'barrons.com': ['wsjregion'],
2020-11-27 19:34:15 +01:00
'groene.nl': ['accept-cookies', 'popunder-hidden'],
'newstatesman.com': ['STYXKEY_nsversion'],
'qz.com': ['gdpr'],
2021-01-06 19:50:12 +01:00
'seattletimes.com': ['st_newsletter_splash_seen'],
2020-11-11 17:19:13 +01:00
'wsj.com': ['wsjregion', 'ResponsiveConditional_initialBreakpoint']
}
// select only specific cookie(s) to drop from remove_cookies domains
2020-04-13 19:11:29 +02:00
var remove_cookies_select_drop = {
2021-01-22 14:44:36 +01:00
'ambito.com': ['TDNotesRead'],
'caixinglobal.com': ['CAIXINGLB_LOGIN_UUID'],
'dn.se': ['randomSplusId'],
'fd.nl': ['socialread'],
2021-01-30 12:55:39 +01:00
'griffithreview.com': ['issuem_lp'],
'nrc.nl': ['counter'],
2021-01-22 14:33:25 +01:00
'theatlantic.com': ['articleViews'],
'thepointmag.com': ['monthly_history']
}
// Override User-Agent with Googlebot
var use_google_bot_default = [
'abc.es',
'barrons.com',
2020-12-12 13:15:50 +01:00
'berlingske.dk',
2020-10-26 22:21:32 +01:00
'deutsche-wirtschafts-nachrichten.de',
'df.cl',
'dn.se',
'editorialedomani.it',
2020-12-12 13:28:25 +01:00
'euobserver.com',
'eurekareport.com.au',
'ft.com',
'handelsblatt.com',
2021-01-25 20:39:20 +01:00
'hilltimes.com',
'hs.fi',
'intelligentinvestor.com.au',
'mexiconewsdaily.com',
'miamiherald.com',
2021-01-16 10:58:06 +01:00
'newleftreview.org',
2020-12-20 21:28:12 +01:00
'nouvelobs.com',
'nzz.ch',
2020-12-19 16:27:30 +01:00
'piqd.de',
'quora.com',
'republic.ru',
2021-01-18 20:12:02 +01:00
'ruhrnachrichten.de',
'seekingalpha.com',
2021-01-31 10:54:06 +01:00
'stratfor.com',
'thetimes.co.uk',
2021-01-13 21:54:29 +01:00
'usinenouvelle.com',
'washingtonpost.com',
2020-10-27 17:03:03 +01:00
'wiwo.de',
'worldpoliticsreview.com',
2020-10-27 18:04:42 +01:00
'wsj.com',
'zeit.de',
];
2020-11-10 18:15:18 +01:00
var use_google_bot = use_google_bot_default.slice();
2020-03-10 19:12:25 +01:00
2020-11-02 18:52:40 +01:00
// Override User-Agent with Bingbot
var use_bing_bot = [
'haaretz.co.il',
'haaretz.com',
'themarker.com',
];
var use_facebook_referer = ['clarin.com', 'fd.nl', 'sloanreview.mit.edu'];
var use_twitter_referer = ['medium.com', 'towardsdatascience.com'];
var use_random_ip = ['esprit.presse.fr', 'slader.com'];
var change_headers = use_google_bot.concat(use_bing_bot, use_facebook_referer, use_twitter_referer, use_random_ip);
// block paywall-scripts individually
var blockedRegexes = {
'adweek.com': /.+\.lightboxcdn\.com\/.+/,
'afr.com': /afr\.com\/assets\/vendorsReactRedux_client.+\.js/,
2020-11-15 14:15:12 +01:00
'alternatives-economiques.fr': /.+\.poool\.fr\/.+/,
'americanbanker.com': /\.tinypass\.com\/.+/,
'barrons.com': /(cdn\.cxense\.com\/.+|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js)/,
'belfasttelegraph.co.uk': /(cdn\.flip-pay\.com\/clients\/inm\/flip-pay\.js|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js)/,
2020-11-08 09:55:15 +01:00
'bizjournals.com': /(assets\.bizjournals\.com\/static\/js\/app\/cxense\.js|cdn\.cxense\.com\/.+)/,
'bloomberg.com': /(\.tinypass\.com\/|assets\.bwbx\.io\/s3\/fence\/)/,
'bostonglobe.com': /meter\.bostonglobe\.com\/js\/.+/,
'businessinsider.com': /\.tinypass\.com\/.+/,
'challenges.fr': /.+\.poool\.fr\/.+/,
'charliehebdo.fr': /.+\.poool\.fr\/.+/,
'chicagobusiness.com': /\.tinypass\.com\/.+/,
'chicagotribune.com': /.+:\/\/.+\.tribdss\.com\/.+/,
'chronicle.com': /(.+\.blueconic\.net\/.+|assets\.login\.chronicle\.com\/common\/che-auth0-user\.js)/,
'clarin.com': /js\.matheranalytics\.com\/.+/,
2021-01-20 20:26:35 +01:00
'cmjornal.pt': /cdn\.ampproject\.org\/v\d\/amp-(access|(sticky-)?ad)-.+\.js/,
'corriere.it': /(\.tinypass\.com\/|\.rcsobjects\.it\/rcs_(cpmt|tracking-service)\/|\.corriereobjects\.it\/.+\/js\/(_paywall\.sjs|tracking\/)|\.userzoom\.com\/files\/js\/)/,
'digiday.com': /\.tinypass\.com\/.+/,
2020-11-15 14:37:30 +01:00
'dvhn.nl': /.+\.evolok\.net\/.+\/authorize\/.+/,
'economist.com': /\.tinypass\.com\/.+/,
'editorialedomani.it': /(.+\.editorialedomani\.it\/pelcro\.js|js\.pelcro\.com\/.+)/,
'elcomercio.pe': /elcomercio\.pe\/pf\/dist\/template\/elcomercio-noticia.+\.js/,
2021-01-24 11:06:57 +01:00
'elconfidencial.com': /\.tinypass\.com\/.+/,
2020-12-22 07:45:05 +01:00
'elmercurio.com': /\.(elmercurio\.com|emol\.cl)\/(.+\/)?js\/(.+\/)?(modal|merPramV\d|PramModal\.min)\.js/,
2021-01-02 12:48:07 +01:00
'elmundo.es': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
2021-01-18 18:43:04 +01:00
'elpais.com': /(\.epimg\.net\/js\/.+\/noticia\.min\.js|\.cdn\.arcpublishing\.com\/arc\/subs\/p\.min\.js|cdn\.ampproject\.org\/v\d\/amp-(access|(sticky-)?ad|consent)-.+\.js)/,
2021-01-02 12:48:07 +01:00
'elperiodico.com': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
2020-11-15 14:37:30 +01:00
'estadao.com.br': /acesso\.estadao\.com\.br\/paywall\/.+\/pw\.js/,
2020-11-12 19:26:54 +01:00
'estrellavalpo.cl': /(.+\.mercuriovalpo\.cl\/impresa\/.+\/assets\/(vendor|\d)\.js|pram\.pasedigital\.cl\/API\/User\/Status\?)/,
'exame.abril.com.br': /\.tinypass\.com\/.+/,
2021-01-02 12:48:07 +01:00
'expansion.com': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
'financialpost.com': /\.tinypass\.com\/.+/,
2020-11-12 19:26:54 +01:00
'folha.uol.com.br': /(.+\.folha\.uol\.com\.br\/paywall\/js\/.+\/publicidade\.ads\.js|paywall\.folha\.uol\.com\.br\/.+|js\.matheranalytics\.com\/.+)/,
2020-12-16 18:38:05 +01:00
'foreignaffairs.com': /.+\.foreignaffairs\.com\/sites\/default\/files\/js\/js_[^y].+\.js/,
'foreignpolicy.com': /\.tinypass\.com\/.+/,
'fortune.com': /\.tinypass\.com\/.+/,
2021-01-02 12:48:07 +01:00
'freiepresse.de': /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js/,
'fresnobee.com': /cdn\.ampproject\.org\/v\d\/amp-subscriptions-.+\.js/,
2020-11-15 14:37:30 +01:00
'ftm.nl': /.+\.ftm\.nl\/js\/routing\?/,
2021-01-02 12:48:07 +01:00
'gelocal.it': /cdn\.ampproject\.org\/v\d\/amp-(access|ad)-.+\.js/,
'gestion.pe': /gestion\.pe\/pf\/dist\/template\/gestion-noticia.+\.js/,
'globes.co.il': /\.tinypass\.com\/.+/,
'globo.com': /\.tinypass\.com\/.+/,
2021-01-30 12:55:39 +01:00
'griffithreview.com': /\.griffithreview\.com\/.+\/leaky-paywall\//,
'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/,
'haaretz.com': /haaretz\.com\/hdc\/web\/js\/minified\/header-scripts-int.js.+/,
'hbr.org': /\.tinypass\.com\/.+/,
'historyextra.com': /.+\.evolok\.net\/.+\/authorize\/.+/,
'ilrestodelcarlino.it': /\.tinypass\.com\/.+/,
'ilsecoloxix.it': /\.repstatic\.it\/minify\/sites\/gelocal\/.+\/config\.cache\.php\?name=ilsecoloxix_pw_js/,
'independent.ie': /(cdn\.flip-pay\.com\/clients\/inm\/flip-pay\.js|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js)/,
'inquirer.com': /\.tinypass\.com\/.+/,
2021-01-02 12:48:07 +01:00
'irishtimes.com': /cdn\.ampproject\.org\/v\d\/amp-(access|ad)-.+\.js/,
2021-02-01 17:21:49 +01:00
'japantimes.co.jp': /\.piano\.io\//,
2021-01-26 21:27:43 +01:00
'jpost.com': /\.jpost\.com\/bundles\/js_article\?/,
'knack.be': /.+\.knack\.be\/js\/responsive\/rmgModal\.js/,
'kurier.at': /\.tinypass\.com\/.+/,
2021-01-02 12:48:07 +01:00
'la-croix.com': /cdn\.ampproject\.org\/v\d\/amp-(access|ad)-.+\.js/,
2020-12-22 07:45:05 +01:00
'lasegunda.com': /\.(lasegunda\.com|emol\.cl)\/(.+\/)?js\/(.+\/)?(modal|merPramV\d|PramModal\.min)\.js/,
'lanuovasardegna.it': /\.repstatic\.it\/minify\/sites\/lanuovasardegna\/.+\/config\.cache\.php\?name=social_js/,
'lastampa.it': /.+\.repstatic\.it\/minify\/sites\/lastampa\/.+\/config\.cache\.php\?name=social_js/,
2020-11-19 08:01:11 +01:00
'latercera.com': /(.+\.latercera\.com\/arc\/subs\/p\.js|cdn\.cxense\.com\/.+)/,
2020-10-25 20:48:40 +01:00
'latimes.com': /js\.matheranalytics\.com\/.+/,
2020-12-31 09:45:01 +01:00
'lavanguardia.com': /(\.evolok\.net\/.+\/authorize\/|\.lavanguardia\.com\/(js\/)?godo-)/,
'lc.nl': /.+\.evolok\.net\/.+\/authorize\/.+/,
2021-02-01 17:21:49 +01:00
'le1hebdo.fr': /(\.qiota\.com\/|\/le1hebdo\.fr\/assets\/front\/js\/qiota\.script\.js)/,
'lejdd.fr': /.+\.poool\.fr\/.+/,
'leparisien.fr': /\.tinypass\.com\/.+/,
'lesechos.fr': /\.tinypass\.com\/.+/,
'limesonline.com': /scripts\.repubblica\.it\/pw\/pw\.js.+/,
'livemint.com': /(.+\.livemint\.com\/js\/localWorker\.js|analytics\.htmedia\.in\/analytics-js\/.+\.js)/,
'lne.es': /cdn\.ampproject\.org\/v\d\/amp-(access|consent)-.+\.js/,
'lopinion.fr': /.+\.poool\.fr\/.+/,
'lrb.co.uk': /\.tinypass\.com\/.+/,
2021-01-24 10:25:55 +01:00
'marketwatch.com': /(cdn\.cxense\.com\/|cdn\.ampproject\.org\/v\d\/amp-(access|ad)-.+\.js)/,
2020-11-12 19:26:54 +01:00
'mercuriovalpo.cl': /(.+\.mercuriovalpo\.cl\/impresa\/.+\/assets\/(vendor|\d)\.js|pram\.pasedigital\.cl\/API\/User\/Status\?)/,
'modernhealthcare.com': /\.tinypass\.com\/.+/,
'nationalgeographic.com': /.+\.blueconic\.net\/.+/,
'nationalpost.com': /\.tinypass\.com\/.+/,
'nationalreview.com': /(.+\.blueconic\.net\/.+|cdn\.ampproject\.org\/v\d\/amp-(access|ad)-.+\.js)/,
'newrepublic.com': /.+\.onecount\.net\/js\/.+/,
'newsweek.com': /js\.pelcro\.com\/.+/,
'newyorker.com': /.+\.newyorker\.com\/verso\/static\/presenter-articles.+\.js/,
2020-11-25 17:29:48 +01:00
'nytimes.com': /(meter-svc\.nytimes\.com\/meter\.js|mwcm\.nyt\.com\/.+\.js)/,
2021-01-19 18:46:06 +01:00
'observador.pt': /\.tinypass\.com\/.+/,
2020-12-21 19:33:09 +01:00
'parismatch.com': /.+\.poool\.fr\/.+/,
'quotidiano.net': /\.tinypass\.com\/.+/,
'repubblica.it': /scripts\.repubblica\.it\/pw\/pw\.js.+/,
2020-11-08 09:55:15 +01:00
'rollingstone.com': /cdn\.cxense\.com\/.+/,
2021-01-18 20:12:02 +01:00
'ruhrnachrichten.de': /\.tinypass\.com\/.+/,
'sacbee.com': /cdn\.ampproject\.org\/v\d\/amp-subscriptions-.+\.js/,
'saechsische.de': /\.tinypass\.com\/.+/,
'science-et-vie.com': /.+\.qiota\.com\/.+/,
'sciencesetavenir.fr': /.+\.poool\.fr\/.+/,
'scmp.com': /\.tinypass\.com\/.+/,
'seekingalpha.com': /(\.tinypass\.com\/|cdn\.ampproject\.org(\/.+)?\/v\d\/amp-(access|ad|loader)-.+\.js)/,
'sfchronicle.com': /.+\.blueconic\.net\/.+/,
'slate.com': /(cdn\.cxense\.com\/.+|\.tinypass\.com\/.+)/,
'sloanreview.mit.edu': /(\.tinypass\.com\/.+|.+\/sloanreview\.mit\.edu\/.+\/welcome-ad\.js)/,
'spectator.co.uk': /\.tinypass\.com\/.+/,
'spectator.com.au': /\.tinypass\.com\/.+/,
'spectator.us': /(cdn\.cxense\.com\/.+|\.tinypass\.com\/.+)/,
2021-01-14 19:26:20 +01:00
'svz.de': /cdn\.ampproject\.org\/v\d\/amp-(access|(sticky-)?ad|consent|fx-flying-carpet)-.+\.js/,
'technologyreview.com': /.+\.blueconic\.net\/.+/,
'telegraph.co.uk': /(\.tinypass\.com\/|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js|\.telegraph\.co\.uk\/.+\/piano.+\.js|assets\.adobedtm\.com\/.+\.js)/,
'thedailybeast.com': /\.tinypass\.com\/.+/,
2021-01-25 20:39:20 +01:00
'hilltimes.com': /\.hilltimes\.com\/.+\/js\/loadingoverlay\/loadingoverlay\.min\.js/,
'thehindu.com': /(cdn\.cxense\.com\/.+|\.tinypass\.com\/.+)/,
'thehindubusinessline.com': /(cdn\.cxense\.com\/.+|\.tinypass\.com\/.+)/,
'thenation.com': /\.tinypass\.com\/.+/,
'timeshighereducation.com': /\.timeshighereducation\.com\/sites\/default\/files\/js\/js_bbCGL.+\.js/,
'valeursactuelles.com': /.+\.qiota\.com\/.+/,
2020-11-08 09:55:15 +01:00
'variety.com': /cdn\.cxense\.com\/.+/,
'washingtonpost.com': /.+\.washingtonpost\.com\/.+\/pwapi-proxy\.min\.js/,
2021-01-02 12:48:07 +01:00
'wsj.com': /(cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js|cdn\.cxense\.com\/.+)/
};
2017-07-08 19:40:29 +02:00
const au_comm_media_domains = ['bendigoadvertiser.com.au', 'bordermail.com.au', 'canberratimes.com.au', 'centralwesterndaily.com.au', 'dailyadvertiser.com.au', 'dailyliberal.com.au', 'examiner.com.au', 'illawarramercury.com.au', 'newcastleherald.com.au', 'northerndailyleader.com.au', 'portnews.com.au', 'standard.net.au', 'theadvocate.com.au', 'thecourier.com.au', 'westernadvocate.com.au'];
2020-07-07 19:35:28 +02:00
const au_news_corp_domains = ['adelaidenow.com.au', 'cairnspost.com.au', 'couriermail.com.au', 'dailytelegraph.com.au', 'geelongadvertiser.com.au', 'goldcoastbulletin.com.au', 'heraldsun.com.au', 'ntnews.com.au', 'theaustralian.com.au', 'themercury.com.au', 'townsvillebulletin.com.au', 'weeklytimesnow.com.au'];
const au_prov_news_domains = ['news-mail.com.au', 'frasercoastchronicle.com.au', 'gladstoneobserver.com.au', 'dailyexaminer.com.au', 'dailymercury.com.au', 'themorningbulletin.com.au', 'sunshinecoastdaily.com.au', 'gympietimes.com.au', 'northernstar.com.au', 'qt.com.au', 'thechronicle.com.au', 'warwickdailynews.com.au'];
2021-01-08 18:40:14 +01:00
const ca_torstar_domains = ['niagarafallsreview.ca', 'stcatharinesstandard.ca', 'thepeterboroughexaminer.com', 'therecord.com', 'thespec.com', 'thestar.com', 'wellandtribune.ca'];
2020-12-10 20:23:12 +01:00
const de_funke_media_domains = ['abendblatt.de', 'braunschweiger-zeitung.de', 'morgenpost.de', 'nrz.de', 'otz.de', 'thueringer-allgemeine.de', 'waz.de', 'wp.de', 'wr.de'];
2020-12-08 20:13:27 +01:00
const de_madsack_domains = ['haz.de', 'kn-online.de', 'ln-online.de', 'lvz.de', 'maz-online.de', 'neuepresse.de', 'ostsee-zeitung.de'];
const es_grupo_vocento_domains = ['diariosur.es', 'diariovasco.com', 'elcomercio.es', 'elcorreo.com', 'eldiariomontanes.es', 'elnortedecastilla.es', 'hoy.es', 'ideal.es', 'larioja.com', 'laverdad.es', 'lavozdigital.es'];
2020-11-27 19:34:15 +01:00
const fi_alma_talent_domains = ['arvopaperi.fi', 'kauppalehti.fi', 'marmai.fi', 'mediuutiset.fi', 'mikrobitti.fi', 'talouselama.fi', 'tekniikkatalous.fi', 'tivi.fi', 'uusisuomi.fi'];
2020-12-06 12:43:16 +01:00
const fr_be_groupe_rossel_domains = ['aisnenouvelle.fr', 'courrier-picard.fr', 'lardennais.fr', 'lavoixdunord.fr', 'lecho.be', 'lesoir.be', 'lest-eclair.fr', 'liberation-champagne.fr', 'lunion.fr', 'nordeclair.fr', 'paris-normandie.fr', 'sudinfo.be'];
2020-12-06 22:32:59 +01:00
const fr_groupe_ebra_domains = ['bienpublic.com', 'dna.fr', 'estrepublicain.fr', 'lalsace.fr', 'ledauphine.com', 'lejsl.com', 'leprogres.fr', 'republicain-lorrain.fr', 'vosgesmatin.fr'];
2020-12-07 18:10:59 +01:00
const fr_groupe_la_depeche_domains = ['centrepresseaveyron.fr', 'ladepeche.fr', 'lindependant.fr', 'midi-olympique.fr', 'midilibre.fr', 'nrpyrenees.fr', 'petitbleu.fr'];
2021-01-05 18:53:59 +01:00
const it_ilmessaggero_domains = ['corriereadriatico.it', 'ilgazzettino.it', 'ilmattino.it', 'ilmessaggero.it', 'quotidianodipuglia.it'];
const nl_ad_region_domains = ['ad.nl', 'bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl'];
2021-01-09 18:14:34 +01:00
const usa_nymag_domains = ['curbed.com', 'grubstreet.com', 'nymag.com', 'thecut.com', 'vulture.com'];
// grouped domains (rules only)
const au_nine_domains = ['brisbanetimes.com.au', 'smh.com.au', 'theage.com.au', 'watoday.com.au'];
const es_epiberica_domains = ['diariodeibiza.es', 'diariodemallorca.es', 'farodevigo.es', 'laprovincia.es'];
const nl_pg_domains = ['parool.nl', 'trouw.nl', 'volkskrant.nl', 'humo.be', 'demorgen.be'];
2020-11-02 18:52:40 +01:00
const userAgentDesktopG = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
const userAgentMobileG = "Chrome/80.0.3987.92 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)"
const userAgentDesktopB = "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
const userAgentMobileB = "Chrome/80.0.3987.92 Mobile Safari/537.36 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
2017-07-08 19:40:29 +02:00
var enabledSites = [];
var disabledSites = [];
2020-11-05 22:21:41 +01:00
var defaultSites_grouped_domains = Object.values(defaultSites);
2021-01-08 18:40:14 +01:00
var defaultSites_domains = defaultSites_grouped_domains.concat(au_comm_media_domains, au_news_corp_domains, au_prov_news_domains, ca_torstar_domains, de_funke_media_domains, de_madsack_domains, es_grupo_vocento_domains, fi_alma_talent_domains, fr_be_groupe_rossel_domains, fr_groupe_ebra_domains, fr_groupe_la_depeche_domains, it_ilmessaggero_domains, nl_ad_region_domains, usa_nymag_domains);
var customSites = {};
var customSites_domains = [];
2021-01-05 18:53:59 +01:00
var excludedSites = [];
2017-07-08 19:40:29 +02:00
function setDefaultOptions() {
ext_api.storage.local.set({
sites: defaultSites
}, function () {
ext_api.runtime.openOptionsPage();
});
}
2020-11-27 19:34:15 +01:00
// copy storage.sync to storage.local (quota exceeded)
ext_api.storage.sync.get({
sites: {},
sites_custom: {},
daily_users: {},
optIn: {},
optInShown: {},
customShown: {}
}, function (items) {
if (Object.keys(items.sites).length > 0) {
ext_api.storage.local.set({
sites: items.sites,
sites_custom: items.sites_custom,
daily_users: items.daily_users,
optIn: items.optIn,
optInShown: items.optInShown,
customShown: items.customShown
}, function () {
ext_api.storage.sync.remove(['sites', 'sites_custom']);
});
}
});
2020-12-07 18:10:59 +01:00
var grouped_sites = {
'###_au_comm_media': au_comm_media_domains,
'###_au_news_corp': au_news_corp_domains,
'###_au_prov_news': au_prov_news_domains,
2021-01-08 18:40:14 +01:00
'###_ca_torstar': ca_torstar_domains,
2020-12-10 20:23:12 +01:00
'###_de_funke_medien': de_funke_media_domains,
2020-12-08 20:13:27 +01:00
'###_de_madsack': de_madsack_domains,
2020-12-07 18:10:59 +01:00
'###_es_grupo_vocento': es_grupo_vocento_domains,
'###_fi_alma_talent': fi_alma_talent_domains,
'###_fr_be_groupe_rossel': fr_be_groupe_rossel_domains,
'###_fr_groupe_ebra': fr_groupe_ebra_domains,
'###_fr_groupe_la_depeche': fr_groupe_la_depeche_domains,
2021-01-05 18:53:59 +01:00
'###_it_ilmessaggero': it_ilmessaggero_domains,
'###_nl_ad_region': nl_ad_region_domains,
'###_usa_nymag': usa_nymag_domains
2020-12-07 18:10:59 +01:00
};
function add_grouped__enabled_domains(groups) {
for (let key in groups) {
if (enabledSites.includes(key))
enabledSites = enabledSites.concat(groups[key]);
else
disabledSites = disabledSites.concat(groups[key]);
2021-01-05 18:53:59 +01:00
for (let site of excludedSites) {
if (enabledSites.includes(site)) {
enabledSites.splice(enabledSites.indexOf(site), 1);
disabledSites.push(site);
}
}
2020-12-07 18:10:59 +01:00
}
}
// add grouped sites to en/disabledSites & init rules (optional)
function add_grouped_sites(init_rules) {
2020-12-07 18:10:59 +01:00
add_grouped__enabled_domains(grouped_sites);
2020-11-21 13:45:18 +01:00
if (init_rules) {
for (let domain of au_comm_media_domains) {
allow_cookies.push(domain);
blockedRegexes[domain] = /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/;
}
for (let domain of au_news_corp_domains) {
allow_cookies.push(domain);
use_google_bot.push(domain);
2021-01-02 12:48:07 +01:00
blockedRegexes[domain] = /cdn\.ampproject\.org\/v\d\/amp-(access|ad|iframe)-.+\.js/;
2020-11-21 13:45:18 +01:00
}
for (let domain of au_prov_news_domains) {
allow_cookies.push(domain);
use_google_bot.push(domain);
}
2021-01-08 18:40:14 +01:00
for (let domain of ca_torstar_domains) {
allow_cookies.push(domain);
blockedRegexes[domain] = /\.(ca|com)\/api\/overlaydata/;
}
2020-12-10 20:23:12 +01:00
for (let domain of de_funke_media_domains) {
allow_cookies.push(domain);
blockedRegexes[domain] = /(cdn\.cxense\.com\/.+|\.tinypass\.com\/.+)/;
2020-12-10 20:23:12 +01:00
}
for (let domain of es_grupo_vocento_domains) {
allow_cookies.push(domain);
2021-01-02 12:48:07 +01:00
blockedRegexes[domain] = /cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent|subscriptions)-.+\.js/;
}
2020-11-27 19:34:15 +01:00
for (let domain of fi_alma_talent_domains) {
use_google_bot.push(domain);
}
2020-12-06 12:43:16 +01:00
for (let domain of fr_be_groupe_rossel_domains) {
if (!['lecho.be'].includes(domain)) {
2020-12-06 12:43:16 +01:00
allow_cookies.push(domain);
use_google_bot.push(domain);
}
}
2020-12-06 22:32:59 +01:00
for (let domain of fr_groupe_ebra_domains) {
allow_cookies.push(domain);
2021-01-02 12:48:07 +01:00
blockedRegexes[domain] = /(.+\.poool\.fr\/.+|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js)/;
2020-12-07 18:10:59 +01:00
}
for (let domain of fr_groupe_la_depeche_domains) {
allow_cookies.push(domain);
blockedRegexes[domain] = /(.+\.poool\.fr\/.+|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js)/;//|iframe
2020-12-06 22:32:59 +01:00
}
for (let domain of it_ilmessaggero_domains)
2020-11-21 13:45:18 +01:00
blockedRegexes[domain] = /utils\.cedsdigital\.it\/js\/PaywallMeter\.js/;
for (let domain of nl_ad_region_domains)
remove_cookies_select_drop[domain] = ['temptationTrackingId'];
// rules only
for (let domain of au_nine_domains)
blockedRegexes[domain] = /cdn\.ampproject\.org\/v\d\/amp-subscriptions-.+\.js/;
for (let domain of es_epiberica_domains)
allow_cookies.push(domain);
for (let domain of nl_pg_domains)
2020-11-21 13:45:18 +01:00
remove_cookies_select_drop[domain] = ['TID_ID'];
use_google_bot_default = use_google_bot.slice();
change_headers = use_google_bot.concat(use_bing_bot, use_facebook_referer, use_twitter_referer, use_random_ip);
2020-11-21 13:45:18 +01:00
}
}
// Get the enabled sites (from local storage) & add to allow/remove_cookies (if not already in one of these arrays)
// Add googlebot- and block_javascript-settings for custom sites
ext_api.storage.local.get({
sites: {},
2021-01-05 18:53:59 +01:00
sites_custom: {},
sites_excluded: []
}, function (items) {
var sites = items.sites;
var sites_custom = items.sites_custom;
2021-01-05 18:53:59 +01:00
excludedSites = items.sites_excluded;
for (let key in sites_custom) {
var domainVar = sites_custom[key]['domain'].toLowerCase();
if (sites_custom[key]['googlebot'] > 0 && !use_google_bot.includes(domainVar))
use_google_bot.push(domainVar);
if (sites_custom[key]['allow_cookies'] > 0 && !allow_cookies.includes(domainVar))
2020-11-10 18:15:18 +01:00
allow_cookies.push(domainVar);
if (sites_custom[key]['block_javascript'] > 0)
block_js_custom.push(domainVar);
if (sites_custom[key]['block_javascript_ext'] > 0)
block_js_custom_ext.push(domainVar);
}
enabledSites = Object.keys(sites).filter(function (key) {
return (sites[key] !== '' && sites[key] !== '###');
}).map(function (key) {
return sites[key].toLowerCase();
});
customSites = sites_custom;
customSites_domains = Object.values(sites_custom).map(x => x.domain);
disabledSites = defaultSites_domains.concat(customSites_domains).filter(x => !enabledSites.includes(x) && x !== '###');
2021-01-05 18:53:59 +01:00
add_grouped_sites(true); //and exclude sites
for (let domainVar of enabledSites) {
if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) {
allow_cookies.push(domainVar);
remove_cookies.push(domainVar);
}
}
disableJavascriptOnListedSites();
});
// Listen for changes to options
ext_api.storage.onChanged.addListener(function (changes, namespace) {
if (namespace === 'sync')
return;
2020-11-10 18:15:18 +01:00
for (let key in changes) {
var storageChange = changes[key];
if (key === 'sites') {
var sites = storageChange.newValue;
enabledSites = Object.keys(sites).filter(function (key) {
return (sites[key] !== '' && sites[key] !== '###');
}).map(function (key) {
return sites[key];
});
disabledSites = defaultSites_domains.concat(customSites_domains).filter(x => !enabledSites.includes(x) && x !== '###');
add_grouped_sites(false);
2020-11-10 18:15:18 +01:00
for (let domainVar of enabledSites) {
if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) {
allow_cookies.push(domainVar);
remove_cookies.push(domainVar);
}
}
}
if (key === 'sites_custom') {
var sites_custom = storageChange.newValue ? storageChange.newValue : {};
var sites_custom_old = storageChange.oldValue ? storageChange.oldValue : {};
customSites = sites_custom;
customSites_domains = Object.values(sites_custom).map(x => x.domain);
// add/remove custom sites in options
var sites_custom_added = Object.keys(sites_custom).filter(x => !Object.keys(sites_custom_old).includes(x) && !defaultSites.hasOwnProperty(x));
var sites_custom_removed = Object.keys(sites_custom_old).filter(x => !Object.keys(sites_custom).includes(x) && !defaultSites.hasOwnProperty(x));
ext_api.storage.local.get({
sites: {}
}, function (items) {
var sites = items.sites;
2020-11-10 18:15:18 +01:00
for (let key of sites_custom_added)
sites[key] = sites_custom[key].domain;
2020-11-10 18:15:18 +01:00
for (let key of sites_custom_removed)
delete sites[key];
ext_api.storage.local.set({
sites: sites
}, function () {
true;
});
});
2020-11-10 18:15:18 +01:00
// restore cookie-settings for removed custom (& also default) domain
var sites_custom_default_domain_removed = Object.values(sites_custom_old).map(function (site_old) {
return site_old.domain;
}).filter(x => !Object.values(sites_custom).map(function (site_new) {
return site_new.domain;
}).includes(x) && defaultSites_domains.includes(x));
for (let domain of sites_custom_default_domain_removed) {
if (!allow_cookies_default.includes(domain) && !remove_cookies.includes(domain))
remove_cookies.push(domain);
}
use_google_bot = use_google_bot_default.slice();
block_js_custom = [];
block_js_custom_ext = [];
for (let key in sites_custom) {
var domainVar = sites_custom[key]['domain'].toLowerCase();
if (sites_custom[key]['googlebot'] > 0 && !use_google_bot.includes(domainVar)) {
use_google_bot.push(domainVar);
}
2020-11-10 18:15:18 +01:00
if (sites_custom[key]['allow_cookies'] > 0) {
if (allow_cookies.includes(domainVar)) {
if (remove_cookies.includes(domainVar))
remove_cookies.splice(remove_cookies.indexOf(domainVar), 1);
} else
allow_cookies.push(domainVar);
} else if (!allow_cookies_default.includes(domainVar) && allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar))
remove_cookies.push(domainVar);
if (sites_custom[key]['block_javascript'] > 0) {
block_js_custom.push(domainVar);
}
if (sites_custom[key]['block_javascript_ext'] > 0) {
block_js_custom_ext.push(domainVar);
}
}
change_headers = use_google_bot.concat(use_bing_bot, use_facebook_referer, use_twitter_referer, use_random_ip);
2017-07-08 19:40:29 +02:00
}
2021-01-05 18:53:59 +01:00
if (key === 'sites_excluded') {
var sites_excluded = storageChange.newValue ? storageChange.newValue : [];
var sites_excluded_old = storageChange.oldValue ? storageChange.oldValue : [];
excludedSites = sites_excluded;
// add/remove excluded sites in en/disabledSites
var sites_excluded_added = sites_excluded.filter(x => !sites_excluded_old.includes(x));
var sites_excluded_removed = sites_excluded_old.filter(x => !sites_excluded.includes(x));
for (let site of sites_excluded_added) {
if (enabledSites.includes(site)) {
enabledSites.splice(enabledSites.indexOf(site), 1);
disabledSites.push(site);
}
}
for (let site of sites_excluded_removed) {
if (disabledSites.includes(site)) {
disabledSites.splice(disabledSites.indexOf(site), 1);
enabledSites.push(site);
}
}
}
// reset disableJavascriptOnListedSites eventListener
ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites);
ext_api.webRequest.handlerBehaviorChanged();
// Refresh the current tab
ext_api.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) {
ext_api.tabs.update(tabs[0].id, {
url: tabs[0].url
});
}
});
}
2017-07-08 19:40:29 +02:00
});
// Set and show default options on install
ext_api.runtime.onInstalled.addListener(function (details) {
2017-07-08 19:40:29 +02:00
if (details.reason == "install") {
setDefaultOptions();
2017-07-08 19:40:29 +02:00
} else if (details.reason == "update") {
ext_api.management.getSelf(function (result) {
if (enabledSites.includes('#options_on_update') && result.installType !== 'development')
ext_api.runtime.openOptionsPage(); // User updated extension (non-developer mode)
});
2017-07-08 19:40:29 +02:00
}
});
// repubblica.it bypass
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
if (!isSiteEnabled(details)) {
return;
}
var updatedUrl = details.url.replace('/pwa/', '/ws/detail/');
return { redirectUrl: updatedUrl };
},
{urls:["*://*.repubblica.it/pwa/*"], types:["main_frame"]},
["blocking"]
);
// inkl disable newsletter login
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
if (!isSiteEnabled(details)) {
return;
}
var updatedUrl = details.url.replace(/etok=[\w]*&/, '');
return { redirectUrl: updatedUrl };
},
{urls:["*://*.inkl.com/*"], types:["main_frame"]},
["blocking"]
);
const faz_uaMobile = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36";
ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) {
if (!isSiteEnabled(details)) {
return;
}
let headers = details.requestHeaders;
headers = headers.map(function (header) {
if (header.name.toLowerCase() === 'user-agent')
header.value = faz_uaMobile;
return header;
});
return {
requestHeaders: headers
};
}, {
urls: ["*://m.faz.net/*"],
types: ["xmlhttprequest"]
},
["blocking", "requestHeaders"]);
// fix nytimes x-frame-options (hidden iframe content)
ext_api.webRequest.onHeadersReceived.addListener(function (details) {
if (!isSiteEnabled(details)) {
return;
}
var headers = details.responseHeaders;
2021-01-06 19:50:12 +01:00
headers = headers.map(function (header) {
if (header.name === 'x-frame-options')
header.value = 'SAMEORIGIN';
return header;
});
return {
responseHeaders: headers
};
}, {
urls: ["*://*.nytimes.com/*"]
},
['blocking', 'responseHeaders']);
2021-01-31 21:42:00 +01:00
// elviajero|retina|verne.elpais.com block inline script
2021-01-18 18:43:04 +01:00
ext_api.webRequest.onHeadersReceived.addListener(function (details) {
if (!isSiteEnabled(details)) {
return;
}
var headers = details.responseHeaders;
headers.push({
'name': 'Content-Security-Policy',
'value': "script-src *;"
});
return {
responseHeaders: headers
};
}, {
'types': ['main_frame', 'sub_frame'],
2021-01-31 21:42:00 +01:00
'urls': ["*://elviajero.elpais.com/*", "*://retina.elpais.com/*", "*://verne.elpais.com/*"]
2021-01-18 18:43:04 +01:00
},
['blocking', 'responseHeaders']);
var block_js_default = ["*://*.tinypass.com/*", "*://*.piano.io/*", "*://*.poool.fr/*", "*://cdn.ampproject.org/v*/amp-access-*.js", "*://*.blueconic.net/*", "*://*.cxense.com/*", "*://*.evolok.net/*", "*://js.matheranalytics.com/*", "*://*.newsmemory.com/*", "*://*.onecount.net/*", "*://js.pelcro.com/*", "*://*.qiota.com/*", "*://*.tribdss.com/*"];
var block_js_custom = [];
var block_js_custom_ext = [];
var block_js = block_js_default.concat(block_js_custom);
// Disable javascript for these sites/general paywall-scripts
function disableJavascriptOnListedSites() {
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
let header_referer = details.originUrl ? details.originUrl : details.initiator;
if (!isSiteEnabled(details) || matchUrlDomain(excludedSites, header_referer)) {
return;
}
return {
cancel: true
};
}, {
urls: block_js,
types: ["script", "xmlhttprequest"]
},
["blocking"]);
}
var extraInfoSpec = ['blocking', 'requestHeaders'];
if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'))
extraInfoSpec.push('extraHeaders');
ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
2020-09-11 16:52:50 +02:00
if (details.type === 'main_frame') {
let current_date_str = currentDateStr();
if (last_date_str < current_date_str) {
bpc_count_daily_users(current_date_str);
last_date_str = current_date_str;
}
}
var requestHeaders = details.requestHeaders;
var header_referer = '';
2020-11-10 18:15:18 +01:00
for (let n in requestHeaders) {
2020-09-11 16:52:50 +02:00
if (requestHeaders[n].name.toLowerCase() == 'referer') {
header_referer = requestHeaders[n].value;
continue;
}
}
// fix brave browser
if (!details.originUrl && !header_referer.includes(details.initiator))
header_referer = details.initiator;
// remove cookies for sites medium platform (custom domains)
var medium_custom_domain = (matchUrlDomain('cdn-client.medium.com', details.url) && !matchUrlDomain(['medium.com', 'towardsdatascience.com'], header_referer) && enabledSites.includes('###_medium_custom'));
2020-05-28 16:38:48 +02:00
if (medium_custom_domain) {
ext_api.cookies.getAll({domain: urlHost(header_referer)}, function(cookies) {
for (let cookie of cookies) {
ext_api.cookies.remove({url: (cookie.secure ? "https://" : "http://") + cookie.domain + cookie.path, name: cookie.name});
}
});
}
2020-12-04 16:56:48 +01:00
// block external javascript for custom sites (optional)
2020-08-22 13:52:43 +02:00
var domain_blockjs_ext = matchUrlDomain(block_js_custom_ext, header_referer);
2021-01-26 21:27:43 +01:00
if (domain_blockjs_ext && !matchUrlDomain(domain_blockjs_ext, details.url) && details.type === 'script' && isSiteEnabled({url: header_referer})) {
return { cancel: true };
}
// check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
var blockedDomains = Object.keys(blockedRegexes);
var domain = matchUrlDomain(blockedDomains, header_referer);
var block_regex = true;
if (domain && details.url.match(blockedRegexes[domain]) && isSiteEnabled({url: header_referer})) {
if (block_regex)
return { cancel: true };
2017-07-08 19:40:29 +02:00
}
// load toggleIcon.js (icon for dark or incognito mode in Chrome))
if (typeof browser !== 'object') {
ext_api.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) {
ext_api.tabs.executeScript({
file: 'toggleIcon.js',
runAt: 'document_start'
}, function (res) {
if (ext_api.runtime.lastError || res[0]) {
return;
}
});
}
});
}
2020-06-20 09:43:02 +02:00
let inkl_site = (matchUrlDomain('cdn.jsdelivr.net', details.url) && matchUrlDomain('inkl.com', header_referer) && isSiteEnabled({url: header_referer}));
2020-10-18 14:49:32 +02:00
let au_nc_amp_site = (matchUrlDomain('cdn.ampproject.org', details.url) && matchUrlDomain(au_news_corp_domains, header_referer) && isSiteEnabled({url: header_referer}));
let au_apn_site = (header_referer && (urlHost(header_referer).endsWith('com.au') || urlHost(header_referer).endsWith('net.au')) && details.url.includes('https://media.apnarm.net.au/'));
2020-10-15 17:11:03 +02:00
let au_swm_site = (header_referer && urlHost(header_referer).endsWith('com.au') && details.url.includes('https://s.thewest.com.au/'));
2021-01-30 19:18:00 +01:00
let cl_elmerc_site = (matchUrlDomain('emol.cl', details.url) && matchUrlDomain('elmercurio.com', header_referer) && isSiteEnabled({url: header_referer}));
2021-01-09 18:14:34 +01:00
let uk_nlr_site = (matchUrlDomain('stripe.com', details.url) && matchUrlDomain('newleftreview.org', header_referer) && isSiteEnabled({url: header_referer}));
let usa_discmag_site = (matchUrlDomain('ctfassets.net', details.url) && matchUrlDomain('discovermagazine.com', header_referer) && isSiteEnabled({url: header_referer}));
2021-01-24 10:25:55 +01:00
let usa_mw_site = (matchUrlDomain('wsj.net', details.url) && matchUrlDomain('marketwatch.com', header_referer) && isSiteEnabled({url: header_referer}));
let bpc_amp_site = (matchUrlDomain('cdn.ampproject.org', details.url) && isSiteEnabled({url: header_referer}) &&
2021-01-24 10:25:55 +01:00
matchUrlDomain(['barrons.com', 'belfasttelegraph.co.uk', 'cicero.de', 'cmjornal.pt', 'elmundo.es', 'elpais.com', 'elperiodico.com', 'expansion.com', 'freiepresse.de', 'fresnobee.com', 'gelocal.it', 'independent.ie', 'irishtimes.com', 'la-croix.com', 'lne.es', 'marketwatch.com', 'nationalreview.com', 'sacbee.com', 'seekingalpha.com', 'sueddeutsche.de', 'svz.de', 'telegraph.co.uk'].concat(au_nine_domains, es_grupo_vocento_domains, fr_groupe_ebra_domains, fr_groupe_la_depeche_domains), header_referer));
if (!isSiteEnabled(details) && !inkl_site && !au_nc_amp_site && !au_apn_site && !au_swm_site && !cl_elmerc_site && !medium_custom_domain && !uk_nlr_site && !usa_discmag_site && !usa_mw_site && !bpc_amp_site) {
return;
2018-11-24 23:10:21 +01:00
}
// remove cookies Discover Magazine
if (details.type === 'image' && matchUrlDomain('ctfassets.net', details.url) && matchUrlDomain('discovermagazine.com', header_referer) && isSiteEnabled({url: 'https://www.discovermagazine.com'})) {
ext_api.cookies.getAll({domain: 'discovermagazine.com'}, function(cookies) {
for (let cookie of cookies) {
ext_api.cookies.remove({url: (cookie.secure ? "https://" : "http://") + cookie.domain + cookie.path, name: cookie.name});
}
});
}
// block javascript of (sub)domain for custom sites (optional)
2020-08-22 13:52:43 +02:00
var domain_blockjs = matchUrlDomain(block_js_custom, details.url);
2021-01-26 21:27:43 +01:00
if (domain_blockjs && matchUrlDomain(domain_blockjs, details.url) && details.type === 'script') {
return { cancel: true };
}
2017-07-08 19:40:29 +02:00
var tabId = details.tabId;
var useUserAgentMobile = false;
2017-07-08 19:40:29 +02:00
var setReferer = false;
if (['main_frame', 'xmlhttprequest'].includes(details.type) && matchUrlDomain(change_headers, details.url)){
2017-07-08 19:40:29 +02:00
// if referer exists, set it to google
requestHeaders = requestHeaders.map(function (requestHeader) {
2017-07-08 19:40:29 +02:00
if (requestHeader.name === 'Referer') {
if (matchUrlDomain(use_facebook_referer, details.url)) {
requestHeader.value = 'https://www.facebook.com/';
} else if (matchUrlDomain(use_twitter_referer, details.url)) {
requestHeader.value = 'https://t.co/';
} else if (matchUrlDomain(use_google_bot, details.url)) {
requestHeader.value = 'https://www.google.com/';
}
setReferer = true;
}
if (requestHeader.name === 'User-Agent') {
useUserAgentMobile = requestHeader.value.toLowerCase().includes("mobile");
}
return requestHeader;
});
2017-07-08 19:40:29 +02:00
// otherwise add it
if (!setReferer) {
if (matchUrlDomain(use_facebook_referer, details.url)) {
2017-07-08 19:40:29 +02:00
requestHeaders.push({
name: 'Referer',
value: 'https://www.facebook.com/'
});
} else if (matchUrlDomain(use_twitter_referer, details.url)) {
requestHeaders.push({
name: 'Referer',
value: 'https://t.co/'
});
2017-07-08 19:40:29 +02:00
} else {
requestHeaders.push({
name: 'Referer',
value: 'https://www.google.com/'
});
}
}
2017-07-08 19:40:29 +02:00
// override User-Agent to use Googlebot
if (matchUrlDomain(use_google_bot, details.url)) {
requestHeaders.push({
"name": "User-Agent",
2020-11-02 18:52:40 +01:00
"value": useUserAgentMobile ? userAgentMobileG : userAgentDesktopG
})
requestHeaders.push({
"name": "X-Forwarded-For",
"value": "66.249.66.1"
})
2017-07-08 19:40:29 +02:00
}
2020-11-02 18:52:40 +01:00
// override User-Agent to use Bingbot
if (matchUrlDomain(use_bing_bot, details.url)) {
requestHeaders.push({
"name": "User-Agent",
"value": useUserAgentMobile ? userAgentMobileB : userAgentDesktopB
})
}
// random IP for sites in use_random_ip
if (matchUrlDomain(use_random_ip, details.url)) {
requestHeaders.push({
"name": "X-Forwarded-For",
"value": randomIP()
})
}
}
2017-07-08 19:40:29 +02:00
// remove cookies before page load
if (!matchUrlDomain(allow_cookies, details.url)) {
requestHeaders = requestHeaders.map(function(requestHeader) {
if (requestHeader.name === 'Cookie') {
requestHeader.value = '';
2017-07-08 19:40:29 +02:00
}
return requestHeader;
});
}
2017-07-08 19:40:29 +02:00
2020-09-14 21:29:13 +02:00
if (tabId !== -1) {
ext_api.tabs.get(tabId, function (currentTab) {
2020-11-23 18:12:40 +01:00
if ((currentTab && isSiteEnabled(currentTab)) || medium_custom_domain || au_apn_site || au_swm_site) {
if (currentTab.url !== currentTabUrl) {
csDone = false;
currentTabUrl = currentTab.url;
}
if ((['main_frame', 'script', 'other', 'xmlhttprequest'].includes(details.type) || matchUrlDomain(cs_limit_except, currentTabUrl)) && !csDone) {
ext_api.tabs.executeScript(tabId, {
file: 'contentScript.js',
runAt: 'document_start'
}, function (res) {
if (ext_api.runtime.lastError || res[0]) {
return;
}
});
}
}
2020-09-14 21:29:13 +02:00
});
} else {//mercuriovalpo.cl
ext_api.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) {
if (isSiteEnabled({url: tabs[0].url})) {
2020-09-14 21:29:13 +02:00
ext_api.tabs.executeScript({
file: 'contentScript.js',
runAt: 'document_start'
}, function (res) {
if (ext_api.runtime.lastError || res[0]) {
return;
}
});
}
2017-07-08 19:40:29 +02:00
}
2020-09-14 21:29:13 +02:00
});
}
2017-07-08 19:40:29 +02:00
return { requestHeaders: requestHeaders };
}, {
urls: ['<all_urls>']
}, extraInfoSpec);
// extraInfoSpec is ['blocking', 'requestHeaders'] + possible 'extraHeaders'
2017-07-08 19:40:29 +02:00
ext_api.tabs.onUpdated.addListener(function (tabId, info, tab) { updateBadge(tab); });
ext_api.tabs.onActivated.addListener(function (activeInfo) { ext_api.tabs.get(activeInfo.tabId, updateBadge); });
2020-11-02 16:57:47 +01:00
function updateBadge(activeTab) {
if (ext_api.runtime.lastError || !activeTab)
2020-11-02 16:57:47 +01:00
return;
let badgeText = '';
let color = 'red';
let currentUrl = activeTab.url;
if (currentUrl) {
if (isSiteEnabled({url: currentUrl})) {
badgeText = 'ON';
color = 'red';
} else if (matchUrlDomain(enabledSites, currentUrl)) {
badgeText = 'ON-';
2020-11-02 16:57:47 +01:00
color = 'orange';
} else if (matchUrlDomain(disabledSites, currentUrl)) {
badgeText = 'OFF';
2020-11-02 16:57:47 +01:00
color = 'blue';
}
2020-11-02 16:57:47 +01:00
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
let isCustomSite = matchUrlDomain(customSites_domains, currentUrl);
if (!isDefaultSite && isCustomSite) {
ext_api.permissions.contains({
origins: ["<all_urls>"]
}, function (result) {
if (!result)
badgeText = '';
if (color && badgeText)
ext_api.browserAction.setBadgeBackgroundColor({color: color});
ext_api.browserAction.setBadgeText({text: badgeText});
});
} else {
2020-11-02 16:57:47 +01:00
if (color && badgeText)
ext_api.browserAction.setBadgeBackgroundColor({color: color});
ext_api.browserAction.setBadgeText({text: badgeText});
2020-11-02 16:57:47 +01:00
}
}
}
function site_switch() {
ext_api.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) {
let currentUrl = tabs[0].url;
2020-11-05 22:21:41 +01:00
let isDefaultSite = matchUrlDomain(defaultSites_grouped_domains, currentUrl);
2020-12-09 17:32:30 +01:00
if (!isDefaultSite) {
let isDefaultSiteGroup = matchUrlDomain(defaultSites_domains, currentUrl);
if (isDefaultSiteGroup)
isDefaultSite = Object.keys(grouped_sites).find(key => grouped_sites[key].includes(isDefaultSiteGroup));
}
let defaultSite_title = isDefaultSite ? Object.keys(defaultSites).find(key => defaultSites[key] === isDefaultSite) : '';
let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl);
let customSite_title = isCustomSite ? Object.keys(customSites).find(key => customSites[key].domain === isCustomSite) : '';
let site_title = defaultSite_title || customSite_title;
let domain = isDefaultSite || isCustomSite;
if (domain && site_title) {
let added_site = [];
let removed_site = [];
if (enabledSites.includes(domain))
removed_site.push(site_title);
else
added_site.push(site_title);
ext_api.storage.local.get({
sites: {}
}, function (items) {
var sites = items.sites;
2020-11-10 18:15:18 +01:00
for (let key of added_site)
sites[key] = domain;
2020-11-10 18:15:18 +01:00
for (let key of removed_site)
delete sites[key];
ext_api.storage.local.set({
sites: sites
}, function () {
true;
});
});
}
}
});
}
2020-11-05 22:21:41 +01:00
function popup_show_toggle_tab(callback) {
2021-01-05 18:53:59 +01:00
ext_api.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) {
let currentUrl = tabs[0].url;
let domain;
let isExcludedSite = matchUrlDomain(excludedSites, currentUrl);
if (!isExcludedSite) {
let isDefaultSiteGrouped = matchUrlDomain(defaultSites_domains, currentUrl);
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl);
domain = isDefaultSiteGrouped || (!isDefaultSite && isCustomSite);
}
callback(domain);
}
});
2020-11-05 22:21:41 +01:00
};
2017-07-08 19:40:29 +02:00
// remove cookies after page load
ext_api.webRequest.onCompleted.addListener(function (details) {
var domainVar = matchUrlDomain(remove_cookies, details.url);
2020-12-15 17:03:17 +01:00
if ((!['main_frame', 'xmlhttprequest', 'other'].includes(details.type)) || !domainVar || !enabledSites.includes(domainVar))
return;
ext_api.cookies.getAll({
domain: domainVar
}, function (cookies) {
for (let cookie of cookies) {
var rc_domain = cookie.domain.replace(/^(\.?www\.|\.)/, '');
// hold specific cookie(s) from remove_cookies domains
if ((rc_domain in remove_cookies_select_hold) && remove_cookies_select_hold[rc_domain].includes(cookie.name)) {
continue; // don't remove specific cookie
}
// drop only specific cookie(s) from remove_cookies domains
if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookie.name))) {
continue; // only remove specific cookie
}
2021-01-02 12:48:07 +01:00
// hold on to consent-cookie
if (cookie.name.match(/(consent|^optanon)/i)) {
continue;
}
cookie.domain = cookie.domain.replace(/^\./, '');
ext_api.cookies.remove({
url: (cookie.secure ? "https://" : "http://") + cookie.domain + cookie.path,
name: cookie.name
});
}
});
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 clear_cookies() {
ext_api.tabs.query({
active: true,
currentWindow: true
}, function (tabs) {
if (tabs.length > 0 && tabs[0].url && tabs[0].url.indexOf("http") !== -1) {
ext_api.tabs.executeScript({
file: 'clearCookies.js',
runAt: 'document_start'
}, function (res) {
if (ext_api.runtime.lastError || res[0]) {
return;
}
});
ext_api.tabs.update(tabs[0].id, {
url: tabs[0].url
});
}
});
}
2020-10-29 18:39:46 +01:00
var chrome_scheme = 'light';
ext_api.runtime.onMessage.addListener(function (message, sender) {
// check storage for opt in
if (message.request === 'optin') {
ext_api.storage.local.get("optIn", function (result) {
// send message back to content script with value of opt in
ext_api.tabs.sendMessage(
sender.tab.id, {
"optIn": (true == result.optIn)
});
});
}
// clear cookies for domain
if (message.domain) {
var domainVar = message.domain.replace('www.', '');
ext_api.cookies.getAll({
domain: domainVar
}, function (cookies) {
for (let cookie of cookies) {
cookie.domain = cookie.domain.replace(/^\./, '');
ext_api.cookies.remove({
url: (cookie.secure ? "https://" : "http://") + cookie.domain + cookie.path,
name: cookie.name
});
}
});
}
if (message.scheme && ![chrome_scheme, 'undefined'].includes(message.scheme)) {
2020-10-29 18:39:46 +01:00
let icon_path = {path: {'128': 'bypass.png'}};
if (message.scheme === 'dark')
icon_path = {path: {'128': 'bypass-dark.png'}};
ext_api.browserAction.setIcon(icon_path);
chrome_scheme = message.scheme;
}
if (message.csDone) {
csDone = true;
//console.log('msg.csDone: ' + csDone);
}
});
// show the tab if we haven't registered the user reacting to the prompt.
ext_api.storage.local.get(["optInShown", "customShown"], function (result) {
if (!result.optInShown || !result.customShown) {
ext_api.tabs.create({
url: "optin/opt-in.html"
});
ext_api.storage.local.set({
"optInShown": true,
"customShown": true
});
}
});
2019-02-11 00:43:12 +01:00
function isSiteEnabled(details) {
var enabledSite = matchUrlDomain(enabledSites, details.url);
if (!ext_name.includes('Clean'))
enabledSite = '';
if (enabledSite in restrictions) {
return restrictions[enabledSite].test(details.url);
}
return !!enabledSite;
}
function matchDomain(domains, hostname) {
var matched_domain = false;
if (!hostname)
hostname = window.location.hostname;
if (typeof domains === 'string')
domains = [domains];
domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
return matched_domain;
}
function urlHost(url) {
if (url && url.startsWith('http')) {
try {
return new URL(url).hostname;
} catch (e) {
console.log(`url not valid: ${url} error: ${e}`);
}
}
return url;
}
function matchUrlDomain(domains, url) {
return matchDomain(domains, urlHost(url));
2019-02-11 00:43:12 +01:00
}
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, ' '));
}
function stripQueryStringAndHashFromPath(url) {
return url.split("?")[0].split("#")[0];
}
function randomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
function randomIP() {
let rndmIP = [];
for (let n = 0; n < 4; n++)
rndmIP.push(randomInt(254) + 1);
return rndmIP.join('.');
}