From 9ff20121d5126025f4546c6936abace5b869ed1f Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Tue, 2 Jan 2024 08:58:14 +0100 Subject: [PATCH] Fix The Diplomat (magazine) --- README.md | 2 +- background.js | 58 +++++++++++++++++++--------------------- changelog.txt | 1 + contentScript.js | 26 +++++++++--------- custom/manifest.json | 2 +- custom/sites_custom.json | 6 +++++ manifest.json | 2 +- sites.js | 2 +- 8 files changed, 51 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 2b60f8bb..e4492533 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ For new sites you also have to opt-in to custom sites/request host permissions f Add-on was removed by Mozilla from [add-on store (AMO)](https://addons.mozilla.org).\ Current installations (by custom collection in Firefox Beta/Nightly or Firefox-fork) will stay active, but with no more updates. -[Firefox Beta 122+](https://play.google.com/store/apps/details?id=org.mozilla.firefox_beta) and [Firefox Nightly 122+](https://play.google.com/store/apps/details?id=org.mozilla.fenix) can still install/sideload a xpi-file (manual updates) when you enable the debug menu (settings > about > tap Firefox logo 5 times > return to settings). +[Firefox Beta 122+](https://play.google.com/store/apps/details?id=org.mozilla.firefox_beta) and [Firefox Nightly 122+](https://play.google.com/store/apps/details?id=org.mozilla.fenix) can still install/sideload a xpi-file (automatic updates) when you enable the debug menu (settings > about > tap Firefox logo 5 times > return to settings). Or use the Firefox-fork [Iceraven](https://github.com/fork-maintainers/iceraven-browser) v2.13.2+ (manual updates).\ You can install/update Iceraven manually or use the app [FFUpdater](https://github.com/Tobi823/ffupdater) diff --git a/background.js b/background.js index 04a68530..e444de59 100644 --- a/background.js +++ b/background.js @@ -1497,51 +1497,47 @@ ext_api.runtime.onMessage.addListener(function (message, sender) { } if (message.request === 'getExtSrc' && message.data) { message.data.html = ''; - if (message.data.url.startsWith('https://archive.')) { - fetch(message.data.url) - .then(response => { - if (response.ok) { - response.text().then(html => { - if (html.includes('
')[0].split('href="')[1].split('"')[0]; - message.data.url_src = url_src; - getArticleSrc(message); - } else { - message.data.html = html; - ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); - } - }); - } - }).catch(function (err) { - ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); - }); - } else - getArticleSrc(message); function getArticleSrc(message) { let url_src = message.data.url_src || message.data.url; fetch(url_src) .then(response => { if (response.ok) { response.text().then(html => { - if (message.data.base64) { - html = decode_utf8(atob(html)); - message.data.selector_source = 'body'; + let recursive; + if (message.data.url.startsWith('https://archive.')) { + if (url_src.includes('/https')) { + if (html.includes('
')[0].split('href="')[1].split('"')[0]; + getArticleSrc(message); + recursive = true; + } else + html = ''; + } } - message.data.html = html; - if (typeof DOMParser === 'function') { - let parser = new DOMParser(); - let doc = parser.parseFromString(html, 'text/html'); - let article_new = doc.querySelector(message.data.selector_source); - if (article_new) - message.data.html = article_new.outerHTML; + if (!recursive) { + if (html) { + if (message.data.base64) { + html = decode_utf8(atob(html)); + message.data.selector_source = 'body'; + } + if (typeof DOMParser === 'function') { + let parser = new DOMParser(); + let doc = parser.parseFromString(html, 'text/html'); + let article_new = doc.querySelector(message.data.selector_source); + if (article_new) + html = article_new.outerHTML; + } + } + message.data.html = html; + ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); } - ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); }); } }).catch(function (err) { ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); }); } + getArticleSrc(message); } if (message.scheme && (![chrome_scheme, 'undefined'].includes(message.scheme) || focus_changed)) { let icon_path = {path: {'128': 'bypass.png'}}; diff --git a/changelog.txt b/changelog.txt index cc0fc26f..50daf41c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ Changelog Bypass Paywalls Clean - Firefox Updates (install signed xpi-file): https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/releases Post-release +Fix The Diplomat (magazine) * v3.4.9.0 (2023-12-31) Add Business Insider Nederland diff --git a/contentScript.js b/contentScript.js index 62441cd8..961925a9 100644 --- a/contentScript.js +++ b/contentScript.js @@ -3139,7 +3139,7 @@ else if (matchDomain('thetimes.co.uk')) { let paywall = document.querySelector('div#paywall-portal-article-footer'); if (paywall && !url.includes('?shareToken=')) { removeDOMElement(paywall); - getArchive(url, 'article:not([id])'); + getArchive(url, 'article#article-main'); window.setTimeout(function () { let headings = document.querySelectorAll('div > div[role="heading"]'); for (let elem of headings) @@ -5022,14 +5022,9 @@ else if (matchDomain('thedailybeast.com')) { else if (matchDomain('thediplomat.com')) { if (matchDomain('magazine.thediplomat.com')) { - csDoneOnce = true; - for (let n = 0; n < 5; n++) { - setTimeout(function () { - let preview = document.querySelector('article.dpl-preview'); - if (preview) - preview.classList.remove('dpl-preview'); - }, n * 500); - } + let preview = document.querySelector('article.dpl-preview'); + if (preview) + preview.classList.remove('dpl-preview'); } } @@ -5886,13 +5881,13 @@ function clearPaywall(paywall, paywall_action) { } } -function getGoogleWebcache(url, paywall_sel, paywall_action = '', article_sel, func_post = '', article_new_sel = article_sel) { +function getGoogleWebcache(url, paywall_sel, paywall_action = '', selector, func_post = '', selector_source = selector) { let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url.split(/[#\?]/)[0]; let paywall = document.querySelectorAll(paywall_sel); if (paywall.length) { clearPaywall(paywall, paywall_action); csDoneOnce = true; - replaceDomElementExt(url_cache, true, false, article_sel, '', article_new_sel); + replaceDomElementExt(url_cache, true, false, selector, '', selector_source); if (func_post) { window.setTimeout(function () { func_post(); @@ -5907,6 +5902,9 @@ function getArchive(url, selector, text_fail = '', selector_source = selector, s } function replaceDomElementExt(url, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) { + let article = document.querySelector(selector); + if (!article) + return; if (proxy) { if (!text_fail) { if (url.startsWith('https://webcache.googleusercontent.com')) @@ -5946,7 +5944,7 @@ function getSelectorLevel(selector) { function replaceDomElementExtSrc(url, url_src, html, proxy, base64, selector, text_fail = '', selector_source = selector, selector_archive = selector) { let article = document.querySelector(selector); if (html) { - if (base64) { + if (!proxy && base64) { html = decode_utf8(atob(html)); selector_source = 'body'; } @@ -6136,7 +6134,9 @@ function externalLink(domains, ext_url_templ, url, text_fail = 'BPC > Full artic text_fail_div.id = 'bpc_archive'; text_fail_div.setAttribute('style', 'margin: 20px; font-size: 20px; font-weight: bold; color: red;'); let parser = new DOMParser(); - text_fail = text_fail.replace(/\[([^\]]+)\]/g, "$1"); + text_fail = text_fail.replace(/\[(?[^\]]+)\]/g, function (match, url) { + return "" + new URL(url).hostname + ""; + }); let doc = parser.parseFromString('' + text_fail + '', 'text/html'); let elem = doc.querySelector('span'); text_fail_div.appendChild(elem); diff --git a/custom/manifest.json b/custom/manifest.json index 2586c98b..e52b84d2 100644 --- a/custom/manifest.json +++ b/custom/manifest.json @@ -51,5 +51,5 @@ "webRequestBlocking", "*://*/*" ], - "version": "3.4.9.0" + "version": "3.4.9.1" } diff --git a/custom/sites_custom.json b/custom/sites_custom.json index 90ad395c..a8b16d04 100644 --- a/custom/sites_custom.json +++ b/custom/sites_custom.json @@ -189,6 +189,12 @@ "block_regex": "\\.eviemagazine\\.com\\/api\\/trpc\\/post\\.paywall", "domain": "eviemagazine.com" }, + "Ewmagazine.nl": { + "add_ext_link": "div.paywall|div.entry-content", + "add_ext_link_type": "archive.is", + "allow_cookies": 1, + "domain": "ewmagazine.nl" + }, "Faithfullymagazine.com": { "allow_cookies": 1, "domain": "faithfullymagazine.com", diff --git a/manifest.json b/manifest.json index 6f7c4dad..32f328a7 100644 --- a/manifest.json +++ b/manifest.json @@ -827,5 +827,5 @@ "*://archive.vn/*", "*://webcache.googleusercontent.com/*" ], - "version": "3.4.9.0" + "version": "3.4.9.1" } diff --git a/sites.js b/sites.js index e2324aee..570f3434 100644 --- a/sites.js +++ b/sites.js @@ -2948,4 +2948,4 @@ var fr_groupe_ebra_nofix_domains = ['bienpublic.com', 'dna.fr', 'estrepublicain. var fr_indigo_nofix_domains = ['africaintelligence.com', 'africaintelligence.fr', 'glitz.paris', 'intelligenceonline.com', 'intelligenceonline.fr', 'lalettre.fr']; var it_gedi_nofix_domains = ['gelocal.it', 'limesonline.com']; var nl_mediahuis_region_nofix_domains = ['gooieneemlander.nl', 'haarlemsdagblad.nl', 'ijmuidercourant.nl', 'leidschdagblad.nl', 'noordhollandsdagblad.nl']; -var nofix_sites = ['11freunde.de', 'aamulehti.fi', 'aftenposten.no', 'aftonbladet.se', 'allgaeuer-zeitung.de', 'asahi.com', 'asiatimes.com', 'autosport.com', 'aviationweek.com', 'badische-zeitung.de', 'bloomberglaw.com', 'bloombergtax.com', 'bnn.de', 'borsen.dk', 'businessinsider.de', 'businessinsider.jp', 'businesslive.co.za', 'businesstimes.com.sg', 'caixin.com', 'caixinglobal.com', 'caravanmagazine.in', 'catalyst-journal.com', 'chegg.com', 'codesports.com.au', 'compactmag.com', 'courrierinternational.com', 'coursehero.com', 'deutsche-wirtschafts-nachrichten.de', 'die-glocke.de', 'dn.no', 'dn.se', 'elordenmundial.com', 'entrepreneur.com', 'epw.in', 'expresso.pt', 'falter.at', 'finance.si', 'ftchinese.com', 'ftchineselive.com', 'gamestar.de', 'geo.de', 'golem.de', 'gp.se', 'handelsblatt.com', 'hbrchina.org', 'hbrfrance.fr', 'heise.de', 'hln.be', 'hs.fi', 'ilsole24ore.com', 'information.dk', 'investors.com', 'iltalehti.fi', 'jacobin.com', 'jeuneafrique.com', 'jungefreiheit.de', 'kleinezeitung.at', 'lavie.fr', 'lavozdegalicia.es', 'law360.co.uk', 'law360.com', 'le1hebdo.fr', 'leconomiste.com', 'lefilmfrancais.com', 'lequipe.fr', 'lesjours.fr', 'letemps.ch', 'liberation.fr', 'limburger.nl', 'main-echo.de', 'mainpost.de', 'manager-magazin.de', 'medianama.com', 'mediapart.fr', 'milanofinanza.it', 'mittelbayerische.de', 'monde-diplomatique.fr', 'mondediplo.com', 'money.it', 'moneycontrol.com', 'moodys.com', 'morningstar.com', 'moz.de', 'nachrichten.at', 'nationaljournal.com', 'nature.com', 'nbr.co.nz', 'newslaundry.com', 'nn.de', 'nwzonline.de', 'observador.pt', 'ouest-france.fr', 'philonomist.com', 'pnp.de', 'politicopro.com', 'politiken.dk', 'pressreader.com', 'publico.pt', 'quillette.com', 'republic.ru', 'rheinpfalz.de', 'risk.net', 'rnz.de', 'saechsische.de', 'schwarzwaelder-bote.de', 'sciencedirect.com', 'springer.com', 'statnews.com', 'stern.de', 'stimme.de', 'straitstimes.com', 'stratfor.com', 'streetinsider.com', 'substack.com', 'suedkurier.de', 'swp.de', 'techcrunch.com', 'the-ken.com', 'theinformation.com', 'theinitium.com', 'themorningcontext.com', 'theparisreview.org', 'thestar.com.my', 'thewirechina.com', 'weltwoche.ch', 'weltwoche.de', 'wissenschaft.de', 'wiwo.de', 'worldpoliticsreview.com', 'ynet.co.il'].concat(be_mediahuis_nofix_domains, de_funke_medien_nofix_domains, de_rp_aachen_medien_nofix_domains, fr_groupe_ebra_nofix_domains, fr_indigo_nofix_domains, it_gedi_nofix_domains, nl_mediahuis_region_nofix_domains); +var nofix_sites = ['11freunde.de', 'aamulehti.fi', 'aftenposten.no', 'aftonbladet.se', 'allgaeuer-zeitung.de', 'asahi.com', 'asiatimes.com', 'autosport.com', 'aviationweek.com', 'badische-zeitung.de', 'bloomberglaw.com', 'bloombergtax.com', 'bnn.de', 'borsen.dk', 'businessinsider.de', 'businessinsider.jp', 'businesslive.co.za', 'businesstimes.com.sg', 'caixin.com', 'caixinglobal.com', 'caravanmagazine.in', 'catalyst-journal.com', 'chegg.com', 'codesports.com.au', 'compactmag.com', 'courrierinternational.com', 'coursehero.com', 'deutsche-wirtschafts-nachrichten.de', 'die-glocke.de', 'dn.no', 'dn.se', 'elordenmundial.com', 'entrepreneur.com', 'epw.in', 'expresso.pt', 'falter.at', 'finance.si', 'ftchinese.com', 'ftchineselive.com', 'gamestar.de', 'geo.de', 'golem.de', 'gp.se', 'handelsblatt.com', 'hbrarabic.com', 'hbrchina.org', 'hbrfrance.fr', 'heise.de', 'hln.be', 'hs.fi', 'ilsole24ore.com', 'information.dk', 'investors.com', 'iltalehti.fi', 'jacobin.com', 'jeuneafrique.com', 'jungefreiheit.de', 'kleinezeitung.at', 'lavie.fr', 'lavozdegalicia.es', 'law360.co.uk', 'law360.com', 'le1hebdo.fr', 'leconomiste.com', 'lefilmfrancais.com', 'lequipe.fr', 'lesjours.fr', 'letemps.ch', 'liberation.fr', 'limburger.nl', 'main-echo.de', 'mainpost.de', 'manager-magazin.de', 'medianama.com', 'mediapart.fr', 'milanofinanza.it', 'mittelbayerische.de', 'monde-diplomatique.fr', 'mondediplo.com', 'money.it', 'moneycontrol.com', 'moodys.com', 'morningstar.com', 'moz.de', 'nachrichten.at', 'nationaljournal.com', 'nature.com', 'nbr.co.nz', 'news24.com', 'newslaundry.com', 'nn.de', 'nwzonline.de', 'observador.pt', 'ouest-france.fr', 'philonomist.com', 'pnp.de', 'politicopro.com', 'politiken.dk', 'pressreader.com', 'publico.pt', 'quillette.com', 'republic.ru', 'rheinpfalz.de', 'risk.net', 'rnz.de', 'saechsische.de', 'schwarzwaelder-bote.de', 'sciencedirect.com', 'springer.com', 'statnews.com', 'stern.de', 'stimme.de', 'straitstimes.com', 'stratfor.com', 'streetinsider.com', 'substack.com', 'suedkurier.de', 'swp.de', 'techcrunch.com', 'the-ken.com', 'theinformation.com', 'theinitium.com', 'themorningcontext.com', 'theparisreview.org', 'thestar.com.my', 'thewirechina.com', 'weltwoche.ch', 'weltwoche.de', 'wissenschaft.de', 'wiwo.de', 'worldpoliticsreview.com', 'ynet.co.il'].concat(be_mediahuis_nofix_domains, de_funke_medien_nofix_domains, de_rp_aachen_medien_nofix_domains, fr_groupe_ebra_nofix_domains, fr_indigo_nofix_domains, it_gedi_nofix_domains, nl_mediahuis_region_nofix_domains);