From 8b811af497bc1e46bb22434b53216b77dcc10545 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Fri, 24 Jun 2022 11:46:16 +0200 Subject: [PATCH] Fix Business Standard --- background.js | 23 +++++------------------ changelog.txt | 1 + contentScript.js | 26 ++++++++------------------ manifest.json | 2 +- sites.js | 3 ++- 5 files changed, 17 insertions(+), 38 deletions(-) diff --git a/background.js b/background.js index fc5faad..7c3a713 100644 --- a/background.js +++ b/background.js @@ -501,7 +501,7 @@ ext_api.webRequest.onBeforeRequest.addListener(function (details) { ); // m.faz.net set user-agent to mobile -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"; +const userAgentMobile = "Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36"; ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) { if (!isSiteEnabled(details)) { return; @@ -509,7 +509,7 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) { let headers = details.requestHeaders; headers = headers.map(function (header) { if (header.name.toLowerCase() === 'user-agent') - header.value = faz_uaMobile; + header.value = userAgentMobile; return header; }); return { @@ -521,20 +521,7 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) { }, ["blocking", "requestHeaders"]); -// wap.business-standard.com (mobile) redirect to www (desktop) -ext_api.webRequest.onBeforeRequest.addListener(function (details) { - if (!isSiteEnabled(details)) { - return; - } - var updatedUrl = details.url.replace('/wap.', '/www.'); - return { redirectUrl: updatedUrl }; -}, -{urls:["*://wap.business-standard.com/*"], types:["main_frame"]}, -["blocking"] -); - -// www.business-standard.com set user-agent to desktop -const business_standard_uaDesktop = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"; +// wap.business-standard.com/article-amp/ set user-agent to mobile ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) { if (!isSiteEnabled(details)) { return; @@ -542,14 +529,14 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) { let headers = details.requestHeaders; headers = headers.map(function (header) { if (header.name.toLowerCase() === 'user-agent') - header.value = business_standard_uaDesktop; + header.value = userAgentMobile; return header; }); return { requestHeaders: headers }; }, { - urls: ["*://www.business-standard.com/*"], + urls: ["*://wap.business-standard.com/article-amp/*"], types: ["main_frame"] }, ["blocking", "requestHeaders"]); diff --git a/changelog.txt b/changelog.txt index bc17686..5b9e496 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Changelog Bypass Paywalls Clean - Firefox Post-release +Fix Business Standard Fix LesEchos.fr * v2.7.2.0 (2022-06-06) diff --git a/contentScript.js b/contentScript.js index 171b570..03b3cc2 100644 --- a/contentScript.js +++ b/contentScript.js @@ -2612,25 +2612,15 @@ else if (matchDomain('business-standard.com')) { let skip_button = document.querySelector('a.btn_skip'); if (skip_button) skip_button.click(); - let p_content = document.querySelector('span.p-content.paywall'); - if (p_content) { - p_content.classList.remove('paywall'); - let json_script = getArticleJsonScript(); - if (json_script) { - let json_text = JSON.parse(json_script.text.replace(/(\r|\n|\t)/gm, ''))[0].articleBody; - json_text = parseHtmlEntities(json_text); - json_text = json_text.replace(/(?:^|[\w\"\'\’])(\.|\?|!)(?=[A-Z\"\”\“\‘\’\'][A-Za-zÀ-ÿ\"\”\“\‘\’\']{1,})/gm, "$&\r\n\r\n") + '\r\n\r\n'; - let article = document.createElement('div'); - article.innerText = json_text; - if (article) { - let old_pars = p_content.querySelectorAll('p'); - for (let old_par of old_pars) { - if (!old_par.querySelector('img')) - removeDOMElement(old_par); - } - p_content.appendChild(article); - } + if (!window.location.pathname.startsWith('/article-amp/')) { + let paywall = document.querySelector('span.p-content.paywall, main'); + let amphtml = document.querySelector('link[rel="amphtml"]'); + if (paywall && amphtml) { + removeDOMElement(paywall); + window.location.href = amphtml.href; } + } else { + amp_unhide_subscr_section('amp-ad, amp-embed, .block-cont-amp, #divnonpaidcontent'); } } diff --git a/manifest.json b/manifest.json index 23cf83b..1538f7f 100644 --- a/manifest.json +++ b/manifest.json @@ -683,5 +683,5 @@ "*://*.wsj.net/*", "*://webcache.googleusercontent.com/*" ], - "version": "2.7.2.1" + "version": "2.7.2.2" } diff --git a/sites.js b/sites.js index 1be18a7..9c60bfd 100644 --- a/sites.js +++ b/sites.js @@ -216,7 +216,8 @@ var defaultSites = { }, "Business Standard": { domain: "business-standard.com", - allow_cookies: 1 + allow_cookies: 1, + block_regex: /cdn\.ampproject\.org\/v\d\/amp-subscriptions-.+\.js/ }, "Causeur": { domain: "causeur.fr",