Update custom sites (block regex for default sites)

master
magnolia1234 2021-10-19 19:38:33 +02:00
parent 7dd0680a5a
commit 354d992665
4 changed files with 17 additions and 24 deletions

View File

@ -426,6 +426,7 @@ var blockedRegexes = {
'wn.de': /cdn\.ampproject\.org\/v\d\/amp-(ad|subscriptions)-.+\.js/, 'wn.de': /cdn\.ampproject\.org\/v\d\/amp-(ad|subscriptions)-.+\.js/,
'wsj.com': /(cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent|subscriptions)-.+\.js|cdn\.cxense\.com\/)/ 'wsj.com': /(cdn\.ampproject\.org\/v\d\/amp-(access|ad|consent|subscriptions)-.+\.js|cdn\.cxense\.com\/)/
}; };
var blockedRegexesCustom = {};
var amp_unhide = []; var amp_unhide = [];
@ -724,12 +725,10 @@ ext_api.storage.local.get({
block_js_custom.push(domainVar); block_js_custom.push(domainVar);
if (sites_custom[key]['block_javascript_ext'] > 0) if (sites_custom[key]['block_javascript_ext'] > 0)
block_js_custom_ext.push(domainVar); 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']) { if (sites_custom[key]['block_regex'].match(/^\/.+\/$/))
if (sites_custom[key]['block_regex'].match(/^\/.+\/$/)) sites_custom[key]['block_regex'] = sites_custom[key]['block_regex'].replace(/(^\/|\/$)/g, '');
sites_custom[key]['block_regex'] = sites_custom[key]['block_regex'].replace(/(^\/|\/$)/g, ''); blockedRegexesCustom[domainVar] = new RegExp(sites_custom[key]['block_regex']);
blockedRegexes[domainVar] = new RegExp(sites_custom[key]['block_regex']);
}
} }
if (sites_custom[key]['amp_unhide'] > 0) if (sites_custom[key]['amp_unhide'] > 0)
amp_unhide.push(domainVar); amp_unhide.push(domainVar);
@ -812,6 +811,7 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
use_twitter_referer = use_twitter_referer_default.slice(); use_twitter_referer = use_twitter_referer_default.slice();
block_js_custom = []; block_js_custom = [];
block_js_custom_ext = []; block_js_custom_ext = [];
blockedRegexesCustom = {};
amp_unhide = []; amp_unhide = [];
for (let key in sites_custom) { for (let key in sites_custom) {
var domainVar = sites_custom[key]['domain'].toLowerCase(); var domainVar = sites_custom[key]['domain'].toLowerCase();
@ -844,20 +844,13 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
if (sites_custom[key]['block_javascript_ext'] > 0) { if (sites_custom[key]['block_javascript_ext'] > 0) {
block_js_custom_ext.push(domainVar); 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']) { if (sites_custom[key]['block_regex'].match(/^\/.+\/$/))
if (sites_custom[key]['block_regex'].match(/^\/.+\/$/)) sites_custom[key]['block_regex'] = sites_custom[key]['block_regex'].replace(/(^\/|\/$)/g, '');
sites_custom[key]['block_regex'] = sites_custom[key]['block_regex'].replace(/(^\/|\/$)/g, ''); blockedRegexesCustom[domainVar] = new RegExp(sites_custom[key]['block_regex']);
blockedRegexes[domainVar] = new RegExp(sites_custom[key]['block_regex']);
} else {
if (blockedRegexes[domainVar])
delete blockedRegexes[domainVar];
}
} }
if (sites_custom[key]['amp_unhide'] > 0) { if (sites_custom[key]['amp_unhide'] > 0) {
amp_unhide.push(domainVar); amp_unhide.push(domainVar);
} else {
amp_unhide.splice(amp_unhide.indexOf(domainVar), 1);
} }
switch (sites_custom[key]['referer']) { switch (sites_custom[key]['referer']) {
case 'facebook': case 'facebook':
@ -1245,11 +1238,10 @@ ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
// check for blocked regular expression: domain enabled, match regex, block on an internal or external regex // check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
var blockedDomains = Object.keys(blockedRegexes); var blockedDomains = Object.keys(blockedRegexes);
var domain = matchUrlDomain(blockedDomains, header_referer); var domain = matchUrlDomain(blockedDomains, header_referer);
var block_regex = true; var blockedDomainsCustom = Object.keys(blockedRegexesCustom);
if (domain && details.url.match(blockedRegexes[domain]) && isSiteEnabled({url: header_referer})) { var domainCustom = matchUrlDomain(blockedDomainsCustom, header_referer);
if (block_regex) if (((domain && details.url.match(blockedRegexes[domain])) || (domainCustom && details.url.match(blockedRegexesCustom[domainCustom]))) && isSiteEnabled({url: header_referer}))
return { cancel: true }; return { cancel: true };
}
// load toggleIcon.js (icon for dark or incognito mode in Chrome)) // load toggleIcon.js (icon for dark or incognito mode in Chrome))
if (typeof browser !== 'object' && ['main_frame', 'xmlhttprequest'].includes(details.type)) { if (typeof browser !== 'object' && ['main_frame', 'xmlhttprequest'].includes(details.type)) {

View File

@ -7,6 +7,7 @@ Fix Business Standard
Fix Il Tirreno (GElocal.it) Fix Il Tirreno (GElocal.it)
Fix Financial Times (amp) Fix Financial Times (amp)
Fix Trouw.nl (timing) Fix Trouw.nl (timing)
Update custom sites (block regex for default sites)
* v2.4.0.0 (2021-10-17) * v2.4.0.0 (2021-10-17)
Add Westfaelische Nachrichten (Germany) Add Westfaelische Nachrichten (Germany)

View File

@ -39,5 +39,5 @@
"webRequestBlocking", "webRequestBlocking",
"<all_urls>" "<all_urls>"
], ],
"version": "2.4.0.1" "version": "2.4.0.2"
} }

View File

@ -544,5 +544,5 @@
"*://*.wallkit.net/*", "*://*.wallkit.net/*",
"*://*.wsj.net/*" "*://*.wsj.net/*"
], ],
"version": "2.4.0.1" "version": "2.4.0.2"
} }