bypass-paywalls-firefox-clean/background.js

745 lines
29 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;
2017-07-08 19:40:29 +02:00
// 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 = {
2020-06-15 22:21:42 +02:00
'barrons.com': /.+barrons\.com\/(amp\/)?article(s)?\/.+/,
'elcomercio.pe': /.+\/elcomercio.pe\/.+((\w)+(\-)+){3,}.+/,
'gestion.pe': /.+\/gestion.pe\/.+((\w)+(\-)+){3,}.+/,
'quora.com': /^((?!quora\.com\/search\?q=).)*$/,
'seekingalpha.com': /.+seekingalpha\.com\/article\/.+/,
'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)
var allow_cookies = [
2020-06-27 14:22:39 +02:00
'abc.es',
2020-03-04 18:55:47 +01:00
'aftonbladet.se',
2020-07-05 13:11:58 +02:00
'belfasttelegraph.co.uk',
'bostonglobe.com',
2020-07-04 13:33:25 +02:00
'business-standard.com',
'clarin.com',
'chronicle.com',
2020-03-19 20:12:04 +01:00
'demorgen.be',
2020-08-26 17:29:51 +02:00
'df.cl',
'dn.se',
'dvhn.nl',
'elmercurio.com',
2020-08-26 17:18:51 +02:00
'mercuriovalpo.cl',
'eurekareport.com.au',
'faz.net',
'folha.uol.com.br',
2020-06-18 20:55:18 +02:00
'ftm.nl',
'gestion.pe',
'haaretz.co.il',
'haaretz.com',
2020-01-11 14:05:12 +01:00
'handelsblatt.com',
2020-02-25 23:33:18 +01:00
'humo.be',
2020-06-27 13:49:37 +02:00
'ilfattoquotidiano.it',
2020-06-08 16:44:46 +02:00
'independent.ie',
'intelligentinvestor.com.au',
2020-06-26 19:56:58 +02:00
'knack.be',
'lc.nl',
'lesoir.be',
2020-08-21 09:41:41 +02:00
'limesonline.com',
'lrb.co.uk',
'mexiconewsdaily.com',
2020-01-31 15:19:17 +01:00
'modernhealthcare.com',
2020-06-17 16:45:16 +02:00
'nationalgeographic.com',
2020-01-31 15:01:53 +01:00
'nationalreview.com',
2020-03-23 17:59:16 +01:00
'newrepublic.com',
2020-08-02 12:35:09 +02:00
'noordhollandsdagblad.nl',
'nytimes.com',
2020-07-08 17:58:08 +02:00
'nzz.ch',
'parool.nl',
'quora.com',
2020-01-05 17:41:06 +01:00
'scribd.com',
2020-02-26 23:16:03 +01:00
'seekingalpha.com',
2020-06-26 18:54:43 +02:00
'slader.com',
2020-04-13 08:57:38 +02:00
'switzersuperreport.com.au',
'techinasia.com',
'the-american-interest.com',
'theathletic.co.uk',
2020-01-05 13:02:44 +01:00
'theathletic.com',
2020-07-09 20:53:36 +02:00
'thehindu.com',
'themarker.com',
'trouw.nl',
'volkskrant.nl',
'washingtonpost.com',
2020-01-31 14:17:59 +01:00
'worldpoliticsreview.com',
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 = {
2020-03-22 13:22:30 +01:00
'barrons.com': ['wsjregion'],
'newstatesman.com': ['STYXKEY_nsversion'],
'qz.com': ['gdpr'],
2020-03-20 11:21:55 +01:00
'wsj.com': ['wsjregion']
}
2020-04-13 19:11:29 +02:00
// list of regional ad.nl sites
const ad_region_domains = ['bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl'];
// select only specific cookie(s) to drop from remove_cookies domains
2020-04-13 19:11:29 +02:00
var remove_cookies_select_drop = {
'ad.nl': ['temptationTrackingId'],
'caixinglobal.com': ['CAIXINGLB_LOGIN_UUID'],
'dn.se': ['randomSplusId'],
2020-04-03 21:03:27 +02:00
'fd.nl': ['socialread'],
'nrc.nl': ['counter'],
'theatlantic.com': ['articleViews']
}
2020-04-13 19:11:29 +02:00
for (var domainIndex in ad_region_domains) {
let domain = ad_region_domains[domainIndex];
remove_cookies_select_drop[domain] = ['temptationTrackingId'];
}
// Override User-Agent with Googlebot
var use_google_bot_default = [
2020-06-27 14:22:39 +02:00
'abc.es',
2020-03-04 18:55:47 +01:00
'aftonbladet.se',
'barrons.com',
2020-08-26 17:29:51 +02:00
'df.cl',
'dn.se',
'eurekareport.com.au',
'ft.com',
2020-01-05 13:02:44 +01:00
'haaretz.co.il',
'haaretz.com',
2020-01-11 14:05:12 +01:00
'handelsblatt.com',
'intelligentinvestor.com.au',
'lesoir.be',
'mexiconewsdaily.com',
2020-04-28 09:46:27 +02:00
'miamiherald.com',
2020-07-08 17:58:08 +02:00
'nzz.ch',
'quora.com',
2020-06-14 18:37:06 +02:00
'republic.ru',
2020-02-26 23:16:03 +01:00
'seekingalpha.com',
2020-04-13 08:57:38 +02:00
'switzersuperreport.com.au',
'theathletic.co.uk',
2020-01-05 13:02:44 +01:00
'theathletic.com',
'themarker.com',
'thetimes.co.uk',
'washingtonpost.com',
2020-01-31 14:17:59 +01:00
'worldpoliticsreview.com',
2019-12-07 22:26:58 +01:00
'wsj.com',
];
var use_google_bot_custom = [];
var use_google_bot = use_google_bot_default.concat(use_google_bot_custom);
2020-03-10 19:12:25 +01:00
// block paywall-scripts individually
var blockedRegexes = {
'adweek.com': /.+\.lightboxcdn\.com\/.+/,
'afr.com': /afr\.com\/assets\/vendorsReactRedux_client.+\.js/,
'americanbanker.com': /.+\.tinypass\.com\/.+/,
2020-06-15 22:21:42 +02:00
'barrons.com': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/,
2020-07-05 13:11:58 +02:00
'belfasttelegraph.co.uk': /cdn\.flip-pay\.com\/clients\/inm\/flip-pay\.js/,
'bloomberg.com': /.+\.tinypass\.com\/.+/,
'bostonglobe.com': /meter\.bostonglobe\.com\/js\/.+/,
'businessinsider.com': /.+\.tinypass\.com\/.+/,
2020-05-02 21:55:47 +02:00
'challenges.fr': /.+\.poool\.fr\/.+/,
2020-07-25 09:06:49 +02:00
'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\/.+/,
'corriere.it': /(\.rcsobjects\.it\/(rcs_cpmt|rcs_tracking-service)\/|\.corriereobjects\.it\/.+\/js\/(_paywall\.sjs|tracking\/)|\.userzoom\.com\/files\/js\/|\.lp4\.io\/app\/)/,
'digiday.com': /.+\.tinypass\.com\/.+/,
2020-08-22 19:38:39 +02:00
'economist.com': /.+\.tinypass\.com\/.+/,
2020-06-18 07:59:22 +02:00
'estadao.com.br': /acesso\.estadao\.com\.br\/paywall\/.+\/pw\.js/,
2020-06-17 16:29:36 +02:00
'dvhn.nl': /.+\.evolok\.net\/.+\/authorize\/.+/,
2020-04-25 20:41:55 +02:00
'elcomercio.pe': /elcomercio\.pe\/pf\/dist\/template\/elcomercio-noticia.+\.js/,
2020-07-29 16:51:35 +02:00
'elmercurio.com': /(elmercurio\.com\/.+\/js\/modal\.js|merreader\.emol\.cl\/assets\/js\/(vendor\/modal|merPramV\d)\.js|staticmer(\d)?\.emol\.cl\/js\/.+\/(modal|PramModal\.min)\.js)/,
2020-05-25 21:01:41 +02:00
'elmundo.es': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/,
'elpais.com': /.+\.epimg\.net\/js\/.+\/noticia\.min\.js/,
'exame.abril.com.br': /.+\.tinypass\.com\/.+/,
'folha.uol.com.br': /.+\.folha\.uol\.com\.br\/paywall\/js\/.+\/publicidade\.ads\.js/,
'globo.com': /.+\.tinypass\.com\/.+/,
'foreignpolicy.com': /.+\.tinypass\.com\/.+/,
'fortune.com': /.+\.tinypass\.com\/.+/,
'ft.com': /.+\.ft\.com\/__assets\/hashed\/page-kit\/shared\.volatile\..+\.bundle\.js/,
2020-06-18 20:55:18 +02:00
'ftm.nl': /.+\.ftm\.nl\/js\/routing\?/,
2020-04-25 20:41:55 +02:00
'gestion.pe': /gestion\.pe\/pf\/dist\/template\/gestion-noticia.+\.js/,
2020-05-15 16:05:03 +02:00
'globes.co.il': /.+\.tinypass\.com\/.+/,
'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/,
'haaretz.com': /haaretz\.com\/hdc\/web\/js\/minified\/header-scripts-int.js.+/,
2020-06-06 16:46:56 +02:00
'historyextra.com': /.+\.evolok\.net\/.+\/authorize\/.+/,
2020-04-23 21:45:47 +02:00
'ilmessaggero.it': /(utils\.cedsdigital\.it\/js\/PaywallMeter\.js|static\.viralize\.tv\/viralize_player)/,
2020-06-08 16:44:46 +02:00
'independent.ie': /cdn\.flip-pay\.com\/clients\/inm\/flip-pay\.js/,
'inquirer.com': /.+\.tinypass\.com\/.+/,
'irishtimes.com': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/,
2020-06-26 19:56:58 +02:00
'knack.be': /.+\.knack\.be\/js\/responsive\/rmgModal\.js/,
2020-03-21 15:48:04 +01:00
'ladepeche.fr': /.+\.poool\.fr\/.+/,
2020-07-25 09:42:31 +02:00
'lasegunda.com': /segreader\.emol\.cl\/assets\/js\/(vendor\/modal\.js|merPramV\d\.js)/,
'lastampa.it': /.+\.repstatic\.it\/minify\/sites\/lastampa\/.+\/config\.cache\.php\?name=social_js/,
2020-06-17 16:29:36 +02:00
'lc.nl': /.+\.evolok\.net\/.+\/authorize\/.+/,
2020-05-20 17:02:34 +02:00
'lejdd.fr': /.+\.poool\.fr\/.+/,
'leparisien.fr': /.+\.tinypass\.com\/.+/,
'lesechos.fr': /.+\.tinypass\.com\/.+/,
2020-08-21 09:41:41 +02:00
'limesonline.com': /scripts\.repubblica\.it\/pw\/pw\.js.+/,
2020-03-28 18:52:19 +01:00
'livemint.com': /(.+\.livemint\.com\/js\/localWorker\.js|analytics\.htmedia\.in\/analytics-js\/.+\.js)/,
2020-03-25 09:07:43 +01:00
'lopinion.fr': /.+\.poool\.fr\/.+/,
'lrb.co.uk': /.+\.tinypass\.com\/.+/,
2020-08-26 17:18:51 +02:00
'mercuriovalpo.cl': /(.+\.mercuriovalpo\.cl\/impresa\/wp-content\/themes\/papel-digital-2019-desktop\/assets\/(vendor|\d)\.js|pram\.pasedigital\.cl\/API\/User\/Status\?)/,
2020-01-31 15:19:17 +01:00
'modernhealthcare.com': /.+\.tinypass\.com\/.+/,
2020-06-17 16:45:16 +02:00
'nationalgeographic.com': /.+\.blueconic\.net\/.+/,
'nationalreview.com': /.+\.blueconic\.net\/.+/,
2020-03-23 17:59:16 +01:00
'newrepublic.com': /.+\.onecount\.net\/js\/.+/,
2020-06-29 20:00:56 +02:00
'newsweek.com': /.+\.googletagmanager\.com\/gtm\.js/,
'nytimes.com': /(.+meter-svc\.nytimes\.com\/meter\.js.+|.+mwcm\.nyt\.com\/.+\.js)/,
'nzherald.co.nz': /nzherald\.co\.nz\/.+\/headjs\/.+\.js/,
2020-02-01 21:25:33 +01:00
'repubblica.it': /scripts\.repubblica\.it\/pw\/pw\.js.+/,
'science-et-vie.com': /.+\.qiota\.com\/.+/,
2020-05-02 09:04:23 +02:00
'sciencesetavenir.fr': /.+\.poool\.fr\/.+/,
2020-08-21 09:02:30 +02:00
'scmp.com': /.+\.tinypass\.com\/.+/,
'sfchronicle.com': /.+\.blueconic\.net\/.+/,
'sloanreview.mit.edu': /(.+\.tinypass\.com\/.+|.+\.netdna-ssl\.com\/wp-content\/themes\/smr\/assets\/js\/libs\/welcome-ad\.js)/,
'spectator.co.uk': /.+\.tinypass\.com\/.+/,
'spectator.com.au': /.+\.tinypass\.com\/.+/,
2020-08-27 21:16:38 +02:00
'technologyreview.com': /.+\.blueconic\.net\/.+/,
'telegraph.co.uk': /.+\.tinypass\.com\/.+/,
2020-01-30 18:01:37 +01:00
'thedailybeast.com': /.+\.tinypass\.com\/.+/,
'thenation.com': /.+\.tinypass\.com\/.+/,
2020-07-13 07:47:51 +02:00
'valeursactuelles.com': /.+\.qiota\.com\/.+/,
'washingtonpost.com': /.+\.washingtonpost\.com\/dr\/resources\/dist\/washpost\/pwapi-proxy\.min\.js/,
2020-06-15 11:59:34 +02:00
'wsj.com': /cdn\.ampproject\.org\/v\d\/amp-access-.+\.js/
};
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'];
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 = [];
var disabledSites = [];
var defaultSites_domains = Object.values(defaultSites);
var customSites = {};
var customSites_domains = [];
2017-07-08 19:40:29 +02:00
function setDefaultOptions() {
ext_api.storage.sync.set({
sites: defaultSites
}, function() {
ext_api.runtime.openOptionsPage();
});
}
// 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.sync.get({
sites: {},
sites_custom: {}
}, function (items) {
var sites = items.sites;
var sites_custom = items.sites_custom;
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]['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 !== '###');
if (enabledSites.includes('ad.nl'))
2020-04-13 19:11:29 +02:00
enabledSites = enabledSites.concat(ad_region_domains);
if (enabledSites.includes('###_au_comm_media')) {
enabledSites = enabledSites.concat(au_comm_media_domains);
for (let domain of au_comm_media_domains) {
2020-07-07 19:35:28 +02:00
allow_cookies.push(domain);
blockedRegexes[domain] = /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/;
}
2020-08-23 20:50:30 +02:00
} else
disabledSites = disabledSites.concat(au_comm_media_domains);
2020-07-07 19:35:28 +02:00
if (enabledSites.includes('###_au_news_corp')) {
enabledSites = enabledSites.concat(au_news_corp_domains);
for (let domain of au_news_corp_domains) {
allow_cookies.push(domain);
use_google_bot_default.push(domain);
}
2020-08-23 20:50:30 +02:00
use_google_bot = use_google_bot_default.slice();
} else
disabledSites = disabledSites.concat(au_news_corp_domains);
if (enabledSites.includes('###_au_prov_news')) {
enabledSites = enabledSites.concat(au_prov_news_domains);
for (let domain of au_prov_news_domains) {
allow_cookies.push(domain);
}
2020-08-23 20:50:30 +02:00
} else
disabledSites = disabledSites.concat(au_prov_news_domains);
for (let domainVar of enabledSites) {
if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) {
allow_cookies.push(domainVar);
remove_cookies.push(domainVar);
}
}
disableJavascriptOnListedSites();
});
2017-07-08 19:40:29 +02:00
// Listen for changes to options
ext_api.storage.onChanged.addListener(function (changes, namespace) {
for (var 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 !== '###');
if (enabledSites.includes('ad.nl'))
2020-04-13 19:11:29 +02:00
enabledSites = enabledSites.concat(ad_region_domains);
if (enabledSites.includes('###_au_comm_media'))
enabledSites = enabledSites.concat(au_comm_media_domains);
2020-08-23 20:50:30 +02:00
else
disabledSites = disabledSites.concat(au_comm_media_domains);
2020-07-07 19:35:28 +02:00
if (enabledSites.includes('###_au_news_corp'))
enabledSites = enabledSites.concat(au_news_corp_domains);
2020-08-23 20:50:30 +02:00
else
disabledSites = disabledSites.concat(au_news_corp_domains);
if (enabledSites.includes('###_au_prov_news'))
enabledSites = enabledSites.concat(au_prov_news_domains);
2020-08-23 20:50:30 +02:00
else
disabledSites = disabledSites.concat(au_prov_news_domains);
// reset disableJavascriptOnListedSites eventListener
ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites);
ext_api.webRequest.handlerBehaviorChanged();
}
if (key === 'sites_custom') {
var sites_custom = storageChange.newValue;
var sites_custom_old = 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));
chrome.storage.sync.get({
sites: {}
}, function (items) {
var sites = items.sites;
for (var key of sites_custom_added)
sites[key] = sites_custom[key].domain;
for (var key of sites_custom_removed)
delete sites[key];
chrome.storage.sync.set({
sites: sites
}, function () {
true;
});
});
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);
}
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);
}
}
// 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"]
);
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) {
let headers = details.requestHeaders;
headers.forEach(function (header, i) {
if (header.name.toLowerCase() == 'user-agent')
header.value = faz_uaMobile;
});
if (!details.originUrl && details.type == "xmlhttprequest" ||
details.initiator == "https://www.faz.net" && details.type == "xmlhttprequest")
return { requestHeaders: headers };
}, {
urls: ["*://m.faz.net/*"]
},
["blocking", "requestHeaders"]);
2020-07-15 19:12:20 +02:00
var block_js_default = ["*://cdn.tinypass.com/*", "*://*.piano.io/*", "*://*.poool.fr/*", "*://*.blueconic.net/*", "*://*.evolok.net/*", "*://js.matheranalytics.com/*", "*://*.onecount.net/*", "*://*.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) {
if (!isSiteEnabled(details)) {
return;
}
return {
cancel: true
};
}, {
urls: block_js,
2020-07-15 19:12:20 +02:00
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) {
var requestHeaders = details.requestHeaders;
var header_referer = '';
for (var n in requestHeaders) {
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', header_referer) && isSiteEnabled({url: 'https://medium.com'}));
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-06-14 18:09:59 +02:00
// remove cookies Discover Magazine
2020-06-14 18:37:06 +02:00
if (matchUrlDomain('ctfassets.net', details.url) && matchUrlDomain('discovermagazine.com', header_referer) && isSiteEnabled({url: 'https://www.discovermagazine.com'})) {
2020-06-14 18:09:59 +02:00
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 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);
2020-07-15 19:12:20 +02:00
if (domain_blockjs_ext && !matchUrlDomain(domain_blockjs_ext, details.url) && details.url.match(/(\.js$|\.js\?|\/json\?)/) && 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);
if (domain && details.url.match(blockedRegexes[domain]) && isSiteEnabled({url: header_referer})) {
2020-06-09 11:57:07 +02:00
return { cancel: true };
2017-07-08 19:40:29 +02:00
}
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}));
if (!isSiteEnabled(details) && !(inkl_site)) {
return;
2018-11-24 23:10:21 +01:00
}
// 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);
2020-07-15 19:12:20 +02:00
if (domain_blockjs && matchUrlDomain(domain_blockjs, details.url) && details.url.match(/(\.js$|\.js\?|\/json\?)/)) {
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 referer exists, set it to google
requestHeaders = requestHeaders.map(function (requestHeader) {
2017-07-08 19:40:29 +02:00
if (requestHeader.name === 'Referer') {
if (details.url.includes("cooking.nytimes.com/api/v1/users/bootstrap")) {
// 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';
2020-06-21 14:32:38 +02:00
} else if (matchUrlDomain(['clarin.com', 'fd.nl'], details.url)) {
requestHeader.value = 'https://www.facebook.com/';
} else {
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) {
2020-06-21 14:32:38 +02:00
if (matchUrlDomain(['clarin.com', 'fd.nl'], details.url)) {
2017-07-08 19:40:29 +02:00
requestHeaders.push({
name: 'Referer',
value: 'https://www.facebook.com/'
});
} 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",
"value": useUserAgentMobile ? userAgentMobile : userAgentDesktop
})
requestHeaders.push({
"name": "X-Forwarded-For",
"value": "66.249.66.1"
})
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-08-26 17:18:51 +02:00
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}) || medium_custom_domain) {
// run contentScript inside tab
2020-08-26 17:18:51 +02:00
ext_api.tabs.executeScript({
file: 'contentScript.js',
runAt: 'document_start'
2020-08-26 17:18:51 +02:00
}, function (res) {
if (ext_api.runtime.lastError || res[0]) {
return;
}
});
2017-07-08 19:40:29 +02:00
}
2020-08-26 17:18:51 +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); });
function updateBadge (activeTab) {
if (!activeTab) { return; }
let badgeText = '';
let color = 'red';
let currentUrl = activeTab.url;
if (currentUrl) {
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
if (isSiteEnabled({url: currentUrl})) {
badgeText = 'ON';
color = 'red';
} else if (matchUrlDomain(enabledSites, currentUrl)) {
badgeText = 'ON-';
color = 'orange';
} else if (matchUrlDomain(disabledSites, currentUrl)) {
badgeText = 'OFF';
color = 'blue';
}
}
ext_api.browserAction.setBadgeBackgroundColor({color: color});
ext_api.browserAction.setBadgeText({text: badgeText});
}
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;
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
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) {
let added_site = [];
let removed_site = [];
if (enabledSites.includes(domain))
removed_site.push(site_title);
else
added_site.push(site_title);
chrome.storage.sync.get({
sites: {}
}, function (items) {
var sites = items.sites;
for (var key of added_site)
sites[key] = domain;
for (var key of removed_site)
delete sites[key];
chrome.storage.sync.set({
sites: sites
}, function () {
true;
});
});
}
}
});
}
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);
if (!domainVar || !enabledSites.includes(domainVar))
return;
ext_api.cookies.getAll({
domain: domainVar
}, function (cookies) {
for (let cookie of cookies) {
var cookie_domain = cookie.domain;
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
}
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 isSiteEnabled(details) {
var enabledSite = matchUrlDomain(enabledSites, details.url);
2019-02-11 00:43:12 +01:00
if (enabledSite in restrictions) {
return restrictions[enabledSite].test(details.url);
2019-02-11 00:43:12 +01:00
}
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];
}