From cee0cc07940069d542186248df3b8f29fa3370d7 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Tue, 29 Jun 2021 21:13:53 +0200 Subject: [PATCH] Fix Quartz (link to archive.is) --- background.js | 3 ++- changelog.txt | 1 + contentScript.js | 38 +++++++++++++++++++++++++++----------- manifest.json | 2 +- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/background.js b/background.js index 0a751df9..e35dd97e 100644 --- a/background.js +++ b/background.js @@ -365,6 +365,7 @@ var blockedRegexes = { 'observador.pt': /\.tinypass\.com\//, 'parismatch.com': /\.poool\.fr\//, 'quotidiano.net': /\.tinypass\.com\//, + 'qz.com': /\.tinypass\.com\//, 'reuters.com': /\.reuters\.com\/(arc\/subs\/p\.min|pf\/resources\/dist\/reuters\/js\/index)\.js/, 'rollingstone.com': /cdn\.cxense\.com\//, 'ruhrnachrichten.de': /\.tinypass\.com\//, @@ -1238,7 +1239,7 @@ if (matchUrlDomain(change_headers, details.url) && (['main_frame', 'sub_frame', } if ((!['font', 'stylesheet'].includes(details.type) || matchUrlDomain(cs_limit_except, currentTabUrl)) && !csDone) { let lib_file = 'lib/empty.js'; - if (matchUrlDomain(['business-standard.com', 'cicero.de', 'economictimes.com', 'faz.net', 'gva.be', 'lesechos.fr', 'newleftreview.org', 'newyorker.com', 'nzherald.co.nz', 'prospectmagazine.co.uk', 'sudouest.fr', 'techinasia.com', 'valor.globo.com'].concat(nl_mediahuis_region_domains), currentTabUrl)) + if (matchUrlDomain(['business-standard.com', 'cicero.de', 'economictimes.com', 'gva.be', 'lesechos.fr', 'newleftreview.org', 'newyorker.com', 'nzherald.co.nz', 'prospectmagazine.co.uk', 'sudouest.fr', 'techinasia.com', 'valor.globo.com'].concat(nl_mediahuis_region_domains), currentTabUrl)) lib_file = 'lib/purify.min.js'; ext_api.tabs.executeScript(tabId, { file: lib_file, diff --git a/changelog.txt b/changelog.txt index d3753779..7c03028b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ Changelog Bypass Paywalls Clean - Firefox Post-release Fix Augsburger Allgemeine +Fix Quartz (link to archive.is) Maintenance contentScript (sanitize html-input) * v2.2.7.0 (2021-06-27) diff --git a/contentScript.js b/contentScript.js index 78aa1b28..fdadd023 100644 --- a/contentScript.js +++ b/contentScript.js @@ -374,7 +374,7 @@ else if (matchDomain('faz.net')) { if (response.ok) { response.text().then(html => { var parser = new DOMParser(); - var doc = parser.parseFromString(DOMPurify.sanitize(html), 'text/html'); + var doc = parser.parseFromString(html, 'text/html'); let json = doc.querySelector('script[id="schemaOrgJson"]'); if (json) { var json_text = json.text.replace(/(\r|\n)/g, ''); @@ -1494,17 +1494,9 @@ else if (matchDomain('thetimes.co.uk')) { let paywall = document.querySelector('div#paywall-portal-article-footer'); if (paywall && !url.includes('?shareToken=')) { removeDOMElement(paywall); - let text_fail_div = document.createElement('div'); - text_fail_div.appendChild(document.createTextNode('BPC > Read full article text:\r\n')); - let a_link = document.createElement('a'); - a_link.innerText = archive_url; - a_link.href = archive_url; - a_link.target = '_blank'; - a_link.setAttribute('style', 'font-weight: bold;'); - text_fail_div.appendChild(a_link); let article = document.querySelector('article[role="article"]'); if (article) - article.insertBefore(text_fail_div, article.firstChild); + article.insertBefore(archiveLink(archive_url), article.firstChild); } let paywall_page = document.querySelector('div#paywall-portal-page-footer'); removeDOMElement(paywall_page); @@ -2187,11 +2179,22 @@ else if (matchDomain('nytimes.com')) { } else if (matchDomain('qz.com')) { + let url = window.location.href; window.setTimeout(function () { - let url = window.location.href; if (url.includes('utm_source=')) window.location.href = url.split('?')[0]; }, 500); // Delay (in milliseconds) + let archive_url = 'https://archive.is?url=' + url; + let paywall = document.querySelector('div.KbD9m'); + let overflow = document.querySelector('div._7S-qA'); + let msg = document.querySelector('div#bpc_archive'); + if (paywall && !msg) { + if (overflow) + overflow.classList.remove('_7S-qA'); + let article = document.querySelector('div#article-content'); + if (article) + article.appendChild(archiveLink(archive_url)); + } } else if (matchDomain('republic.ru')) { @@ -2646,6 +2649,19 @@ function replaceDomElementExt(url, proxy, base64, selector, text_fail = '') { }); } +function archiveLink(archive_url) { + let text_fail_div = document.createElement('div'); + text_fail_div.id = 'bpc_archive'; + text_fail_div.appendChild(document.createTextNode('BPC > Read full article text:\r\n')); + let a_link = document.createElement('a'); + a_link.innerText = archive_url; + a_link.href = archive_url; + a_link.target = '_blank'; + a_link.setAttribute('style', 'font-weight: bold;'); + text_fail_div.appendChild(a_link); + return text_fail_div; +} + function removeClassesByPrefix(el, prefix) { let el_classes = el.classList; for (let el_class of el_classes) { diff --git a/manifest.json b/manifest.json index d07a5242..0db9d964 100644 --- a/manifest.json +++ b/manifest.json @@ -528,5 +528,5 @@ "*://*.wallkit.net/*", "*://*.wsj.net/*" ], - "version": "2.2.7.2" + "version": "2.2.7.3" } \ No newline at end of file