Add Frankfurter Allgemeine (Faz.net)

Updated script from paywallr (@tobimori).
Also compatible with Firefox now (regex lookbehind not supported on FF).
This commit is contained in:
magnolia1234 2020-04-25 17:18:12 +02:00
parent 5818435761
commit 54d87365f0
4 changed files with 69 additions and 1 deletions

View file

@ -171,6 +171,7 @@
[Science & Vie](https://www.science-et-vie.com) - [Science & Vie](https://www.science-et-vie.com) -
[Valeurs Actuelles](https://www.valeursactuelles.com) [Valeurs Actuelles](https://www.valeursactuelles.com)
##### Germany/Austria ##### Germany/Austria
[Frankfurter Allgemeine Zeitung](https://www.faz.net) -
[Handelsblatt](https://www.handelsblatt.com) - [Handelsblatt](https://www.handelsblatt.com) -
[Kleine Zeitung](https://www.kleinezeitung.at) [Kleine Zeitung](https://www.kleinezeitung.at)
##### Italy ##### Italy

View file

@ -30,6 +30,7 @@ var allow_cookies = [
'dvhn.nl', 'dvhn.nl',
'elmercurio.com', 'elmercurio.com',
'eurekareport.com.au', 'eurekareport.com.au',
'faz.net',
'folha.uol.com.br', 'folha.uol.com.br',
'gestion.pe', 'gestion.pe',
'goldcoastbulletin.com.au', 'goldcoastbulletin.com.au',
@ -330,6 +331,22 @@ ext_api.webRequest.onBeforeRequest.addListener(function (details) {
["blocking"] ["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_default = ["*://*.tinypass.com/*", "*://*.poool.fr/*", "*://*.piano.io/*", "*://*.outbrain.com/*"];
var block_js_custom = []; var block_js_custom = [];
var block_js = block_js_default.concat(block_js_custom); var block_js = block_js_default.concat(block_js_custom);

View file

@ -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 = ''; var href = '';
const signin_links = document.querySelectorAll('a.primary-button--link'); const signin_links = document.querySelectorAll('a.primary-button--link');
for (let i = 0; i < signin_links.length; i++) { 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 // General Functions
function removeDOMElement(...elements) { function removeDOMElement(...elements) {
for (let element of elements) { for (let element of elements) {

View file

@ -41,6 +41,7 @@ var defaultSites =
"Folha de S. Paulo": "folha.uol.com.br", "Folha de S. Paulo": "folha.uol.com.br",
"Foreign Policy": "foreignpolicy.com", "Foreign Policy": "foreignpolicy.com",
"Fortune": "fortune.com", "Fortune": "fortune.com",
"Frankfurter Allgemeine Zeitung": "faz.net",
"Gestión": "gestion.pe", "Gestión": "gestion.pe",
"Glassdoor": "glassdoor.com", "Glassdoor": "glassdoor.com",
"Gold Coast Bulletin": "goldcoastbulletin.com.au", "Gold Coast Bulletin": "goldcoastbulletin.com.au",