From 8dc0ec439415d43d8c651442f6c5d3778e876257 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Sat, 4 Feb 2023 17:29:46 +0100 Subject: [PATCH] Fix The Hill Times (text) --- changelog.txt | 1 + contentScript.js | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/changelog.txt b/changelog.txt index 17222b56..45dc6687 100644 --- a/changelog.txt +++ b/changelog.txt @@ -13,6 +13,7 @@ Fix Madsack Mediengruppe Fix The Atlantic (images) Fix The Australian (The Oz) Fix The Globe and Mail (media) +Fix The Hill Times (text) * v3.0.3.0 (2023-01-29) Add Saarbruecker Zeitung diff --git a/contentScript.js b/contentScript.js index 727adaa7..7bae6ffb 100644 --- a/contentScript.js +++ b/contentScript.js @@ -61,8 +61,15 @@ if (bg2csData.ld_json && dompurify_loaded) { if (json_script) { try { let json = JSON.parse(json_script.text.replace(/[\r\n]/g, '').replace(/(\\r)?\\n/g, '
')); - let json_key = Object.keys(json).find(key => key.match(/^(articlebody|text)$/i)); - let json_text = parseHtmlEntities(json[json_key]); + let json_key, json_text; + if (Array.isArray(json)) { + json = json.filter(x => json_key = Object.keys(x).find(key => key.match(/^(articlebody|text)$/i))); + if (json_key) + json_text = parseHtmlEntities(json[0][json_key]); + } else { + json_key = Object.keys(json).find(key => key.match(/^(articlebody|text)$/i)); + json_text = parseHtmlEntities(json[json_key]); + } let content = document.querySelector(article_sel); if (json_text && content) { let parser = new DOMParser(); @@ -3259,18 +3266,24 @@ else if (matchDomain('hbrchina.org')) { } else if (matchDomain('hilltimes.com')) { - let paywall = document.querySelector('div[class^="paywallcont"]'); - if (paywall) { - removeDOMElement(paywall); - let content = document.querySelector('meta[property="og:description"][content]'); - if (content) { - let article = document.querySelector('div#fadebg'); - if (article) { - article.innerText = parseHtmlEntities(content.content); - article.removeAttribute('id'); + let paywall = document.querySelectorAll('div[class^="paywallcont"]'); + if (paywall.length) { + removeDOMElement(...paywall); + let json_script = document.querySelector('script.saswp-schema-markup-output'); + if (json_script) { + try { + let json = JSON.parse(json_script.text); + json_text = json.filter(x => x.articleBody)[0].articleBody.replace(/\s{2,}/g, '\r\n\r\n'); + let article = document.querySelector('div#fadebg > p'); + if (article) + article.innerText = parseHtmlEntities(json_text); + } catch (err) { + console.log(err); } } } + let banner = document.querySelector('section.hide_this_section'); + hideDOMElement(banner); } else if (matchDomain('hindustantimes.com')) {