Update custom sites (amp unhide)

This commit is contained in:
magnolia1234 2021-10-17 21:15:00 +02:00
parent 9223e7dd4e
commit 531f155666
7 changed files with 71 additions and 36 deletions

View file

@ -640,7 +640,7 @@ Check 'Options'-link in popup-menu and go to custom sites.
\* by default BPC has limited permissions, but you can opt-in to enable custom sites (and also clear cookies/block general paywall-scripts for non-listed sites). You can also just request permissions for the custom sites you added yourself.
By default sites' cookies/local storage are removed after page loads (to bypass article limit).
Also you can enable Googlebot/Bingbot user-agent, disable Javascript for (sub)domain(s)/external sources and/or set the referer (to Facebook, Google or Twitter; ignored when Googlebot is set).
Also you can enable Googlebot/Bingbot user-agent, set the referer (to Facebook, Google or Twitter; ignored when Googlebot is set), disable Javascript for (sub)domain(s)/external sources, block regular expression and/or unhide text on amp-page.
[Example list of custom sites](https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/blob/master/custom/sites_custom.json) or [download list (json)](https://gitlab.com/magnolia1234/bypass-paywalls-firefox-clean/-/raw/master/custom/sites_custom.json)

View file

@ -425,6 +425,8 @@ var blockedRegexes = {
'wsj.com': /(cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent|subscriptions)-.+\.js|cdn\.cxense\.com\/)/
};
var amp_unhide = [];
// grouped domains in sites.js (for options)
// grouped domains (rules only)
@ -726,6 +728,8 @@ ext_api.storage.local.get({
blockedRegexes[domainVar] = new RegExp(sites_custom[key]['block_regex']);
}
}
if (sites_custom[key]['amp_unhide'] > 0)
amp_unhide.push(domainVar);
switch (sites_custom[key]['referer']) {
case 'facebook':
use_facebook_referer.push(domainVar);
@ -805,6 +809,7 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
use_twitter_referer = use_twitter_referer_default.slice();
block_js_custom = [];
block_js_custom_ext = [];
amp_unhide = [];
for (let key in sites_custom) {
var domainVar = sites_custom[key]['domain'].toLowerCase();
if (sites_custom[key]['googlebot'] > 0 && !use_google_bot.includes(domainVar)) {
@ -836,16 +841,21 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
if (sites_custom[key]['block_javascript_ext'] > 0) {
block_js_custom_ext.push(domainVar);
}
if (!(defaultSites_domains.includes(domainVar) && blockedRegexes[domainVar])) {
if (sites_custom[key]['block_regex']) {
if (sites_custom[key]['block_regex'].match(/^\/.+\/$/))
sites_custom[key]['block_regex'] = sites_custom[key]['block_regex'].replace(/(^\/|\/$)/g, '');
blockedRegexes[domainVar] = new RegExp(sites_custom[key]['block_regex']);
} else {
if (blockedRegexes[domainVar])
delete blockedRegexes[domainVar];
}
}
if (!(defaultSites_domains.includes(domainVar) && blockedRegexes[domainVar])) {
if (sites_custom[key]['block_regex']) {
if (sites_custom[key]['block_regex'].match(/^\/.+\/$/))
sites_custom[key]['block_regex'] = sites_custom[key]['block_regex'].replace(/(^\/|\/$)/g, '');
blockedRegexes[domainVar] = new RegExp(sites_custom[key]['block_regex']);
} else {
if (blockedRegexes[domainVar])
delete blockedRegexes[domainVar];
}
}
if (sites_custom[key]['amp_unhide'] > 0) {
amp_unhide.push(domainVar);
} else {
amp_unhide.splice(amp_unhide.indexOf(domainVar), 1);
}
switch (sites_custom[key]['referer']) {
case 'facebook':
use_facebook_referer.push(domainVar);
@ -1272,7 +1282,7 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
let usa_today_site = (matchUrlDomain('gannett-cdn.com', details.url) && matchUrlDomain(['usatoday.com'], header_referer));
allow_ext_source = allow_ext_source || inkl_site || cl_elmerc_site || es_elesp_site || it_repubblica_site || usa_law360_site || usa_mw_site || usa_natgeo_site || usa_today_site;
bpc_amp_site = (matchUrlDomain('cdn.ampproject.org', details.url) && matchUrlDomain(['aachener-zeitung.de', 'asiatimes.com', 'augsburger-allgemeine.de', 'barrons.com', 'belfasttelegraph.co.uk', 'cicero.de', 'cmjornal.pt', 'elpais.com', 'elperiodico.com', 'freiepresse.de', 'handelsblatt.com', 'ilfattoquotidiano.it', 'inc42.com', 'independent.ie', 'irishtimes.com', 'la-croix.com', 'marketwatch.com', 'nationalreview.com', 'noz.de', 'nwzonline.de', 'scmp.com', 'seekingalpha.com', 'shz.de', 'staradvertiser.com', 'sueddeutsche.de', 'svz.de', 'telegraph.co.uk', 'washingtonpost.com', 'westfalen-blatt.de', 'wn.de', 'wsj.com'].concat(au_news_corp_domains, au_nine_domains, de_madsack_domains, es_epiberica_domains, es_grupo_vocento_domains, es_unidad_domains, fr_groupe_ebra_domains, fr_groupe_la_depeche_domains, it_repubblica_domains, usa_mcc_domains, usa_mng_domains, usa_theathletic_domains), header_referer));
bpc_amp_site = (matchUrlDomain('cdn.ampproject.org', details.url) && matchUrlDomain(['aachener-zeitung.de', 'asiatimes.com', 'augsburger-allgemeine.de', 'barrons.com', 'belfasttelegraph.co.uk', 'cicero.de', 'cmjornal.pt', 'elpais.com', 'elperiodico.com', 'freiepresse.de', 'handelsblatt.com', 'ilfattoquotidiano.it', 'inc42.com', 'independent.ie', 'irishtimes.com', 'la-croix.com', 'marketwatch.com', 'nationalreview.com', 'noz.de', 'nwzonline.de', 'scmp.com', 'seekingalpha.com', 'shz.de', 'staradvertiser.com', 'sueddeutsche.de', 'svz.de', 'telegraph.co.uk', 'washingtonpost.com', 'westfalen-blatt.de', 'wn.de', 'wsj.com'].concat(amp_unhide, au_news_corp_domains, au_nine_domains, de_madsack_domains, es_epiberica_domains, es_grupo_vocento_domains, es_unidad_domains, fr_groupe_ebra_domains, fr_groupe_la_depeche_domains, it_repubblica_domains, usa_mcc_domains, usa_mng_domains, usa_theathletic_domains), header_referer));
}
if (!isSiteEnabled(details) && !allow_ext_source && !bpc_amp_site && !au_swm_site) {
@ -1383,26 +1393,27 @@ if (matchUrlDomain(change_headers, details.url) && (!['font', 'image', 'styleshe
let lib_file = 'lib/empty.js';
if (matchUrlDomain(['bloomberg.com', 'cicero.de', 'economictimes.com', 'lesechos.fr', 'newleftreview.org', 'newyorker.com', 'nzherald.co.nz', 'prospectmagazine.co.uk', 'sudouest.fr', 'techinasia.com', 'valor.globo.com', 'washingtonpost.com'].concat(nl_mediahuis_region_domains, no_nhst_media_domains, usa_theathletic_domains), currentTabUrl))
lib_file = 'lib/purify.min.js';
var bg2csData = {
optin_setcookie: optin_setcookie
};
var bg2csData = {
optin_setcookie: optin_setcookie,
amp_unhide: matchUrlDomain(amp_unhide, currentTabUrl)
};
ext_api.tabs.executeScript(tabId, {
code: 'var bg2csData = ' + JSON.stringify(bg2csData) + ';'
}, function () {
ext_api.tabs.executeScript(tabId, {
code: 'var bg2csData = ' + JSON.stringify(bg2csData) + ';'
file: lib_file,
runAt: 'document_start'
}, function () {
ext_api.tabs.executeScript(tabId, {
file: lib_file,
file: 'contentScript.js',
runAt: 'document_start'
}, function () {
ext_api.tabs.executeScript(tabId, {
file: 'contentScript.js',
runAt: 'document_start'
}, function (res) {
if (ext_api.runtime.lastError || res[0]) {
return;
}
})
});
}, function (res) {
if (ext_api.runtime.lastError || res[0]) {
return;
}
})
});
});
}
}
});

View file

@ -8,7 +8,7 @@ Fix GElocal.it
Fix National Review
Fix Ruhr Nachrichten (amp)
Fix Tech in Asia (visual story)
Update custom sites (block regex & add import)
Update custom sites (block regex, amp unhide & add imported)
Update options: enable new sites by default
* v2.3.9.0 (2021-10-10)

View file

@ -32,14 +32,34 @@ if (!matchDomain(arr_localstorage_hold)) {
var div_bpc_done = document.querySelector('div#bpc_done');
if (!div_bpc_done) {
var bg2csData;
// check for opt-in confirmation (from background.js)
if (bg2csData.optin_setcookie) {
if ((bg2csData !== undefined) && bg2csData.optin_setcookie) {
if (domain = matchDomain(['belfasttelegraph.co.uk', 'independent.ie'])) {
if (!cookieExists('subscriber'))
setCookie('subscriber', '{"subscriptionStatus": true}', domain, '/', 14);
}
}
// custom sites: try to unhide text on amp-page
if ((bg2csData !== undefined) && bg2csData.amp_unhide) {
window.setTimeout(function () {
let amp_page = document.querySelector('script[src^="https://cdn.ampproject.org/"]');
if (amp_page) {
let preview = document.querySelector('[subscriptions-section="content-not-granted"]');
removeDOMElement(preview);
let subscr_section = document.querySelectorAll('[subscriptions-section="content"]');
for (let elem of subscr_section)
elem.removeAttribute('subscriptions-section');
}
let content_hidden = document.querySelectorAll('[amp-access][amp-access-hide]');
for (elem of content_hidden)
elem.removeAttribute('amp-access-hide');
let amp_ads = document.querySelectorAll('amp-ad');
removeDOMElement(...amp_ads);
}, 500); // Delay (in milliseconds)
}
// Content workarounds/domain
if (matchDomain(['medium.com', 'towardsdatascience.com']) || document.querySelector('script[src^="https://cdn-client.medium.com/"]')) {
@ -856,7 +876,7 @@ else if ((domain = matchDomain(fr_groupe_ebra_domains)) && window.location.href.
}, 500); // Delay (in milliseconds)
}
} else {
let amp_access_hide = document.querySelector('[amp-access-hide]');
let amp_access_hide = document.querySelector('[amp-access][amp-access-hide]');
if (amp_access_hide) {
let not_access_section = document.querySelector('section[amp-access="NOT access"]');
removeDOMElement(not_access_section);
@ -2864,9 +2884,9 @@ else
csDone = true;
}
if (csDone || csDoneOnce) {
if ((csDone && (bg2csData !== undefined)) || csDoneOnce) {
addDivBpcDone();
if (csDone)
if (csDone && (bg2csData !== undefined) && !bg2csData.amp_unhide)
ext_api.runtime.sendMessage({csDone: true});
}

View file

@ -556,5 +556,5 @@
"*://*.wallkit.net/*",
"*://*.wsj.net/*"
],
"version": "2.3.9.7"
"version": "2.3.9.8"
}

View file

@ -19,7 +19,8 @@
<body>
<h2>Custom Sites</h2>
<div style="width:90%;">
To add a new site, enter an unique title/domain (without www.). Select options for useragent (like Googlebot), block Javascript (on (sub)domain(s) of site and/or external domains), block regular expression (ignored when default site blocks regex) and/or set referer (ignored when Googlebot is set).<br>
To add a new site, enter an unique title/domain (without www.).<br>
Select options for useragent (like Googlebot), set referer (ignored when Googlebot is set), block Javascript (on (sub)domain(s) of site and/or external domains), block regular expression (ignored when default site blocks regex) and/or unhide text on amp-page.<br>
Custom sites are enabled automatically in <small><button><a href="options.html" style="text-decoration:none;color:inherit">Options</a></button></small> (cookies will be removed by default unless you enable allow_cookies; cookie settings for default sites are ignored).<br>
If you want to use custom sites (for non-listed sites) enable it in <small><button><a href="optin/opt-in.html" style="text-decoration:none;color:inherit">Opt-in</a></button></small>
<strong>Custom sites enabled: <span id="custom-enabled"></span></strong><br>

View file

@ -189,6 +189,7 @@ function edit_options() {
document.querySelector('input[data-key="block_javascript"]').checked = (edit_site.block_javascript > 0);
document.querySelector('input[data-key="block_javascript_ext"]').checked = (edit_site.block_javascript_ext > 0);
document.querySelector('input[data-key="block_regex"]').value = edit_site.block_regex ? edit_site.block_regex : '';
document.querySelector('input[data-key="amp_unhide"]').checked = (edit_site.amp_unhide > 0);
document.querySelector('select[data-key="referer"]').selectedIndex = referer_options.indexOf(edit_site.referer);
});
}
@ -246,7 +247,8 @@ function renderOptions() {
'allow_cookies': 1,
'block_javascript': 1,
'block_javascript_ext': 1,
'block_regex': 0
'block_regex': 0,
'amp_unhide': 1
};
for (var key in add_checkboxes) {
labelEl = document.createElement('label');
@ -306,7 +308,8 @@ function renderOptions() {
(sites_custom[key]['block_javascript_ext'] > 0 ? ' | block javascript ext' : '') +
(sites_custom[key]['block_regex'] ? ' | block regex' : '') +
(sites_custom[key]['useragent'] ? ' | useragent: ' + sites_custom[key]['useragent'] : '') +
(sites_custom[key]['referer'] ? ' | referer: ' + sites_custom[key]['referer'] : '');
(sites_custom[key]['referer'] ? ' | referer: ' + sites_custom[key]['referer'] : '') +
(sites_custom[key]['amp_unhide'] > 0 ? ' | amp_unhide' : '');
optionEl.value = key;
selectEl.add(optionEl);
}