2020-01-15 17:58:10 +00:00
|
|
|
/* Please respect alphabetical order when adding a site in any list */
|
|
|
|
|
2017-07-08 17:40:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-01-14 19:02:04 +00:00
|
|
|
// Cookies from this list are blocked by default (obsolete)
|
|
|
|
// defaultSites are loaded from sites(_custom).json at installation extension
|
|
|
|
var defaultSites = {};
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2018-01-31 05:08:11 +00:00
|
|
|
const restrictions = {
|
2019-12-16 19:24:04 +00:00
|
|
|
'barrons.com': /.+barrons\.com\/articles\/.+/,
|
|
|
|
'prime.economictimes.indiatimes.com': /.+prime\.economictimes\.indiatimes\.com\/news\/[0-9]{8}\/.+/,
|
2020-01-29 17:26:03 +00:00
|
|
|
'wsj.com': /(.+wsj\.com\/articles\/.+|.+blogs\.wsj\.com\/.+)/
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't remove cookies before page load
|
2020-01-28 22:06:25 +00:00
|
|
|
// allow_cookies are completed with domains in sites(_custom).json (default allow/remove_cookies)
|
|
|
|
var allow_cookies = [
|
|
|
|
'adelaidenow.com.au',
|
2020-01-05 15:19:01 +00:00
|
|
|
'barrons.com',
|
2020-01-28 22:06:25 +00:00
|
|
|
'bostonglobe.com',
|
|
|
|
'cairnspost.com.au',
|
2020-02-16 15:35:17 +00:00
|
|
|
'clarin.com',
|
2020-01-28 22:06:25 +00:00
|
|
|
'couriermail.com.au',
|
|
|
|
'dailytelegraph.com.au',
|
|
|
|
'dn.se',
|
2020-02-12 17:55:28 +00:00
|
|
|
'dvhn.nl',
|
2020-02-09 14:51:34 +00:00
|
|
|
'elmercurio.com',
|
2020-02-03 17:56:37 +00:00
|
|
|
'fd.nl',
|
2020-01-28 22:06:25 +00:00
|
|
|
'folha.uol.com.br',
|
|
|
|
'goldcoastbulletin.com.au',
|
2020-01-05 15:19:01 +00:00
|
|
|
'haaretz.co.il',
|
|
|
|
'haaretz.com',
|
2020-01-11 13:05:12 +00:00
|
|
|
'handelsblatt.com',
|
2020-01-28 22:06:25 +00:00
|
|
|
'heraldsun.com.au',
|
|
|
|
'kleinezeitung.at',
|
2019-10-23 11:06:43 +00:00
|
|
|
'lemonde.fr',
|
2020-02-12 17:55:28 +00:00
|
|
|
'lc.nl',
|
2020-01-25 13:56:18 +00:00
|
|
|
'lrb.co.uk',
|
2020-01-28 22:06:25 +00:00
|
|
|
'mexiconewsdaily.com',
|
2020-01-31 14:19:17 +00:00
|
|
|
'modernhealthcare.com',
|
2020-01-31 14:01:53 +00:00
|
|
|
'nationalreview.com',
|
2020-01-14 19:02:04 +00:00
|
|
|
'nknews.org',
|
2020-01-28 22:06:25 +00:00
|
|
|
'ntnews.com.au',
|
2019-10-23 11:06:43 +00:00
|
|
|
'nytimes.com',
|
2019-10-14 12:52:27 +00:00
|
|
|
'parool.nl',
|
2020-01-14 19:02:04 +00:00
|
|
|
'prime.economictimes.indiatimes.com',
|
2020-01-05 15:19:01 +00:00
|
|
|
'quora.com',
|
2020-01-05 16:41:06 +00:00
|
|
|
'scribd.com',
|
2020-01-14 19:02:04 +00:00
|
|
|
'techinasia.com',
|
2020-01-05 15:19:01 +00:00
|
|
|
'telegraph.co.uk',
|
2020-01-28 22:06:25 +00:00
|
|
|
'the-american-interest.com',
|
2020-01-05 12:02:44 +00:00
|
|
|
'theathletic.com',
|
2019-10-23 11:06:43 +00:00
|
|
|
'theaustralian.com.au',
|
2020-01-05 15:19:01 +00:00
|
|
|
'themarker.com',
|
2019-10-28 23:25:53 +00:00
|
|
|
'themercury.com.au',
|
2020-01-05 15:19:01 +00:00
|
|
|
'thetimes.co.uk',
|
2020-01-28 22:06:25 +00:00
|
|
|
'townsvillebulletin.com.au',
|
2019-10-14 12:52:27 +00:00
|
|
|
'trouw.nl',
|
2019-10-23 11:06:43 +00:00
|
|
|
'volkskrant.nl',
|
2020-01-28 22:06:25 +00:00
|
|
|
'weeklytimesnow.com.au',
|
2020-01-31 13:17:59 +00:00
|
|
|
'worldpoliticsreview.com',
|
2019-10-23 11:06:43 +00:00
|
|
|
'wsj.com',
|
2017-07-08 17:40:29 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
// Removes cookies after page load
|
2020-01-14 19:02:04 +00:00
|
|
|
// remove_cookies are completed with domains of sites(_custom).json (default allow/remove_cookies)
|
|
|
|
var remove_cookies = [
|
2017-07-08 17:40:29 +00:00
|
|
|
]
|
|
|
|
|
2019-10-25 13:00:08 +00:00
|
|
|
// select specific cookie(s) to hold from remove_cookies domains
|
|
|
|
const remove_cookies_select_hold = {
|
2020-01-13 21:23:03 +00:00
|
|
|
'newstatesman.com': ['STYXKEY_nsversion'],
|
|
|
|
'qz.com': ['gdpr'],
|
|
|
|
'washingtonpost.com': ['wp_gdpr']
|
2019-10-25 13:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// select only specific cookie(s) to drop from remove_cookies domains
|
|
|
|
const remove_cookies_select_drop = {
|
2019-11-17 19:26:29 +00:00
|
|
|
'ad.nl': ['temptationTrackingId'],
|
2019-12-20 18:13:21 +00:00
|
|
|
'caixinglobal.com': ['CAIXINGLB_LOGIN_UUID'],
|
2019-11-17 19:26:29 +00:00
|
|
|
'demorgen.be': ['TID_ID'],
|
2020-01-28 22:06:25 +00:00
|
|
|
'dn.se': ['randomSplusId'],
|
2019-11-17 19:26:29 +00:00
|
|
|
'ed.nl': ['temptationTrackingId'],
|
2020-01-28 22:06:25 +00:00
|
|
|
'nrc.nl': ['counter'],
|
|
|
|
'theatlantic.com': ['articleViews']
|
2019-10-25 13:00:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 20:44:03 +00:00
|
|
|
// Override User-Agent with Googlebot
|
|
|
|
const use_google_bot = [
|
2020-01-28 22:06:25 +00:00
|
|
|
'adelaidenow.com.au',
|
2019-10-22 12:37:02 +00:00
|
|
|
'barrons.com',
|
2020-01-28 22:06:25 +00:00
|
|
|
'cairnspost.com.au',
|
|
|
|
'couriermail.com.au',
|
|
|
|
'dailytelegraph.com.au',
|
|
|
|
'dn.se',
|
2020-02-03 17:56:37 +00:00
|
|
|
'fd.nl',
|
2020-01-28 22:06:25 +00:00
|
|
|
'goldcoastbulletin.com.au',
|
2020-01-05 12:02:44 +00:00
|
|
|
'haaretz.co.il',
|
|
|
|
'haaretz.com',
|
2020-01-11 13:05:12 +00:00
|
|
|
'handelsblatt.com',
|
2020-01-28 22:06:25 +00:00
|
|
|
'heraldsun.com.au',
|
2019-11-02 11:07:01 +00:00
|
|
|
'lemonde.fr',
|
2020-01-28 22:06:25 +00:00
|
|
|
'mexiconewsdaily.com',
|
2020-01-05 12:02:44 +00:00
|
|
|
'nknews.org',
|
2020-01-28 22:06:25 +00:00
|
|
|
'ntnews.com.au',
|
2020-01-05 12:02:44 +00:00
|
|
|
'prime.economictimes.indiatimes.com',
|
2019-10-29 18:27:54 +00:00
|
|
|
'quora.com',
|
2019-05-12 20:44:03 +00:00
|
|
|
'telegraph.co.uk',
|
2020-01-05 12:02:44 +00:00
|
|
|
'theathletic.com',
|
2019-10-22 12:37:02 +00:00
|
|
|
'theaustralian.com.au',
|
2020-01-05 12:02:44 +00:00
|
|
|
'themarker.com',
|
2019-10-28 23:25:53 +00:00
|
|
|
'themercury.com.au',
|
2019-05-12 20:44:03 +00:00
|
|
|
'thetimes.co.uk',
|
2020-01-28 22:06:25 +00:00
|
|
|
'townsvillebulletin.com.au',
|
|
|
|
'weeklytimesnow.com.au',
|
2020-01-31 13:17:59 +00:00
|
|
|
'worldpoliticsreview.com',
|
2019-12-07 21:26:58 +00:00
|
|
|
'wsj.com',
|
2019-05-12 20:44:03 +00:00
|
|
|
]
|
2020-01-28 22:06:25 +00:00
|
|
|
// block paywall-scripts individually
|
|
|
|
var blockedRegexes = {
|
|
|
|
'adweek.com': /.+\.lightboxcdn\.com\/.+/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'afr.com': /afr\.com\/assets\/vendorsReactRedux_client.+\.js/,
|
2020-02-14 12:08:15 +00:00
|
|
|
'americanbanker.com': /.+\.tinypass\.com\/.+/,
|
2020-02-22 12:21:18 +00:00
|
|
|
'bloomberg.com': /.+\.tinypass\.com\/.+/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'bostonglobe.com': /meter\.bostonglobe\.com\/js\/.+/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'businessinsider.com': /(.+\.tinypass\.com\/.+|cdn\.onesignal\.com\/sdks\/.+\.js)/,
|
|
|
|
'challenges.fr': /.+\.poool\.fr\/.+/,
|
|
|
|
'chicagobusiness.com': /.+\.tinypass\.com\/.+/,
|
2019-11-27 18:23:00 +00:00
|
|
|
'chicagotribune.com': /.+:\/\/.+\.tribdss\.com\//,
|
2020-02-16 15:54:57 +00:00
|
|
|
'corriere.it': /.+\.rcsobjects\.it\/rcs_cpmt\/.+\/corriere_ct\.js/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'digiday.com': /.+\.tinypass\.com\/.+/,
|
2020-01-09 10:44:01 +00:00
|
|
|
'economist.com': /(.+\.tinypass\.com\/.+|economist\.com\/_next\/static\/runtime\/main.+\.js)/,
|
2020-02-09 14:51:34 +00:00
|
|
|
'elmercurio.com': /merreader\.emol\.cl\/assets\/js\/vendor\/modal\.js/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'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\/.+/,
|
2019-12-08 18:34:26 +00:00
|
|
|
'foreignpolicy.com': /.+\.tinypass\.com\/.+/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'fortune.com': /.+\.tinypass\.com\/.+/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'haaretz.com': /haaretz\.com\/hdc\/web\/js\/minified\/header-scripts-int.js.+/,
|
2019-12-13 13:14:55 +00:00
|
|
|
'inquirer.com': /.+\.tinypass\.com\/.+/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'lastampa.it': /.+\.repstatic\.it\/minify\/sites\/lastampa\/.+\/config\.cache\.php\?name=social_js/,
|
|
|
|
'lejdd.fr': /.+\.swisspay\.ch\/.+/,
|
2020-01-07 21:26:47 +00:00
|
|
|
'leparisien.fr': /.+\.tinypass\.com\/.+/,
|
2020-01-08 22:21:21 +00:00
|
|
|
'lesechos.fr': /.+\.tinypass\.com\/.+/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'lrb.co.uk': /.+\.tinypass\.com\/.+/,
|
2020-01-31 14:19:17 +00:00
|
|
|
'modernhealthcare.com': /.+\.tinypass\.com\/.+/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'newcastleherald.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'nytimes.com': /(.+meter-svc\.nytimes\.com\/meter\.js.+|.+mwcm\.nyt\.com\/.+\.js)/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'nzherald.co.nz': /nzherald\.co\.nz\/.+\/headjs\/.+\.js/,
|
2020-02-01 20:25:33 +00:00
|
|
|
'repubblica.it': /scripts\.repubblica\.it\/pw\/pw\.js.+/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'sloanreview.mit.edu': /.+\.tinypass\.com\/.+/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'spectator.co.uk': /.+\.tinypass\.com\/.+/,
|
2020-02-02 17:20:33 +00:00
|
|
|
'spectator.com.au': /.+\.tinypass\.com\/.+/,
|
2020-02-14 12:08:15 +00:00
|
|
|
'telegraph.co.uk': /.+\.tinypass\.com\/.+/,
|
2020-02-03 16:48:55 +00:00
|
|
|
'theadvocate.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/,
|
2020-02-02 17:20:33 +00:00
|
|
|
'thecourier.com.au': /.+cdn-au\.piano\.io\/api\/tinypass.+\.js/,
|
2020-01-30 17:01:37 +00:00
|
|
|
'thedailybeast.com': /.+\.tinypass\.com\/.+/,
|
2020-01-15 17:58:10 +00:00
|
|
|
'theglobeandmail.com': /theglobeandmail\.com\/pb\/resources\/scripts\/build\/chunk-bootstraps\/.+\.js/,
|
2020-02-20 20:11:36 +00:00
|
|
|
'thenation.com': /.+\.tinypass\.com\/.+/,
|
2020-01-28 22:06:25 +00:00
|
|
|
'valeursactuelles.com': /.+\.poool\.fr\/.+/
|
2019-11-27 18:23:00 +00:00
|
|
|
};
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2019-04-06 23:34:30 +00: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 17:40:29 +00:00
|
|
|
var enabledSites = [];
|
|
|
|
|
2020-01-28 22:06:25 +00:00
|
|
|
function setDefaultOptions() {
|
|
|
|
browser.storage.sync.set({
|
|
|
|
sites: defaultSites
|
|
|
|
}, function() {
|
|
|
|
browser.runtime.openOptionsPage();
|
|
|
|
});
|
|
|
|
}
|
2020-01-15 17:58:10 +00:00
|
|
|
// Get the enabled sites (from local storage) & add to allow/remove_cookies (if not already in one of these arrays)
|
2020-01-25 13:56:18 +00:00
|
|
|
browser.storage.sync.get({
|
2017-07-08 17:40:29 +00:00
|
|
|
sites: {}
|
|
|
|
}, function(items) {
|
|
|
|
var sites = items.sites;
|
|
|
|
enabledSites = Object.keys(items.sites).map(function(key) {
|
|
|
|
return items.sites[key];
|
|
|
|
});
|
2020-01-15 17:58:10 +00:00
|
|
|
enabledSites = enabledSites.filter(function(el) { return (el !== '###'); });
|
|
|
|
for (var domainIndex in enabledSites) {
|
|
|
|
var domainVar = enabledSites[domainIndex];
|
2020-01-14 19:02:04 +00:00
|
|
|
if (!allow_cookies.includes(domainVar) && !remove_cookies.includes(domainVar)) {
|
|
|
|
allow_cookies.push(domainVar);
|
|
|
|
remove_cookies.push(domainVar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-08 17:40:29 +00:00
|
|
|
// 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
|
2020-01-14 19:02:04 +00:00
|
|
|
browser.runtime.onInstalled.addListener(function (details) {
|
2017-07-08 17:40:29 +00:00
|
|
|
if (details.reason == "install") {
|
2020-01-14 19:02:04 +00:00
|
|
|
const url_sites = browser.runtime.getURL('sites.json');
|
|
|
|
fetch(url_sites)
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
|
|
|
var defaultSites_merge = {...defaultSites, ...json};
|
|
|
|
defaultSites = defaultSites_merge;
|
|
|
|
// add custom sites
|
|
|
|
const url_sites_custom = 'https://raw.githubusercontent.com/magnolia1234/bypass-paywalls-firefox-clean/master/sites_custom.json';
|
|
|
|
fetch(url_sites_custom)
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
|
|
|
var defaultSites_merge = {...defaultSites, ...json};
|
|
|
|
defaultSites = defaultSites_merge;
|
|
|
|
setDefaultOptions();
|
|
|
|
})
|
|
|
|
} else { setDefaultOptions(); }
|
|
|
|
} );
|
|
|
|
})
|
|
|
|
} else { setDefaultOptions(); }
|
|
|
|
} );
|
2017-07-08 17:40:29 +00:00
|
|
|
} else if (details.reason == "update") {
|
|
|
|
// User updated extension
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-28 22:06:25 +00:00
|
|
|
// Disable javascript for these sites/general paywall-scripts
|
2020-01-11 20:16:10 +00:00
|
|
|
browser.webRequest.onBeforeRequest.addListener(function(details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
2019-05-12 23:31:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-21 13:50:50 +00:00
|
|
|
return {cancel: true};
|
2019-05-12 23:31:18 +00:00
|
|
|
},
|
|
|
|
{
|
2020-01-28 22:06:25 +00:00
|
|
|
urls: ["*://*.tinypass.com/*", "*://*.poool.fr/*", "*://*.piano.io/*", "*://*.outbrain.com/*"],
|
2019-05-12 23:31:18 +00:00
|
|
|
types: ["script"]
|
|
|
|
},
|
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2019-02-10 23:43:12 +00:00
|
|
|
browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
2019-11-27 18:23:00 +00: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;
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 18:15:37 +00:00
|
|
|
|
|
|
|
// remove cookies for sites medium platform (mainfest.json needs in permissions: <all_urls>)
|
|
|
|
if (isSiteEnabled({url: '.medium.com'}) && details.url.indexOf('cdn-client.medium.com') !== -1 && header_referer.indexOf('.medium.com') === -1) {
|
|
|
|
var domainVar = new URL(header_referer).hostname;
|
|
|
|
browser.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
for (var i=0; i<cookies.length; i++) {
|
|
|
|
browser.cookies.remove({url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path, name: cookies[i].name});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-11-27 18:23:00 +00:00
|
|
|
|
2020-01-28 22:06:25 +00:00
|
|
|
// remove cookies for regional ADR sites of ad.nl (mainfest.json needs in permissions: <all_urls>)
|
|
|
|
if (isSiteEnabled({url: '.ad.nl'})) {
|
|
|
|
const ad_region_domains = ['bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl'];
|
|
|
|
var domainVar = new URL(details.url).hostname.replace('www.', '');
|
|
|
|
if (ad_region_domains.includes(domainVar)) {
|
|
|
|
browser.cookies.getAll({domain: domainVar}, function(cookies) {
|
|
|
|
for (var i=0; i<cookies.length; i++) {
|
|
|
|
if (remove_cookies_select_drop['ad.nl'].includes(cookies[i].name)){
|
|
|
|
browser.cookies.remove({url: (cookies[i].secure ? "https://" : "http://") + cookies[i].domain + cookies[i].path, name: cookies[i].name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-11-27 18:23:00 +00:00
|
|
|
// check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
|
|
|
|
for (var domain in blockedRegexes) {
|
2019-12-10 18:02:16 +00:00
|
|
|
if ((isSiteEnabled({url: '.'+ domain}) || isSiteEnabled({url: header_referer})) && details.url.match(blockedRegexes[domain])) {
|
2019-11-27 18:23:00 +00:00
|
|
|
if (details.url.indexOf(domain) !== -1 || header_referer.indexOf(domain) !== -1) {
|
2019-12-10 18:02:16 +00: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)) {
|
2020-01-28 22:06:25 +00:00
|
|
|
browser.webRequest.handlerBehaviorChanged(function () {});
|
2019-12-10 18:02:16 +00:00
|
|
|
break;
|
2020-01-11 20:16:10 +00:00
|
|
|
} else if (header_referer.indexOf('theglobeandmail.com') !== -1 && !(header_referer.indexOf('/article-') !== -1)) {
|
|
|
|
browser.webRequest.handlerBehaviorChanged(function () {});
|
|
|
|
break;
|
2019-12-10 18:02:16 +00:00
|
|
|
}
|
2019-11-27 18:23:00 +00:00
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 18:23:00 +00:00
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
2018-11-24 22:10:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 17:40:29 +00:00
|
|
|
var tabId = details.tabId;
|
2019-11-27 18:23:00 +00:00
|
|
|
|
2019-04-06 23:34:30 +00:00
|
|
|
var useUserAgentMobile = false;
|
2017-07-08 17:40:29 +00:00
|
|
|
var setReferer = false;
|
|
|
|
|
|
|
|
// if referer exists, set it to google
|
2019-05-12 20:44:03 +00:00
|
|
|
requestHeaders = requestHeaders.map(function(requestHeader) {
|
2017-07-08 17:40:29 +00:00
|
|
|
if (requestHeader.name === 'Referer') {
|
2019-02-13 09:33:45 +00: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';
|
2020-02-16 15:35:17 +00:00
|
|
|
} else if (details.url.indexOf("clarin.com") !== -1 || details.url.indexOf("kleinezeitung.at") !== -1) {
|
2019-02-13 09:33:45 +00:00
|
|
|
requestHeader.value = 'https://www.facebook.com/';
|
|
|
|
} else {
|
|
|
|
requestHeader.value = 'https://www.google.com/';
|
|
|
|
}
|
|
|
|
setReferer = true;
|
|
|
|
}
|
2019-04-06 23:34:30 +00:00
|
|
|
if (requestHeader.name === 'User-Agent') {
|
|
|
|
useUserAgentMobile = requestHeader.value.toLowerCase().includes("mobile");
|
|
|
|
}
|
|
|
|
|
2019-02-13 09:33:45 +00:00
|
|
|
return requestHeader;
|
|
|
|
});
|
2017-07-08 17:40:29 +00:00
|
|
|
|
|
|
|
// otherwise add it
|
|
|
|
if (!setReferer) {
|
2020-02-16 15:35:17 +00:00
|
|
|
if (details.url.indexOf("clarin.com") !== -1 || details.url.indexOf("kleinezeitung.at") !== -1) {
|
2017-07-08 17:40:29 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
|
|
|
value: 'https://www.facebook.com/'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
|
|
|
value: 'https://www.google.com/'
|
|
|
|
});
|
|
|
|
}
|
2019-04-06 23:34:30 +00:00
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2019-05-12 20:44:03 +00:00
|
|
|
// override User-Agent to use Googlebot
|
|
|
|
var useGoogleBot = use_google_bot.filter(function(item) {
|
2019-09-21 13:50:50 +00:00
|
|
|
return typeof item == 'string' && details.url.indexOf(item) > -1;
|
2019-05-12 20:44:03 +00:00
|
|
|
}).length > 0;
|
|
|
|
|
|
|
|
if (useGoogleBot) {
|
2019-04-06 23:34:30 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "User-Agent",
|
|
|
|
"value": useUserAgentMobile ? userAgentMobile : userAgentDesktop
|
|
|
|
})
|
2019-05-12 20:44:03 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "X-Forwarded-For",
|
|
|
|
"value": "66.249.66.1"
|
|
|
|
})
|
2017-07-08 17:40:29 +00: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 04:28:29 +00: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 13:00:08 +00:00
|
|
|
|
|
|
|
var cookie_domain = cookies[i].domain;
|
2019-11-17 19:26:29 +00:00
|
|
|
var rc_domain = cookie_domain.replace(/^(\.?www\.|\.)/, '');
|
2019-10-25 13:00:08 +00:00
|
|
|
// hold specific cookie(s) from remove_cookies domains
|
2019-11-17 19:26:29 +00:00
|
|
|
if ((rc_domain in remove_cookies_select_hold) && remove_cookies_select_hold[rc_domain].includes(cookies[i].name)){
|
2019-10-25 13:00:08 +00:00
|
|
|
continue; // don't remove specific cookie
|
|
|
|
}
|
|
|
|
// drop only specific cookie(s) from remove_cookies domains
|
2019-11-17 19:26:29 +00:00
|
|
|
if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookies[i].name))){
|
2019-10-25 13:00:08 +00:00
|
|
|
continue; // only remove specific cookie
|
|
|
|
}
|
2018-10-19 04:28:29 +00:00
|
|
|
browser.cookies.remove(cookie);
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
urls: ["<all_urls>"]
|
2018-08-28 23:15:23 +00:00
|
|
|
});
|
2019-02-10 23:43:12 +00:00
|
|
|
|
|
|
|
function isSiteEnabled(details) {
|
|
|
|
var isEnabled = enabledSites.some(function(enabledSite) {
|
2019-12-13 12:57:04 +00:00
|
|
|
var useSite = (details.url.indexOf("." + enabledSite) !== -1 || details.url.indexOf("/" + enabledSite) !== -1);
|
2019-02-10 23:43:12 +00:00
|
|
|
if (enabledSite in restrictions) {
|
2019-12-16 19:24:04 +00:00
|
|
|
return useSite && details.url.match(restrictions[enabledSite]);
|
2019-02-10 23:43:12 +00: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, ' '));
|
|
|
|
}
|
2020-01-28 22:06:25 +00:00
|
|
|
|
|
|
|
function stripQueryStringAndHashFromPath(url) {
|
|
|
|
return url.split("?")[0].split("#")[0];
|
|
|
|
}
|