From 84aa5aa881ecbef76bd40cd33064a97b5f7b1faf Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sun, 29 Mar 2020 13:38:26 +0200 Subject: [PATCH] Fix Telegraaf.nl --- contentScript.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/contentScript.js b/contentScript.js index 27e6a53..d815c4d 100644 --- a/contentScript.js +++ b/contentScript.js @@ -54,12 +54,40 @@ else if (matchDomain("americanbanker.com")) { } else if (matchDomain('telegraaf.nl')) { - setTimeout(function () { - const paywall = document.getElementById('TEMPRORARY_METERING_ID'); - if (paywall) { - window.location.reload(true); + if (window.location.href.startsWith('https://www.telegraaf.nl/error?ref=/')) { + window.location.href = window.location.href.split('&')[0].replace('error?ref=/', ''); + } + let article_wrapper = document.querySelector('.ArticlePageWrapper__uid'); + let spotx_banner = document.querySelector('.ArticleBodyBlocks__inlineArticleSpotXBanner'); + let paywall = document.querySelector('.PopupBackdrop__block'); + removeDOMElement(spotx_banner, paywall); + let premium = document.querySelector('.PremiumLabelWithLine__body'); + let article_id = article_wrapper ? article_wrapper.innerText : '123'; + let article_body_done = document.querySelector('#articleBody' + article_id); + if (premium && !article_body_done) { + let article_body_old = document.querySelector('[id^=articleBody]'); + removeDOMElement(article_body_old); + let json = document.querySelector('script[type="application/ld+json"][data-react-helmet="true"]'); + if (json) { + json_text = JSON.parse(json.text).articleBody; + let article_body = document.querySelector('section.TextArticlePage__bodyText'); + if (article_body) { + let div_main = document.createElement("div"); + div_main.setAttribute('id', 'articleBody' + article_id); + let div_elem = document.createElement("div"); + div_elem.setAttribute('data-element', 'articleBodyBlocks'); + let text_array = json_text.split('\n\n'); + text_array.forEach(p_text => { + let p_div = document.createElement("p"); + p_div.setAttribute('class', 'ArticleBodyBlocks__paragraph ArticleBodyBlocks__paragraph--nieuws'); + p_div.innerText = p_text; + div_elem.appendChild(p_div); + }); + div_main.appendChild(div_elem); + article_body.appendChild(div_main); + } } - }, 1000); // Delay (in milliseconds) + } } else if (matchDomain('ad.nl')) {