From c602805d41001c8b1d5015561646ddb92db09792 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Tue, 2 Aug 2022 19:05:09 +0200 Subject: [PATCH] Add Standaard.be --- README.md | 1 + background.js | 21 ++++---- changelog.txt | 1 + contentScript.js | 122 +++++++---------------------------------------- manifest.json | 3 +- sites.js | 5 +- 6 files changed, 37 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index a2c290de..d934d5a0 100644 --- a/README.md +++ b/README.md @@ -581,6 +581,7 @@ Grouped in options:\ Grouped in options:\ *Mediahuis Belgiƫ* sites like:\ +[De Standaard](https://www.standaard.be) - [Gazet van Antwerpen](https://www.gva.be) - [Het Belang van Limburg](https://www.hbvl.be) - [Het Nieuwsblad](https://www.nieuwsblad.be)\ diff --git a/background.js b/background.js index 4cfb93c6..806f9b32 100644 --- a/background.js +++ b/background.js @@ -27,6 +27,7 @@ var restrictions = { 'theatlantic.com': /^((?!\/newsletters\.theatlantic\.com\/).)*$/, 'nytimes.com': /^((?!\/timesmachine\.nytimes\.com\/).)*$/, 'science.org': /^((?!\.science\.org\/doi\/).)*$/, + 'standaard.be': /^((?!\.standaard\.be\/plus\/).)*$/, 'timesofindia.com': /\.timesofindia\.com($|\/($|toi-plus(\/.+)?|.+\.cms))/, 'quora.com': /^((?!quora\.com\/search\?q=).)*$/, 'repubblica.it': /^((?!\/video\.repubblica\.it\/).)*$/, @@ -1435,15 +1436,17 @@ ext_api.runtime.onMessage.addListener(function (message, sender) { let parser = new DOMParser(); let doc = parser.parseFromString(html, 'text/html'); let article_new = doc.querySelector(message.data.selector_source); - message.data.html = article_new.outerHTML; - ext_api.tabs.query({ - active: true, - currentWindow: true - }, function (tabs) { - if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { - ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); - } - }); + if (article_new) { + message.data.html = article_new.outerHTML; + ext_api.tabs.query({ + active: true, + currentWindow: true + }, function (tabs) { + if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) { + ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data}); + } + }); + } }); } }).catch(function (err) { diff --git a/changelog.txt b/changelog.txt index 7e8cf637..eeeb1b58 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ Changelog Bypass Paywalls Clean - Firefox Post-release Add Limburger.nl +Add Standaard.be Add SuomenSotilas.fi Add Tagesspiegel.de Redirect Google AMP cache (opt-in to custom sites) diff --git a/contentScript.js b/contentScript.js index 61505bc3..a37c07d1 100644 --- a/contentScript.js +++ b/contentScript.js @@ -1928,113 +1928,25 @@ else if (matchDomain('ftm.nl')) { removeDOMElement(banner_pp); } -else if (matchDomain(['gva.be', 'hbvl.be', 'nieuwsblad.be'])) { +else if (matchDomain(['gva.be', 'hbvl.be', 'nieuwsblad.be', 'standaard.be'])) { + let url = window.location.href; + let article_selector = 'div[data-mht-block="article-detail__article-main"]'; + if (matchDomain('standaard.be')) + article_selector = 'article'; let paywall = document.querySelector('div[data-cj-root="subscription-wall"]'); - if (paywall && dompurify_loaded) { + if (paywall) { removeDOMElement(paywall); - let main_content = document.querySelector('div[data-mht-block="article-detail__article-main"]'); - let json_script = main_content.querySelector('script'); - let json_str = json_script.text.substring(json_script.textContent.indexOf('{')); - try { - let json = JSON.parse(json_str); - if (json) { - let json_text = Object.values(json)[0]['data']['article']['body']; - let parser = new DOMParser(); - let div_content = main_content.querySelector('div'); - let par_elem, par_key, par_li, par_html, par_link; - let head = document.querySelector('head'); - let streamone = false; - let flourish = false; - for (let par of json_text) { - for (let key in par) { - par_elem = document.createElement('p'); - par_key = par[key]; - if (['p', 'subhead'].includes(key)) { - if (par_key.includes('<')) { - par_html = parser.parseFromString('

' + DOMPurify.sanitize(par_key) + '

', 'text/html'); - par_elem = par_html.querySelector('p'); - } else - par_elem.innerText = par_key; - if (key === 'subhead') - par_elem.setAttribute('style', 'font-weight: bold;'); - } else if (key === 'image') { - par_elem = document.createElement('img'); - par_elem.src = par_key.url; - } else if (key === 'bullet_list') { - par_elem = document.createElement('ul'); - for (let bullet of par_key) { - par_html = parser.parseFromString('
  • ' + DOMPurify.sanitize(bullet) + '
  • ', 'text/html'); - par_li = par_html.querySelector('li'); - let bullet_link = par_li.querySelector('a'); - if (bullet_link && bullet_link.href && !bullet_link.innerText) - bullet_link.innerText = bullet_link.href; - par_elem.appendChild(par_li); - } - } else if (key === 'related') { - par_elem = document.createElement('p'); - if (par_key.article && par_key.article.title && par_key.article.webcmsRelativeUrl) { - par_link = document.createElement('a'); - if (par_key.article.label) - par_link.innerText = par_key.article.label; - par_link.innerText += par_key.article.title; - par_link.href = par_key.article.webcmsRelativeUrl; - par_elem.appendChild(par_link); - } - } else if (key === 'iframe_sized') { - par_elem = document.createElement('iframe'); - par_elem.src = par_key.url; - if (par_key.height && par_key.width) { - par_elem.setAttribute('height', par_key.height); - par_elem.setAttribute('width', par_key.width); - } - } else if (key === 'streamone') { - if (!streamone) { - let streamone_script = document.createElement('script'); - streamone_script.setAttribute('src', 'https://shared.mediahuis.be/videoplayers/mediahuis/video-theoplayer.js?v=20220525T184101'); - streamone_script.setAttribute('defer', true); - streamone_script.setAttribute('crossorigin', 'anonymous'); - if (head) - head.appendChild(streamone_script); - streamone = true; - } - let par_key_id = DOMPurify.sanitize(par_key.id); - par_html = parser.parseFromString('
    ', 'text/html'); - par_elem = par_html.querySelector('div'); - } else if (key === 'legacy-ml') { - par_html = parser.parseFromString('
    ' + DOMPurify.sanitize(par_key) + '
    ', 'text/html'); - par_elem = par_html.querySelector('div'); - if (!flourish && par_key.includes('flourish.studio')) { - let flourish_script = document.createElement('script'); - flourish_script.setAttribute('src', 'https://public.flourish.studio/resources/embed.js'); - if (head) - head.appendChild(flourish_script); - flourish = true; - } - } else { - console.log(key); - console.log(par_key); - par_html = parser.parseFromString('

    ' + DOMPurify.sanitize(par_key) + '

    ', 'text/html'); - par_elem = par_html.querySelector('p'); - } - if (!['streamone', 'legacy-ml', 'iframe_sized'].includes(key)) - par_elem.setAttribute('style', 'font-size: 16px;'); - if (par_elem) - div_content.appendChild(par_elem); - } - } - } - } catch (err) { - console.warn('unable to parse text'); - console.warn(err); - } + csDoneOnce = true; + let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url.split('?')[0]; + replaceDomElementExt(url_cache, true, false, article_selector); + window.setTimeout(function () { + let overlay = document.querySelector('div.cj-root'); + removeDOMElement(overlay); + let noscroll = document.querySelector('html.is-dialog-active'); + if (noscroll) + noscroll.classList.remove('is-dialog-active'); + }, 1000); // Delay (in milliseconds) } - window.setTimeout(function () { - let overlay = document.querySelector('div.cj-root'); - removeDOMElement(overlay); - let noscroll = document.querySelector('html.is-dialog-active'); - if (noscroll) - noscroll.classList.remove('is-dialog-active'); - }, 500); // Delay (in milliseconds) } else if (matchDomain(['knack.be', 'kw.be', 'levif.be'])) { @@ -2070,6 +1982,8 @@ else if (matchDomain('limburger.nl')) { let noscroll = document.querySelector('html.is-dialog-active'); if (noscroll) noscroll.classList.remove('is-dialog-active'); + let ads = document.querySelectorAll('div.ad'); + removeDOMElement(...ads); }, 1000); // Delay (in milliseconds) } } diff --git a/manifest.json b/manifest.json index 1c43454d..d6d5b3a5 100644 --- a/manifest.json +++ b/manifest.json @@ -528,6 +528,7 @@ "*://*.spglobal.com/*", "*://*.spiegel.de/*", "*://*.sportico.com/*", + "*://*.standaard.be/*", "*://*.standard.net.au/*", "*://*.star-telegram.com/*", "*://*.staradvertiser.com/*", @@ -699,5 +700,5 @@ "*://gcm.omerlocdn.com/*", "*://webcache.googleusercontent.com/*" ], - "version": "2.7.8.2" + "version": "2.7.8.3" } diff --git a/sites.js b/sites.js index 8b8266db..ebed93ac 100644 --- a/sites.js +++ b/sites.js @@ -1176,7 +1176,8 @@ var defaultSites = { group: [ "gva.be", "hbvl.be", - "nieuwsblad.be" + "nieuwsblad.be", + "standaard.be" ], allow_cookies: 1 }, @@ -2209,4 +2210,4 @@ var no_nhst_media_domains = grouped_sites['###_no_nhst_media']; // sites with no fix (background) var nl_ad_region_domains = ['ad.nl', 'bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl']; -var nofix_sites = ['africaintelligence.com', 'africaintelligence.fr', 'aftenposten.no', 'bild.de', 'borsen.dk', 'businesstimes.com.sg', 'caixin.com', 'caixinglobal.com', 'caravanmagazine.in', 'cnbc.com', 'courrierinternational.com', 'dn.se', 'elordenmundial.com', 'epw.in', 'expresso.pt', 'ftchinese.com', 'gazzetta.it', 'handelsblatt.com', 'hln.be', 'ilmanifesto.it', 'ilsole24ore.com', 'jacobinmag.com', 'jeunesafrique.com', 'kurier.at', 'lavozdegalicia.es', 'leconomiste.com', 'lefigaro.fr', 'lemonde.fr', 'lepoint.fr', 'liberation.fr', 'mediapart.fr', 'milanofinanza.it', 'mondediplo.com', 'moneycontrol.com', 'nieuwsblad.be', 'nknews.org', 'ouest-france.fr', 'politiken.de', 'publico.pt', 'republic.ru', 'rp-online.de', 'standaard.be', 'statnews.com', 'stern.de', 'straitstimes.com', 'sueddeutsche.de', 'tagesanzeiger.ch', 'the-ken.com', 'theinformation.com', ' themorningcontext.com', 'theparisreview.org', 'thewirechina.com', 'welt.de', 'wiwo.de', 'ynet.co.il'].concat(nl_ad_region_domains); +var nofix_sites = ['africaintelligence.com', 'africaintelligence.fr', 'aftenposten.no', 'bild.de', 'borsen.dk', 'businesstimes.com.sg', 'caixin.com', 'caixinglobal.com', 'caravanmagazine.in', 'cnbc.com', 'courrierinternational.com', 'dn.se', 'elordenmundial.com', 'epw.in', 'expresso.pt', 'ftchinese.com', 'gazzetta.it', 'handelsblatt.com', 'hln.be', 'ilmanifesto.it', 'ilsole24ore.com', 'jacobinmag.com', 'jeunesafrique.com', 'kurier.at', 'lavozdegalicia.es', 'leconomiste.com', 'lefigaro.fr', 'lemonde.fr', 'lepoint.fr', 'liberation.fr', 'mediapart.fr', 'milanofinanza.it', 'mondediplo.com', 'moneycontrol.com', 'nieuwsblad.be', 'nknews.org', 'ouest-france.fr', 'politiken.de', 'publico.pt', 'republic.ru', 'rp-online.de', 'statnews.com', 'stern.de', 'straitstimes.com', 'sueddeutsche.de', 'tagesanzeiger.ch', 'the-ken.com', 'theinformation.com', ' themorningcontext.com', 'theparisreview.org', 'thewirechina.com', 'welt.de', 'wiwo.de', 'ynet.co.il'].concat(nl_ad_region_domains);