From d2aa8c6699de4d889fc2687da7021adff12f8548 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Wed, 30 Mar 2022 18:22:20 +0200 Subject: [PATCH] Fix Madsack Mediengruppe --- changelog.txt | 1 + contentScript.js | 101 +++++++++++++++++++++++++++---------------- custom/manifest.json | 2 +- manifest.json | 2 +- sites.js | 2 +- 5 files changed, 68 insertions(+), 40 deletions(-) diff --git a/changelog.txt b/changelog.txt index a9f824a..119bbcd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,7 @@ Post-release Add Diario Cordoba Add La Opinion A Coruna Add La Opinion de Zamora +Fix Madsack Mediengruppe * v2.6.2.0 (2022-03-27) Add Badische Neueste Nachrichten diff --git a/contentScript.js b/contentScript.js index 5a1ab4b..5c0a63f 100755 --- a/contentScript.js +++ b/contentScript.js @@ -38,6 +38,18 @@ if (!matchDomain(arr_localstorage_hold)) { window.localStorage.clear(); } +function getArticleJsonScript() { + let scripts = document.querySelectorAll('script[type="application/ld+json"]'); + let json_script; + for (let script of scripts) { + if (script.innerText.includes('articleBody')) { + json_script = script; + break; + } + } + return json_script; +} + var bg2csData; // custom/updated sites: load text from json @@ -49,14 +61,9 @@ if ((bg2csData !== undefined) && bg2csData.ld_json && dompurify_loaded) { let paywall = document.querySelector(paywall_sel); if (paywall) { removeDOMElement(paywall); - let scripts = document.querySelectorAll('script[type="application/ld+json"]'); - let json; - for (let script of scripts) { - if (script.innerText.includes('articleBody')) - json = script; - } - if (json) { - let json_text = JSON.parse(json.text).articleBody; + let json_script = getArticleJsonScript(); + if (json_script) { + let json_text = JSON.parse(json_script.text).articleBody; let content = document.querySelector(article_sel); if (json_text && content) { let parser = new DOMParser(); @@ -629,14 +636,9 @@ else if (matchDomain(['ksta.de', 'rundschau-online.de'])) { let paywall = document.querySelector('.pay.wall'); if (paywall) { removeDOMElement(paywall); - let scripts = document.querySelectorAll('script[type="application/ld+json"]'); - let json; - for (let script of scripts) { - if (script.innerText.includes('articleBody')) - json = script; - } - if (json) { - let json_text = JSON.parse(json.text).articleBody; + let json_script = getArticleJsonScript(); + if (json_script) { + let json_text = JSON.parse(json_script.text).articleBody; json_text = parseHtmlEntities(json_text); json_text = breakText(json_text); let region = 'ortsmarke'; @@ -718,24 +720,55 @@ else if (matchDomain(['westfalen-blatt.de', 'wn.de', 'muensterschezeitung.de'])) } } -else if ((domain = matchDomain(de_madsack_domains)) || document.querySelector('link[rel="preload"][href="https://static.rndtech.de/cmp/1.x.x.js"]')) { - let url = window.location.href; - if (!url.includes(domain + '/amp/')) { +else if (matchDomain(de_madsack_domains) || document.querySelector('link[rel="preload"][href="https://static.rndtech.de/cmp/1.x.x.js"]') || document.querySelector('a.pdb-footer-meta-items-item-link[href="http://www.madsack.de/"]')) { + if (!(window.location.pathname.startsWith('/amp/') || window.location.search.startsWith('?outputType=valid_amp'))) { let paidcontent_intro = document.querySelector('div.pdb-article-body-paidcontentintro'); if (paidcontent_intro) { paidcontent_intro.classList.remove('pdb-article-body-paidcontentintro'); - let json_script = document.querySelector('div.pdb-article > script[type="application/ld+json"]'); - let json_text = JSON.parse(json_script.text).articleBody; - if (json_text) { - let pdb_richtext_field = document.querySelectorAll('div.pdb-richtext-field'); - if (pdb_richtext_field[1]) - pdb_richtext_field[1].innerText = json_text; + let json_script = getArticleJsonScript(); + if (json_script) { + let json_text = JSON.parse(json_script.text).articleBody; + if (json_text) { + let pdb_richtext_field = document.querySelectorAll('div.pdb-richtext-field'); + if (pdb_richtext_field[1]) + pdb_richtext_field[1].innerText = json_text; + } } let paidcontent_reg = document.querySelector('div.pdb-article-paidcontent-registration'); removeDOMElement(paidcontent_reg); + } else { + let paywall = document.querySelector('div.paywall'); + if (paywall) { + let gradient = document.querySelector('div[class^="ArticleContentLoaderstyled__Gradient"]'); + let loading = document.querySelector('#article > svg'); + removeDOMElement(paywall, gradient, loading); + let article = document.querySelector('div[class*="ArticleTeaserContainer"] > div:not([class])'); + let json_script = getArticleJsonScript(); + if (json_script) { + let json = JSON.parse(json_script.text); + if (article && json) { + let json_text = json.articleBody; + let article_new = document.createElement('span'); + let par = article.querySelector('p'); + let par_class = par ? par.getAttribute('class') : ''; + article_new.setAttribute('class', par_class); + article_new.innerText = json_text; + article.innerText = ''; + if (json.articleSection) { + let json_section = json.articleSection; + let article_section = document.querySelector('span'); + article_section.setAttribute('class', par_class); + article_section.setAttribute('style', 'font-weight: bold;'); + article_section.innerText = json_section + '. '; + article.appendChild(article_section); + } + article.appendChild(article_new); + } + } + } } } else { - amp_unhide_subscr_section('.pdb-ad-container'); + amp_unhide_subscr_section('.pdb-ad-container, amp-embed'); } } @@ -2437,14 +2470,9 @@ else if (matchDomain('business-standard.com')) { let p_content = document.querySelector('span.p-content.paywall'); if (p_content) { p_content.classList.remove('paywall'); - let scripts = document.querySelectorAll('script[type="application/ld+json"]'); - let json; - for (let script of scripts) { - if (script.innerText.includes('articleBody')) - json = script; - } - if (json) { - let json_text = JSON.parse(json.text.replace(/(\r|\n|\t)/gm, ''))[0].articleBody; + 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'); @@ -3643,9 +3671,8 @@ else if ((domain = matchDomain(usa_mcc_domains)) || document.querySelector('scri } } -else if ((domain = matchDomain(usa_mng_domains)) || (window.location.href.match(/\.com\/(\d){4}\/(\d){2}\/(\d){2}\/.+\/amp\//) && document.querySelector('amp-img#paywall[src*=".com/wp-content/plugins/dfm-amp-mods/"]'))) { - let url = window.location.href; - if (url.split('?')[0].endsWith('/amp/')) { +else if (matchDomain(usa_mng_domains) || (window.location.href.match(/\.com\/(\d){4}\/(\d){2}\/(\d){2}\/.+\/amp\//) && document.querySelector('amp-img#paywall[src*=".com/wp-content/plugins/dfm-amp-mods/"]'))) { + if (window.location.pathname.endsWith('/amp/')) { amp_unhide_subscr_section('amp-ad, amp-embed'); } } diff --git a/custom/manifest.json b/custom/manifest.json index 6975411..106ff98 100644 --- a/custom/manifest.json +++ b/custom/manifest.json @@ -41,5 +41,5 @@ "webRequestBlocking", "" ], - "version": "2.6.2.1" + "version": "2.6.2.2" } diff --git a/manifest.json b/manifest.json index 57d82b5..e05d249 100755 --- a/manifest.json +++ b/manifest.json @@ -654,5 +654,5 @@ "*://*.wallkit.net/*", "*://*.wsj.net/*" ], - "version": "2.6.2.1" + "version": "2.6.2.2" } diff --git a/sites.js b/sites.js index 84155e0..4886330 100755 --- a/sites.js +++ b/sites.js @@ -1062,7 +1062,7 @@ var defaultSites = { "ostsee-zeitung.de" ], allow_cookies: 1, - block_regex: /cdn\.ampproject\.org\/v\d\/amp-(ad|subscriptions)-.+\.js/ + block_regex: /(\.tinypass\.com\/|\.piano\.io\/|cdn\.ampproject\.org\/v\d\/amp-(ad|subscriptions)-.+\.js)/ }, "Mainichi Shimbun": { domain: "mainichi.jp",