From 9157ebcd8c0574c897e488990a18d61b63aa494e Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Fri, 22 Oct 2021 12:36:25 +0200 Subject: [PATCH] Fix The Globe and Mail --- background.js | 3 ++- changelog.txt | 1 + contentScript.js | 31 +++++++++++-------------------- custom/manifest.json | 2 +- manifest.json | 2 +- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/background.js b/background.js index 71df70b..b30ded7 100755 --- a/background.js +++ b/background.js @@ -35,6 +35,7 @@ const restrictions = { 'seekingalpha.com': /.+\/seekingalpha\.com\/($|(amp\/)?(article|news)\/|samw\/)/, 'statista.com': /^((?!\.statista\.com\/(outlook|study)\/).)*$/, 'techinasia.com': /\.techinasia\.com\/.+/, + 'theglobeandmail.com': /\.theglobeandmail\.com\/.+\//, 'timeshighereducation.com': /.+\.timeshighereducation\.com\/(sites\/default\/files\/|.+((\w)+(\-)+){3,}.+)/ } @@ -407,7 +408,7 @@ var blockedRegexes = { 'telegraph.co.uk': /(\.tinypass\.com\/|cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent)-.+\.js|\.telegraph\.co\.uk\/.+\/piano.+\.js|assets\.adobedtm\.com\/.+\.js)/, 'theartnewspaper.com': /\.amazonaws.com\/production-website-scripts\/bouncer\.js/, 'thedailybeast.com': /\.tinypass\.com\//, - 'theglobeandmail.com': /smartwall\.theglobeandmail\.com\//, + 'theglobeandmail.com': /(\.theglobeandmail\.com\/pf\/dist\/engine\/react\.js|smartwall\.theglobeandmail\.com\/)/, 'thehindu.com': /(cdn\.cxense\.com\/|\.tinypass\.com\/)/, 'thehindubusinessline.com': /(cdn\.cxense\.com\/|\.tinypass\.com\/)/, 'theintercept.com': /\.theintercept\.com\/api\/tinypass\.min\.js/, diff --git a/changelog.txt b/changelog.txt index e866662..e9c8548 100644 --- a/changelog.txt +++ b/changelog.txt @@ -10,6 +10,7 @@ Fix Business Standard Fix Il Tirreno (GElocal.it) Fix Financial Times (amp) Fix La Croix (timing) +Fix The Globe and Mail Fix The New Yorker (homepage) Fix Trouw.nl (timing) Update custom sites (block regex for default sites) diff --git a/contentScript.js b/contentScript.js index 3182d2f..e793ab0 100755 --- a/contentScript.js +++ b/contentScript.js @@ -3,6 +3,7 @@ var ext_api = (typeof browser === 'object') ? browser : chrome; var domain; var csDone = false; var csDoneOnce = false; +var dompurify_loaded = (typeof DOMPurify === 'function'); var ca_torstar_domains = ['niagarafallsreview.ca', 'stcatharinesstandard.ca', 'thepeterboroughexaminer.com', 'therecord.com', 'thespec.com', 'thestar.com', 'wellandtribune.ca']; var de_funke_media_domains = ['abendblatt.de', 'braunschweiger-zeitung.de', 'morgenpost.de', 'nrz.de', 'otz.de', 'thueringer-allgemeine.de', 'tlz.de', 'waz.de', 'wp.de', 'wr.de']; @@ -927,7 +928,7 @@ else if (matchDomain('lesechos.fr') && window.location.href.match(/-\d{6,}/)) { let ad_blocks = document.querySelectorAll('[class*="jzxvkd"'); for (let ad_block of ad_blocks) ad_block.setAttribute('style', 'display:none'); - if (abo_banner) { + if (abo_banner && dompurify_loaded) { removeDOMElement(abo_banner); let url = window.location.href; let html = document.documentElement.outerHTML; @@ -994,7 +995,7 @@ else if (matchDomain('loeildelaphotographie.com')) { else if (matchDomain('marianne.net')) { let paywall = document.querySelector('div.paywall'); - if (paywall) { + if (paywall && dompurify_loaded) { let article_source = document.querySelector('div.article-body[data-content-src]'); if (article_source) { let article_text = decode_utf8(atob(article_source.getAttribute('data-content-src'))); @@ -1218,7 +1219,7 @@ else if (matchDomain(nl_mediahuis_region_domains)) { if (close_button) close_button.click(); let premium = document.querySelector('div.common-components-plus_pluslabel--container'); - if (premium) { + if (premium && dompurify_loaded) { let hidden_article = document.querySelector('div[data-auth-body="article"]'); if (hidden_article) hidden_article.removeAttribute('style'); @@ -1671,7 +1672,7 @@ else if (matchDomain('bloomberg.com')) { blur.removeAttribute('style'); } let json_script = document.querySelector('script[data-component-props="ArticleBody"], script[data-component-props="FeatureBody"]'); - if (json_script) { + if (json_script && dompurify_loaded) { let json = JSON.parse(json_script.innerHTML); if (json) { let json_text = json.body ? json.body : ''; @@ -1826,7 +1827,7 @@ else if (matchDomain('economictimes.com')) { window.setTimeout(function () { let paywall = document.querySelector('div#blocker_layer'); let data_prime = document.querySelector('div[data-prime="1"]'); - if (paywall || data_prime) { + if ((paywall || data_prime) && dompurify_loaded) { removeDOMElement(paywall); if (data_prime) data_prime.removeAttribute('data-prime'); @@ -2239,7 +2240,7 @@ else if (matchDomain('newyorker.com') && window.location.href.split('?')[0].matc let parser = new DOMParser(); for (let overlay of overlays) { let noscript = overlay.querySelector('noscript'); - if (noscript && noscript.innerHTML) { + if (noscript && noscript.innerHTML && dompurify_loaded) { let html = parser.parseFromString(DOMPurify.sanitize(noscript.innerHTML), 'text/html'); overlay.appendChild(html.querySelector('img')); removeDOMElement(noscript); @@ -2251,7 +2252,7 @@ else if (matchDomain('nzherald.co.nz')) { let article_content = document.querySelector('.article__content'); if (article_content) { let article_offer = document.querySelector('.article-offer'); - if (article_offer) { + if (article_offer && dompurify_loaded) { removeDOMElement(article_offer); let css_selector = article_content.querySelectorAll('p[style]')[1].getAttribute('class'); let hidden_not_pars = article_content.querySelectorAll('.' + css_selector + ':not(p)'); @@ -2451,7 +2452,7 @@ else if (matchDomain('study.com')) { else if (matchDomain('techinasia.com')) { let paywall = document.querySelector('.paywall-content'); - if (paywall) { + if (paywall && dompurify_loaded) { paywall.classList.remove('paywall-content'); let url = window.location.href; let url_xhr = url.replace('.com/', '.com/wp-json/techinasia/2.0/posts/').replace('/visual-story/', '/'); @@ -2576,18 +2577,8 @@ else if (matchDomain('thediplomat.com')) { else if (matchDomain('theglobeandmail.com')) { let article_body_subscribed = document.querySelector('.c-article-body--subscribed'); - if (article_body_subscribed) { + if (article_body_subscribed) article_body_subscribed.removeAttribute('class'); - csDoneOnce = true; - } - function tgam_main() { - document.addEventListener('bpc_event', function (e) { - if (window.tgam) - window.tgam.keytar.subscriberPaywallEnabled = false; - }) - } - insert_script(tgam_main); - document.dispatchEvent(new CustomEvent('bpc_event', {})); } else if (matchDomain(['thehindu.com', 'thehindubusinessline.com'])) { @@ -2682,7 +2673,7 @@ else if (matchDomain(no_nhst_media_domains)) { } else { window.setTimeout(function () { let paywall = document.querySelector('iframe#paywall-iframe'); - if (paywall) { + if (paywall && dompurify_loaded) { removeDOMElement(paywall); fetch(url) .then(response => { diff --git a/custom/manifest.json b/custom/manifest.json index 09c6820..32c664d 100644 --- a/custom/manifest.json +++ b/custom/manifest.json @@ -39,5 +39,5 @@ "webRequestBlocking", "" ], - "version": "2.4.0.4" + "version": "2.4.0.5" } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 7a23c5c..74c2a6f 100755 --- a/manifest.json +++ b/manifest.json @@ -544,5 +544,5 @@ "*://*.wallkit.net/*", "*://*.wsj.net/*" ], - "version": "2.4.0.4" + "version": "2.4.0.5" } \ No newline at end of file