From 54d87365f0b83ee629d063758250b074f475c485 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sat, 25 Apr 2020 17:18:12 +0200 Subject: [PATCH] Add Frankfurter Allgemeine (Faz.net) Updated script from paywallr (@tobimori). Also compatible with Firefox now (regex lookbehind not supported on FF). --- README.md | 1 + background.js | 17 ++++++++++++++++ contentScript.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++- sites.js | 1 + 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b040f56..849fff7 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ [Science & Vie](https://www.science-et-vie.com) - [Valeurs Actuelles](https://www.valeursactuelles.com) ##### Germany/Austria +[Frankfurter Allgemeine Zeitung](https://www.faz.net) - [Handelsblatt](https://www.handelsblatt.com) - [Kleine Zeitung](https://www.kleinezeitung.at) ##### Italy diff --git a/background.js b/background.js index 6d05509..46ef638 100644 --- a/background.js +++ b/background.js @@ -30,6 +30,7 @@ var allow_cookies = [ 'dvhn.nl', 'elmercurio.com', 'eurekareport.com.au', +'faz.net', 'folha.uol.com.br', 'gestion.pe', 'goldcoastbulletin.com.au', @@ -330,6 +331,22 @@ ext_api.webRequest.onBeforeRequest.addListener(function (details) { ["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"]); + var block_js_default = ["*://*.tinypass.com/*", "*://*.poool.fr/*", "*://*.piano.io/*", "*://*.outbrain.com/*"]; var block_js_custom = []; var block_js = block_js_default.concat(block_js_custom); diff --git a/contentScript.js b/contentScript.js index e943eb6..6167041 100644 --- a/contentScript.js +++ b/contentScript.js @@ -478,7 +478,7 @@ else if (matchDomain('challenges.fr')) { }); } -else if (window.location.href.indexOf("barrons.com") !== -1) { +else if (matchDomain('barrons.com')) { var href = ''; const signin_links = document.querySelectorAll('a.primary-button--link'); for (let i = 0; i < signin_links.length; i++) { @@ -505,6 +505,55 @@ else if (matchDomain('lescienze.it')) { } } +else if (matchDomain('faz.net')) { + let paywall = document.querySelector('#paywall-form-container-outer,.atc-ContainerPaywall'); + if (paywall) { + removeDOMElement(paywall); + let url = new URL(window.location.href); + let mUrl = new URL(url.pathname, "https://m.faz.net/"); + fetch(mUrl) + .then(response => { + if (response.ok) { + response.text().then(html => { + var parser = new DOMParser(); + var doc = parser.parseFromString(html, 'text/html'); + let json = doc.querySelector('script[id="schemaOrgJson"]'); + if (json) { + var json_text = JSON.parse(json.text).ArticleBody; + let article_text = document.querySelector('.art_txt.paywall,.atc-Text.js-atc-Text'); + article_text.innerText = ''; + + const breakText = (str) => { + str = str.replace(/(?:^|[\w\"\“])(\.|\?|!)(?=[A-Za-zÀ-ÿ\„]{2,})/gm, "$&\n\n"); + str = str.replace(/([a-z\"\“])(?=[A-Z])/gm, "$&\n\n"); + // exceptions: names with alternating lower/uppercase (no general fix) + str = str.replace(/Glaxo\n\nSmith\n\nKline/g, "GlaxoSmithKline"); + str = str.replace(/If\n\nSG/g, "IfSG"); + str = str.replace(/La\n\nPierre/g, "LaPierre"); + return str; + }; + + json_text = breakText(json_text); + json_text.split("\n\n").forEach( + (p_text) => { + let elem; + if (p_text.length < 80) { + elem = document.createElement("h2"); + elem.setAttribute('class', 'atc-SubHeadline'); + } else { + elem = document.createElement("p"); + elem.setAttribute('class', 'atc-TextParagraph'); + }; + elem.innerText = p_text; + article_text.appendChild(elem); + }); + } + }) + } + }); + } +} + // General Functions function removeDOMElement(...elements) { for (let element of elements) { diff --git a/sites.js b/sites.js index beb60e9..231696c 100644 --- a/sites.js +++ b/sites.js @@ -41,6 +41,7 @@ var defaultSites = "Folha de S. Paulo": "folha.uol.com.br", "Foreign Policy": "foreignpolicy.com", "Fortune": "fortune.com", + "Frankfurter Allgemeine Zeitung": "faz.net", "Gestión": "gestion.pe", "Glassdoor": "glassdoor.com", "Gold Coast Bulletin": "goldcoastbulletin.com.au",