From 12976ed26b818b9751ef06b9fc496b59bf4dd28d Mon Sep 17 00:00:00 2001
From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com>
Date: Fri, 24 Dec 2021 08:32:21 +0100
Subject: [PATCH] Remove Algemeen Dagblad (now regional only)
---
README.md | 4 +--
background.js | 8 ++---
changelog.txt | 1 +
contentScript.js | 62 +++++++++++++++++++++++----------------
manifest.json | 1 -
options/options_custom.js | 14 ++++++---
sites.js | 13 ++++----
7 files changed, 59 insertions(+), 44 deletions(-)
diff --git a/README.md b/README.md
index b23ad78..7289d04 100755
--- a/README.md
+++ b/README.md
@@ -489,7 +489,7 @@ Grouped in options:\
[Vrij Nederland](https://www.nl.nl)
Grouped in options:\
-[Algemeen Dagblad](https://www.ad.nl) and regional ADR sites like
+Algemeen Dagblad Regional (ADR) sites like
[BN DeStem](https://www.bndestem.nl) -
[Brabants Dagblad](https://www.bd.nl) -
[Eindhovens Dagblad](https://www.ed.nl) -
@@ -667,7 +667,7 @@ Grouped in options:\
[La Estrella de Valparaíso](https://www.estrellavalpo.cl) -
[La Segunda](https://digital.lasegunda.com) -
[La Tercera](https://www.latercera.com)
-#### Columbia
+##### Columbia
[El Espectador](https://www.elespectador.com)
##### Mexico
[Mexico News Daily](https://mexiconewsdaily.com)
diff --git a/background.js b/background.js
index 51f3ad1..3d61f2c 100755
--- a/background.js
+++ b/background.js
@@ -943,7 +943,7 @@ if (matchUrlDomain(change_headers, details.url) && !['font', 'image', 'styleshee
if (tabId !== -1) {
ext_api.tabs.get(tabId, function (currentTab) {
- if ((currentTab && isSiteEnabled(currentTab)) || medium_custom_domain || au_swm_site) {
+ if (!ext_api.runtime.lastError && currentTab && (isSiteEnabled(currentTab) || medium_custom_domain || au_swm_site)) {
if (currentTab.url !== currentTabUrl) {
csDone = false;
currentTabUrl = currentTab.url;
@@ -1018,7 +1018,7 @@ if (matchUrlDomain(change_headers, details.url) && !['font', 'image', 'styleshee
// extraInfoSpec is ['blocking', 'requestHeaders'] + possible 'extraHeaders'
ext_api.tabs.onUpdated.addListener(function (tabId, info, tab) { updateBadge(tab); });
-ext_api.tabs.onActivated.addListener(function (activeInfo) { ext_api.tabs.get(activeInfo.tabId, updateBadge); });
+ext_api.tabs.onActivated.addListener(function (activeInfo) { if (activeInfo.tabId) ext_api.tabs.get(activeInfo.tabId, updateBadge); });
function updateBadge(activeTab) {
if (ext_api.runtime.lastError || !activeTab)
@@ -1144,9 +1144,7 @@ function remove_cookies_fn(domainVar, exclusions = false) {
active: true,
currentWindow: true
}, function (tabs) {
- if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
- if (ext_api.runtime.lastError)
- return;
+ if (!ext_api.runtime.lastError && tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
let tabId = tabs[0].id;
let storeId = '0';
for (let store of cookieStores) {
diff --git a/changelog.txt b/changelog.txt
index c19863b..4d9a8c0 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -5,6 +5,7 @@ Post-release
Add El Espectador (Columbia)
Add ESPN USA (news only)
Add Les Inrockuptibles (France)
+Remove Algemeen Dagblad (now regional only)
Fix Helsingin Sanomat (dynamic)
Fix Lequipe.fr (json)
Fix The Diplomat (cookies)
diff --git a/contentScript.js b/contentScript.js
index 4c36739..ec4e4b9 100755
--- a/contentScript.js
+++ b/contentScript.js
@@ -69,7 +69,7 @@ function amp_iframes_replace(weblink = false) {
}
}
-function amp_unhide_subscr_section(amp_ads_sel = 'amp-ad, .ad', amp_iframe_link = false) {
+function amp_unhide_subscr_section(amp_ads_sel = 'amp-ad, .ad', replace_iframes = true, amp_iframe_link = false) {
let preview = document.querySelector('[subscriptions-section="content-not-granted"]');
removeDOMElement(preview);
let subscr_section = document.querySelectorAll('[subscriptions-section="content"]');
@@ -77,10 +77,11 @@ function amp_unhide_subscr_section(amp_ads_sel = 'amp-ad, .ad', amp_iframe_link
elem.removeAttribute('subscriptions-section');
let amp_ads = document.querySelectorAll(amp_ads_sel);
removeDOMElement(...amp_ads);
- amp_iframes_replace(amp_iframe_link);
+ if (replace_iframes)
+ amp_iframes_replace(amp_iframe_link);
}
-function amp_unhide_access_hide(amp_access = '', amp_access_not = '', amp_ads_sel = 'amp-ad, .ad', amp_iframe_link = false) {
+function amp_unhide_access_hide(amp_access = '', amp_access_not = '', amp_ads_sel = 'amp-ad, .ad', replace_iframes = true, amp_iframe_link = false) {
let access_hide = document.querySelectorAll('[amp-access' + amp_access + '][amp-access-hide]');
for (elem of access_hide)
elem.removeAttribute('amp-access-hide');
@@ -90,7 +91,8 @@ function amp_unhide_access_hide(amp_access = '', amp_access_not = '', amp_ads_se
}
let amp_ads = document.querySelectorAll(amp_ads_sel);
removeDOMElement(...amp_ads);
- amp_iframes_replace(amp_iframe_link);
+ if (replace_iframes)
+ amp_iframes_replace(amp_iframe_link);
}
// custom sites: try to unhide text on amp-page
@@ -208,9 +210,9 @@ else {
removeDOMElement(header_ads);
let amp_ads_sel = 'amp-ad, amp-embed, [id^="ad-mrec-"], .story-ad-container';
if (window.location.hostname.startsWith('amp.')) {
- amp_unhide_access_hide('="access AND subscriber"', '', amp_ads_sel, true);
+ amp_unhide_access_hide('="access AND subscriber"', '', amp_ads_sel, true, true);
} else if (window.location.href.includes('?amp')) {
- amp_unhide_access_hide('="subscriber AND status=\'logged-in\'"', '', amp_ads_sel, true);
+ amp_unhide_access_hide('="subscriber AND status=\'logged-in\'"', '', amp_ads_sel, true, true);
}
} else {
// Australian Seven West Media
@@ -1114,20 +1116,24 @@ else if (matchDomain('lequipe.fr')) {
if (par_type) {
article.innerHTML = '';
let json_split = json.split('__type:' + par_type);
+ if (json_split.length < 5) {
+ par_type = json.split('content:"')[1].split('"},{__type:')[1].split(',')[0];
+ json_split = json.split('__type:' + par_type);
+ }
let article_dom;
let article_text = '';
let parser = new DOMParser();
for (let par of json_split) {
par = par.split('}')[0];
if (par.includes(',content:')) {
- par = par.split(',content:')[1].split(',layout')[0];
- if (par) {
- if (par.includes(',title:')) {
- let par_split_title = par.split(',title:').map(x => x.replace(/^\"|\"$/g, ''));
- par = par_split_title[0];
- if (par_split_title[1].length > 2)
- par = '' + par_split_title[1] + '
' + par;
- }
+ let content = par.split(',content:')[1].split('",')[0];
+ let par_title = '';
+ if (par.includes(',title:'))
+ par_title = par.split(',title:')[1].split(',')[0].replace(/^\"|\"$/g, '');
+ if (content) {
+ par = content.replace('class=', '');
+ if (par_title.length > 2)
+ par = '' + par_title + '
' + content;
par = par.replace(/\\u003C/g, '<').replace(/\\u003E/g, '>').replace(/\\u002F/g, '/').replace(/\\"/g, '"').replace(/^\"|\"$/g, '');
article_text += '
' + par + '
'; } @@ -1408,7 +1414,7 @@ else } else if (window.location.hostname.match(/\.(be|nl)$/)) {//belgium/netherlands -if (matchDomain(['ad.nl', 'bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl'])) { +if (matchDomain(['bd.nl', 'ed.nl', 'tubantia.nl', 'bndestem.nl', 'pzc.nl', 'destentor.nl', 'gelderlander.nl'])) { let paywall = document.querySelectorAll('.article__component--paywall-module-notification, .fjs-paywall-notification'); let modal_login = document.querySelector('.modal--login'); removeDOMElement(...paywall, modal_login); @@ -1662,8 +1668,8 @@ if (matchDomain('prospectmagazine.co.uk')) { let paywall = document.querySelector('div.paywall_overlay_blend, div.paywall'); if (paywall) { removeDOMElement(paywall); - let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url.split('//')[1]; - replaceDomElementExt(url_cache, true, false, 'main', 'Failed to load from Google webcache: '); + let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url; + replaceDomElementExt(url_cache, true, false, 'main'); } }); } @@ -1689,11 +1695,12 @@ else if (matchDomain('telegraph.co.uk')) { if (paywall.length) { let truncated_content = document.querySelector('.truncated-content'); removeDOMElement(...paywall, truncated_content); - amp_unhide_access_hide('="c.result=\'ALLOW_ACCESS\'"', '', 'amp-ad, amp-embed'); + amp_unhide_access_hide('="c.result=\'ALLOW_ACCESS\'"', '', 'amp-ad, amp-embed', false); } } else { + let subwall = document.querySelectorAll('[class^="subwall"]'); let ads = document.querySelectorAll('.advert, .commercial-unit'); - removeDOMElement(...ads); + removeDOMElement(...subwall, ...ads); } } @@ -1845,7 +1852,7 @@ else if (matchDomain('valor.globo.com')) { if (paywall) { removeDOMElement(paywall); let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url; - replaceDomElementExt(url_cache, true, false, 'div.protected-content', 'Failed to load from Google webcache: '); + replaceDomElementExt(url_cache, true, false, 'div.protected-content'); } let skeleton_box = document.querySelector('div.glb-skeleton-box'); if (skeleton_box) { @@ -2548,8 +2555,8 @@ else if (matchDomain('newleftreview.org')) { let paywall = document.querySelector('div.promo-wrapper'); if (paywall) { removeDOMElement(paywall); - let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url.split('//')[1]; - replaceDomElementExt(url_cache, true, false, 'div.article-page', 'Failed to load from Google webcache: '); + let url_cache = 'https://webcache.googleusercontent.com/search?q=cache:' + url; + replaceDomElementExt(url_cache, true, false, 'div.article-page'); } }, 500); // Delay (in milliseconds) } @@ -3341,9 +3348,14 @@ function replaceDomElementExt(url, proxy, base64, selector, text_fail = '') { article.parentNode.replaceChild(article_new, article); } }); - } else if (text_fail) { - if (article) { + } else { + if (!text_fail) { + if (url.includes('webcache.googleusercontent.com')) + text_fail = 'BPC > failed to load from Google webcache: ' + } + if (text_fail && article) { let text_fail_div = document.createElement('div'); + text_fail_div.setAttribute('style', 'margin: 0px 50px; font-weight: bold; color: red;'); text_fail_div.appendChild(document.createTextNode(text_fail)); if (proxy) { let a_link = document.createElement('a'); @@ -3362,12 +3374,12 @@ function archiveLink(url) { let archive_url = 'https://archive.today?run=1&url=' + url.split('?')[0]; let text_fail_div = document.createElement('div'); text_fail_div.id = 'bpc_archive'; + text_fail_div.setAttribute('style', 'margin: 20px; font-weight: bold; color:red;'); text_fail_div.appendChild(document.createTextNode('BPC > 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; } diff --git a/manifest.json b/manifest.json index 41d83a9..3e78e7f 100755 --- a/manifest.json +++ b/manifest.json @@ -47,7 +47,6 @@ "*://*.abc.es/*", "*://*.abendblatt.de/*", "*://*.abril.com.br/*", - "*://*.ad.nl/*", "*://*.adage.com/*", "*://*.adelaidenow.com.au/*", "*://*.adweek.com/*", diff --git a/options/options_custom.js b/options/options_custom.js index a129c3a..354b060 100644 --- a/options/options_custom.js +++ b/options/options_custom.js @@ -265,10 +265,16 @@ function renderOptions() { if (add_checkboxes[key]) { inputEl.type = 'checkbox'; inputEl.dataset.value = 1; - } else if (key === 'title') { - inputEl.placeholder = 'Example'; - } else if (key === 'domain') - inputEl.placeholder = 'example.com'; + } else { + let placeholders = { + title: 'Example', + domain: 'example.com', + block_regex: '\\.example\\.com\\/js\\/', + amp_redirect: 'div.paywall' + }; + if (placeholders[key]) + inputEl.placeholder = placeholders[key]; + } labelEl.appendChild(document.createTextNode(' ' + key)); add_sitesEl.appendChild(labelEl); } diff --git a/sites.js b/sites.js index eae90b2..bdd88c0 100755 --- a/sites.js +++ b/sites.js @@ -39,10 +39,9 @@ var defaultSites = { domain: "adweek.com", block_regex: /\.lightboxcdn\.com\// }, - "Algemeen Dagblad (+ regional) (free premium articles only)": { + "Algemeen Dagblad (regional free premium articles only)": { domain: "###_nl_ad_region", group: [ - "ad.nl", "bd.nl", "bndestem.nl", "destentor.nl", @@ -890,11 +889,6 @@ var defaultSites = { block_regex: /\.tinypass\.com\//, useragent: "googlebot" }, - "Le Vif.be": { - domain: "levif.be", - allow_cookies: 1, - block_regex: /(\.levif\.be\/js\/responsive\/rmg(Modal|Paywall)\.js|\.blueconic\.net\/)/ - }, "Le Scienze": { domain: "lescienze.it", group_rule: "###_gr_it_repubblica_domains" @@ -904,6 +898,11 @@ var defaultSites = { allow_cookies: 1, block_regex: /\.poool\.fr\// }, + "Le Vif.be": { + domain: "levif.be", + allow_cookies: 1, + block_regex: /(\.levif\.be\/js\/responsive\/rmg(Modal|Paywall)\.js|\.blueconic\.net\/)/ + }, "Lee Enterprises Group": { domain: "###_usa_lee_ent", group: [