Fix Economist (only block external paywall-script)

Includes new option to block external scripts on referring (enabled) domain.
This commit is contained in:
magnolia1234 2019-11-27 19:23:00 +01:00 committed by GitHub
parent 324fa0bc44
commit 4cda414dc3
4 changed files with 39 additions and 43 deletions

View file

@ -179,7 +179,6 @@ const remove_cookies = [
// select specific cookie(s) to hold from remove_cookies domains // select specific cookie(s) to hold from remove_cookies domains
const remove_cookies_select_hold = { const remove_cookies_select_hold = {
'nrc.nl': ['nmt_closed_cookiebar'],
'washingtonpost.com': ['wp_gdpr'], 'washingtonpost.com': ['wp_gdpr'],
'wsj.com': ['wsjregion'] 'wsj.com': ['wsjregion']
} }
@ -214,12 +213,14 @@ function setDefaultOptions() {
}); });
} }
const blockedRegexes = [ // to block external script also add domain to manifest.json (permissions)
/.+:\/\/.+\.tribdss\.com\//, const blockedRegexes = {
/thenation\.com\/.+\/paywall-script\.php/, 'chicagotribune.com': /.+:\/\/.+\.tribdss\.com\//,
/haaretz\.co\.il\/htz\/js\/inter\.js/, 'thenation.com': /thenation\.com\/.+\/paywall-script\.php/,
/nzherald\.co\.nz\/.+\/headjs\/.+\.js/ 'haaretz.co.il': /haaretz\.co\.il\/htz\/js\/inter\.js/,
]; 'nzherald.co.nz': /nzherald\.co\.nz\/.+\/headjs\/.+\.js/,
'economist.com': /.+\.tinypass\.com\/.+/
};
const userAgentDesktop = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" 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)" const userAgentMobile = "Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)"
@ -259,31 +260,6 @@ browser.runtime.onInstalled.addListener(function(details) {
} }
}); });
/**
// WSJ bypass
browser.webRequest.onBeforeSendHeaders.addListener(function(details) {
if (!isSiteEnabled(details) || details.url.indexOf("mod=rsswn") !== -1 || details.url.indexOf("/print-edition/") !== -1) {
return;
}
var param;
var updatedUrl;
param = getParameterByName("mod", details.url);
if (param === null) {
updatedUrl = stripQueryStringAndHashFromPath(details.url);
updatedUrl += "?mod=rsswn";
} else {
updatedUrl = details.url.replace(param, "rsswn");
}
return { redirectUrl: updatedUrl};
},
{urls:["*://*.wsj.com/*"], types:["main_frame"]},
["blocking"]
);
**/
// Disable javascript for these sites // Disable javascript for these sites
chrome.webRequest.onBeforeRequest.addListener(function(details) { chrome.webRequest.onBeforeRequest.addListener(function(details) {
if (!isSiteEnabled(details) || details.url.indexOf("mod=rsswn") !== -1) { if (!isSiteEnabled(details) || details.url.indexOf("mod=rsswn") !== -1) {
@ -292,22 +268,36 @@ chrome.webRequest.onBeforeRequest.addListener(function(details) {
return {cancel: true}; return {cancel: true};
}, },
{ {
urls: ["*://*.theglobeandmail.com/*", "*://*.economist.com/*", "*://*.thestar.com/*", "*://*.newstatesman.com/*", "*://*.bostonglobe.com/*", "*://*.afr.com/*"], urls: ["*://*.theglobeandmail.com/*", "*://*.thestar.com/*", "*://*.newstatesman.com/*", "*://*.bostonglobe.com/*", "*://*.afr.com/*"],
types: ["script"] types: ["script"]
}, },
["blocking"] ["blocking"]
); );
browser.webRequest.onBeforeSendHeaders.addListener(function(details) { browser.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;
}
}
// check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
for (var domain in blockedRegexes) {
if (isSiteEnabled({url: '.'+ domain}) && details.url.match(blockedRegexes[domain])) {
if (details.url.indexOf(domain) !== -1 || header_referer.indexOf(domain) !== -1) {
return { cancel: true };
}
}
}
if (!isSiteEnabled(details)) { if (!isSiteEnabled(details)) {
return; return;
} }
if (blockedRegexes.some(function(regex) { return regex.test(details.url); })) {
return { cancel: true };
}
var requestHeaders = details.requestHeaders;
var tabId = details.tabId; var tabId = details.tabId;
var useUserAgentMobile = false; var useUserAgentMobile = false;
@ -423,7 +413,6 @@ browser.webRequest.onCompleted.addListener(function(details) {
if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookies[i].name))){ if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookies[i].name))){
continue; // only remove specific cookie continue; // only remove specific cookie
} }
browser.cookies.remove(cookie); browser.cookies.remove(cookie);
} }
}); });

View file

@ -171,6 +171,11 @@ if (window.location.href.indexOf("caixinglobal.com") !== -1) {
} }
} }
if (window.location.href.indexOf("economist.com") !== -1) {
const wrapper = document.getElementById('bottom-page-wrapper');
removeDOMElement(wrapper);
}
function removeDOMElement(...elements) { function removeDOMElement(...elements) {
for (let element of elements) { for (let element of elements) {
if (element) element.remove(); if (element) element.remove();

View file

@ -20,7 +20,8 @@
"*://*.telegraaf.nl/*", "*://*.telegraaf.nl/*",
"*://*.trouw.nl/*", "*://*.trouw.nl/*",
"*://*.volkskrant.nl/*", "*://*.volkskrant.nl/*",
"*://*.washingtonpost.com/*" "*://*.washingtonpost.com/*",
"*://*.economist.com/*"
], ],
"js": ["contentScript.js"] "js": ["contentScript.js"]
} }
@ -145,7 +146,8 @@
"*://*.lemonde.fr/*", "*://*.lemonde.fr/*",
"*://*.scientificamerican.com/*", "*://*.scientificamerican.com/*",
"*://*.thehindu.com/*", "*://*.thehindu.com/*",
"*://*.demorgen.be/*" "*://*.demorgen.be/*",
"*://*.tinypass.com/*"
], ],
"version": "1.6.2" "version": "1.6.2"
} }

View file

@ -17,7 +17,7 @@ var defaultSites = {
'De Groene Amsterdammer': 'groene.nl', 'De Groene Amsterdammer': 'groene.nl',
'De Tijd': 'tijd.be', 'De Tijd': 'tijd.be',
'de Volkskrant': 'volkskrant.nl', 'de Volkskrant': 'volkskrant.nl',
'The Economist (javascript disabled)': 'economist.com', 'The Economist': 'economist.com',
'Eindhovens Dagblad': 'ed.nl', 'Eindhovens Dagblad': 'ed.nl',
'Examiner': 'examiner.com.au', 'Examiner': 'examiner.com.au',
'Financial Times': 'ft.com', 'Financial Times': 'ft.com',