From d91c9098894269106906940101a8c047d76f7fc9 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Tue, 25 Jan 2022 18:15:31 +0100 Subject: [PATCH] Fix The West Australian (regional) --- README.md | 2 +- background.js | 79 +++++++++++++++++++++++++++++++----------------- changelog.txt | 1 + contentScript.js | 4 +-- manifest.json | 2 +- sites.js | 2 +- 6 files changed, 57 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index a64228c..68a0027 100644 --- a/README.md +++ b/README.md @@ -559,7 +559,7 @@ Grouped in options:\ [The Saturday Paper](https://www.thesaturdaypaper.com.au) - [The Spectator Australia](https://www.spectator.com.au) - [The Sydney Morning Herald](https://www.smh.com.au) - -[The West Australian (+ regional)](https://thewest.com.au) - +[The West Australian (+ regional/opt-in to custom sites)](https://thewest.com.au) - [WAtoday](https://www.watoday.com.au) Grouped in options:\ diff --git a/background.js b/background.js index 06048e7..a690d6a 100644 --- a/background.js +++ b/background.js @@ -716,6 +716,56 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) { enabledSites.push(mc_domain); } + let header_referer_hostname = urlHost(header_referer); + if (header_referer_hostname.endsWith('.com.au')) { + // enable regional The West Australian sites (opt-in to custom sites) + var au_thewest_domains = ['thewest.com.au']; + var au_thewest_domain = (details.url.startsWith('https://images.thewest.com.au/') && ['image'].includes(details.type) && + !matchUrlDomain(au_thewest_domains, header_referer) && enabledSites.includes('thewest.com.au')); + if (au_thewest_domain) { + let thewest_domain = urlHost(header_referer).replace(/^(www|edition)\./, ''); + if (!allow_cookies.includes(thewest_domain)) + allow_cookies.push(thewest_domain); + au_thewest_domains.push(thewest_domain); + if (!enabledSites.includes(thewest_domain)) + enabledSites.push(thewest_domain); + } + + } else if (header_referer_hostname.endsWith('.de')) { + + // block script for additional Madsack/RND sites (opt-in to custom sites) + var de_madsack_domains = grouped_sites['###_de_madsack']; + var de_rnd_domain = (matchUrlDomain('rndtech.de', details.url) && ['script'].includes(details.type) && !matchUrlDomain(de_madsack_domains.concat(['madsack.de', 'madsack-medien-campus.de', 'rnd.de']), header_referer) && enabledSites.includes('###_de_madsack')); + if (de_rnd_domain) { + let rnd_domain = urlHost(header_referer).replace(/^(www|m)\./, ''); + if (!allow_cookies.includes(rnd_domain)) + allow_cookies.push(rnd_domain); + blockedRegexes[rnd_domain] = blockedRegexes['haz.de']; + de_madsack_domains.push(rnd_domain); + if (!enabledSites.includes(rnd_domain)) + enabledSites.push(rnd_domain); + } + + } else if (header_referer_hostname.endsWith('.fi')) { + + // set user-agent to GoogleBot for additional Snamoma Media Finland (opt-in to custom sites) + var fi_sanoma_domains = grouped_sites['###_fi_sanoma']; + var fi_sanoma_sndp_domain = (matchUrlDomain('sanoma-sndp.fi', details.url) && ['xmlhttprequest'].includes(details.type) && !matchUrlDomain(fi_sanoma_domains, header_referer) && enabledSites.includes('###_fi_sanoma')); + if (fi_sanoma_sndp_domain) { + let sanoma_domain = urlHost(header_referer).replace(/^www\./, ''); + if (!allow_cookies.includes(sanoma_domain)) + allow_cookies.push(sanoma_domain); + if (!use_google_bot.includes(sanoma_domain)) { + use_google_bot.push(sanoma_domain); + change_headers.push(sanoma_domain); + } + fi_sanoma_domains.push(sanoma_domain); + if (!enabledSites.includes(sanoma_domain)) + enabledSites.push(sanoma_domain); + } + + } else if (header_referer_hostname.match(/\.(com|org)$/)) { + // set googlebot-useragent for Gannett sites var usa_gannett_domains = grouped_sites['###_usa_gannett']; var usa_gannett_domain = (matchUrlDomain('gannett-cdn.com', details.url) && ['xmlhttprequest'].includes(details.type) && !matchUrlDomain(usa_gannett_domains.concat(['usatoday.com']), header_referer) && enabledSites.includes('###_usa_gannett')); @@ -792,33 +842,6 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) { enabledSites.push(mng_domain); } - // block script for additional Madsack/RND sites (opt-in to custom sites) - var de_madsack_domains = grouped_sites['###_de_madsack']; - var de_rnd_domain = (matchUrlDomain('rndtech.de', details.url) && ['script'].includes(details.type) && !matchUrlDomain(de_madsack_domains.concat(['madsack.de', 'madsack-medien-campus.de', 'rnd.de']), header_referer) && enabledSites.includes('###_de_madsack')); - if (de_rnd_domain) { - let rnd_domain = urlHost(header_referer).replace(/^(www|m)\./, ''); - if (!allow_cookies.includes(rnd_domain)) - allow_cookies.push(rnd_domain); - blockedRegexes[rnd_domain] = blockedRegexes['haz.de']; - de_madsack_domains.push(rnd_domain); - if (!enabledSites.includes(rnd_domain)) - enabledSites.push(rnd_domain); - } - - // set user-agent to GoogleBot for additional Snamoma Media Finland (opt-in to custom sites) - var fi_sanoma_domains = grouped_sites['###_fi_sanoma']; - var fi_sanoma_sndp_domain = (matchUrlDomain('sanoma-sndp.fi', details.url) && ['xmlhttprequest'].includes(details.type) && !matchUrlDomain(fi_sanoma_domains, header_referer) && enabledSites.includes('###_fi_sanoma')); - if (fi_sanoma_sndp_domain) { - let sanoma_domain = urlHost(header_referer).replace(/^www\./, ''); - if (!allow_cookies.includes(sanoma_domain)) - allow_cookies.push(sanoma_domain); - if (!use_google_bot.includes(sanoma_domain)) { - use_google_bot.push(sanoma_domain); - change_headers.push(sanoma_domain); - } - fi_sanoma_domains.push(sanoma_domain); - if (!enabledSites.includes(sanoma_domain)) - enabledSites.push(sanoma_domain); } // block external javascript for custom sites (optional) @@ -854,7 +877,7 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) { let allow_ext_source = medium_custom_domain; let bpc_amp_site = false; - let au_swm_site = (header_referer && urlHost(header_referer).endsWith('com.au') && details.url.includes('https://s.thewest.com.au/')); + let au_swm_site = (header_referer && urlHost(header_referer).endsWith('com.au') && details.url.includes('https://images.thewest.com.au/')); if (isSiteEnabled({url: header_referer})) { let inkl_site = (matchUrlDomain('cdn.jsdelivr.net', details.url) && matchUrlDomain('inkl.com', header_referer)); diff --git a/changelog.txt b/changelog.txt index 3a11143..84032a4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ Changelog Bypass Paywalls Clean - Firefox Post-release Fix Australia News Corp (amp-redirect) +Fix The West Australian (regional) * v2.5.3.1 (2022-01-23) Hotfix block inline script diff --git a/contentScript.js b/contentScript.js index 9998ca6..4aa431e 100644 --- a/contentScript.js +++ b/contentScript.js @@ -218,8 +218,8 @@ else { } } else { // Australian Seven West Media - let swm_script = document.querySelector('script[src^="https://s.thewest.com.au"]'); - if (matchDomain('thewest.com.au') || swm_script) { + let swm_image = document.querySelector('img[src^="https://images.thewest.com.au"]'); + if (matchDomain('thewest.com.au') || swm_image) { window.setTimeout(function () { let breach_screen = document.querySelector('div[data-testid*="BreachScreen"]'); if (breach_screen) { diff --git a/manifest.json b/manifest.json index f9a4cff..144df2d 100644 --- a/manifest.json +++ b/manifest.json @@ -603,5 +603,5 @@ "*://*.wsj.net/*", "*://*.zephr.com/*" ], - "version": "2.5.3.2" + "version": "2.5.3.3" } diff --git a/sites.js b/sites.js index 54bd724..51374a7 100644 --- a/sites.js +++ b/sites.js @@ -1630,7 +1630,7 @@ var defaultSites = { allow_cookies: 1, block_regex: /\.washingtonpost\.com\/pwapiv2\/article/ }, - "The West Australian (+ regional)": { + "The West Australian (+ regional/opt-in to custom sites)": { domain: "thewest.com.au", allow_cookies: 1 },