2017-07-08 17:40:29 +00:00
|
|
|
'use strict';
|
2020-05-01 10:58:36 +00:00
|
|
|
var ext_api = (typeof browser === 'object') ? browser : chrome;
|
2021-11-07 07:47:42 +00:00
|
|
|
var url_loc = (typeof browser === 'object') ? 'firefox' : 'chrome';
|
2021-10-16 06:58:31 +00:00
|
|
|
var manifestData = ext_api.runtime.getManifest();
|
|
|
|
var ext_name = manifestData.name;
|
|
|
|
var ext_version = manifestData.version;
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2022-10-22 08:55:10 +00:00
|
|
|
const cs_limit_except = ['elespanol.com', 'faz.net', 'globeandmail.com', 'nationalgeographic.com'].concat(de_westfalen_medien_domains);
|
2022-10-24 17:07:37 +00:00
|
|
|
const dompurify_sites = ['arcinfo.ch', 'asiatimes.com', 'bloomberg.com', 'cicero.de', 'ilmanifesto.it', 'iltalehti.fi', 'iltirreno.it', 'ipolitics.ca', 'italiaoggi.it', 'lanuovasardegna.it', 'lequipe.fr', 'lesechos.fr', 'marianne.net', 'newleftreview.org', 'newscientist.com', 'nzherald.co.nz', 'outlookbusiness.com', 'prospectmagazine.co.uk', 'spectator.co.uk', 'stratfor.com', 'techinasia.com', 'timesofindia.com', 'valor.globo.com', 'vn.nl'].concat(nl_mediahuis_region_domains);
|
2020-12-04 15:14:23 +00:00
|
|
|
var currentTabUrl = '';
|
|
|
|
var csDone = false;
|
2021-10-17 13:16:44 +00:00
|
|
|
var optin_setcookie = false;
|
2021-11-10 16:46:22 +00:00
|
|
|
var optin_update = true;
|
2022-01-05 19:40:38 +00:00
|
|
|
var blocked_referer = false;
|
2020-12-04 15:14:23 +00:00
|
|
|
|
2020-02-25 21:47:05 +00:00
|
|
|
// defaultSites are loaded from sites.js at installation extension
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2022-01-05 19:40:38 +00:00
|
|
|
var restrictions = {
|
2021-08-03 18:03:11 +00:00
|
|
|
'bloomberg.com': /^((?!\.bloomberg\.com\/news\/terminal\/).)*$/,
|
2022-07-01 13:47:47 +00:00
|
|
|
'dailywire.com': /^((?!\.dailywire\.com\/(episode|show|videos|watch)).)*$/,
|
2022-01-05 19:40:38 +00:00
|
|
|
'economictimes.com': /\.economictimes\.com($|\/($|(__assets|prime)(\/.+)?|.+\.cms))/,
|
2021-03-13 15:49:58 +00:00
|
|
|
'elespanol.com': /^((?!\/cronicaglobal\.elespanol\.com\/).)*$/,
|
2022-05-22 14:09:51 +00:00
|
|
|
'espn.com': /^((?!espn\.com\/watch).)*$/,
|
2022-09-04 07:13:36 +00:00
|
|
|
'esquire.com': /^((?!\/classic\.esquire\.com\/).)*$/,
|
2022-01-05 19:40:38 +00:00
|
|
|
'faz.net': /^((?!\.faz\.net\/aktuell\/(\?switchfaznet)?$).)*$/,
|
2021-11-12 12:34:31 +00:00
|
|
|
'lastampa.it': /^((?!\/video\.lastampa\.it\/).)*$/,
|
2022-09-15 10:17:16 +00:00
|
|
|
'lequipe.fr': /^((?!\.lequipe\.fr\/.+\/les-notes\/).)*$/,
|
2022-09-26 14:44:11 +00:00
|
|
|
'nknews.org': /^((?!nknews\.org\/pro\/).)*$/,
|
2022-07-10 06:35:21 +00:00
|
|
|
'nytimes.com': /^((?!\/timesmachine\.nytimes\.com\/).)*$/,
|
2022-01-04 20:57:52 +00:00
|
|
|
'science.org': /^((?!\.science\.org\/doi\/).)*$/,
|
2022-01-05 19:40:38 +00:00
|
|
|
'timesofindia.com': /\.timesofindia\.com($|\/($|toi-plus(\/.+)?|.+\.cms))/,
|
2020-05-27 15:11:31 +00:00
|
|
|
'quora.com': /^((?!quora\.com\/search\?q=).)*$/,
|
2021-11-12 12:34:31 +00:00
|
|
|
'repubblica.it': /^((?!\/video\.repubblica\.it\/).)*$/,
|
2022-01-05 19:40:38 +00:00
|
|
|
'seekingalpha.com': /\/seekingalpha\.com($|\/($|(amp\/)?(article|news)\/|samw\/))/,
|
2021-08-10 15:24:03 +00:00
|
|
|
'statista.com': /^((?!\.statista\.com\/(outlook|study)\/).)*$/,
|
2021-02-15 18:06:51 +00:00
|
|
|
'techinasia.com': /\.techinasia\.com\/.+/,
|
2022-08-06 05:49:29 +00:00
|
|
|
'theatlantic.com': /^((?!\/newsletters\.theatlantic\.com\/).)*$/,
|
2022-08-10 17:19:51 +00:00
|
|
|
'thetimes.co.uk': /^((?!epaper\.thetimes\.co\.uk).)*$/,
|
2022-08-18 19:56:52 +00:00
|
|
|
'timeshighereducation.com': /\.timeshighereducation\.com\/((features|news|people)\/|.+((\w)+(\-)+){3,}.+|sites\/default\/files\/)/,
|
|
|
|
'uol.com.br': /^((?!(conta|email)\.uol\.com\.br).)*$/,
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2021-12-19 10:13:00 +00:00
|
|
|
for (let domain of au_news_corp_domains)
|
|
|
|
restrictions[domain] = new RegExp('^((?!todayspaper\\.' + domain.replace(/\./g, '\\.') + '\\/).)*$');
|
2022-01-22 17:37:56 +00:00
|
|
|
if (typeof browser !== 'object') {
|
2022-04-21 17:52:47 +00:00
|
|
|
for (let domain of [])
|
2022-01-22 17:37:56 +00:00
|
|
|
restrictions[domain] = new RegExp('((\\/|\\.)' + domain.replace(/\./g, '\\.') + '\\/$|' + restrictions[domain].toString().replace(/(^\/|\/$)/g, '') + ')');
|
|
|
|
}
|
2021-12-19 10:13:00 +00:00
|
|
|
|
2021-11-04 17:50:19 +00:00
|
|
|
// Don't remove cookies before/after page load
|
|
|
|
var allow_cookies = [];
|
|
|
|
var remove_cookies = [];
|
|
|
|
// select specific cookie(s) to hold/drop from remove_cookies domains
|
|
|
|
var remove_cookies_select_hold, remove_cookies_select_drop;
|
|
|
|
|
|
|
|
// Set User-Agent
|
|
|
|
var use_google_bot, use_bing_bot;
|
|
|
|
// Set Referer
|
|
|
|
var use_facebook_referer, use_google_referer, use_twitter_referer;
|
|
|
|
// Set random IP-address
|
2021-12-21 16:36:48 +00:00
|
|
|
var random_ip = {};
|
|
|
|
var use_random_ip = [];
|
2021-11-04 17:50:19 +00:00
|
|
|
// concat all sites with change of headers (useragent, referer or random ip)
|
|
|
|
var change_headers;
|
2021-01-12 20:46:50 +00:00
|
|
|
|
2020-01-28 22:06:25 +00:00
|
|
|
// block paywall-scripts individually
|
2021-11-04 17:50:19 +00:00
|
|
|
var blockedRegexes = {};
|
|
|
|
|
|
|
|
// unhide text on amp-page
|
|
|
|
var amp_unhide;
|
2021-11-17 16:45:33 +00:00
|
|
|
// redirect to amp-page
|
|
|
|
var amp_redirect;
|
2021-11-18 16:55:25 +00:00
|
|
|
// code for contentScript
|
|
|
|
var cs_code;
|
2022-02-22 18:23:36 +00:00
|
|
|
// load text from json
|
|
|
|
var ld_json;
|
2022-08-01 18:49:58 +00:00
|
|
|
// load text from Google webcache
|
|
|
|
var ld_google_webcache;
|
2021-11-04 17:50:19 +00:00
|
|
|
|
|
|
|
// custom: block javascript
|
|
|
|
var block_js_custom = [];
|
|
|
|
var block_js_custom_ext = [];
|
|
|
|
|
|
|
|
function initSetRules() {
|
|
|
|
allow_cookies = [];
|
|
|
|
remove_cookies = [];
|
|
|
|
remove_cookies_select_drop = {};
|
|
|
|
remove_cookies_select_hold = {};
|
|
|
|
use_google_bot = [];
|
|
|
|
use_bing_bot = [];
|
|
|
|
use_facebook_referer = [];
|
|
|
|
use_google_referer = [];
|
|
|
|
use_twitter_referer = [];
|
2021-12-21 16:36:48 +00:00
|
|
|
random_ip = {};
|
2021-11-04 17:50:19 +00:00
|
|
|
change_headers = [];
|
|
|
|
amp_unhide = [];
|
2021-11-17 16:45:33 +00:00
|
|
|
amp_redirect = {};
|
2021-11-18 16:55:25 +00:00
|
|
|
cs_code = {};
|
2022-02-22 18:23:36 +00:00
|
|
|
ld_json = {};
|
2022-08-01 18:49:58 +00:00
|
|
|
ld_google_webcache = {};
|
2021-11-04 17:50:19 +00:00
|
|
|
block_js_custom = [];
|
|
|
|
block_js_custom_ext = [];
|
|
|
|
blockedRegexes = {};
|
2022-08-17 06:49:28 +00:00
|
|
|
init_custom_domains();
|
2021-11-04 17:50:19 +00:00
|
|
|
}
|
2020-07-06 17:30:48 +00:00
|
|
|
|
2020-11-02 17:52:40 +00:00
|
|
|
const userAgentDesktopG = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
|
|
|
|
const userAgentMobileG = "Chrome/80.0.3987.92 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)"
|
|
|
|
|
|
|
|
const userAgentDesktopB = "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
|
|
|
|
const userAgentMobileB = "Chrome/80.0.3987.92 Mobile Safari/537.36 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
|
2019-04-06 23:34:30 +00:00
|
|
|
|
2017-07-08 17:40:29 +00:00
|
|
|
var enabledSites = [];
|
2020-08-20 17:01:12 +00:00
|
|
|
var disabledSites = [];
|
2021-11-04 17:50:19 +00:00
|
|
|
var optionSites = {};
|
2020-08-20 17:01:12 +00:00
|
|
|
var customSites = {};
|
|
|
|
var customSites_domains = [];
|
2021-11-07 07:47:42 +00:00
|
|
|
var updatedSites = {};
|
2021-11-14 12:40:46 +00:00
|
|
|
var updatedSites_new = [];
|
2021-12-02 17:02:07 +00:00
|
|
|
var updatedSites_domains_new = [];
|
2021-01-05 17:53:59 +00:00
|
|
|
var excludedSites = [];
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2020-01-28 22:06:25 +00:00
|
|
|
function setDefaultOptions() {
|
2020-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.set({
|
2021-03-26 12:05:20 +00:00
|
|
|
sites: filterObject(defaultSites, function (val, key) {
|
2022-05-17 18:30:08 +00:00
|
|
|
return val.domain && !val.domain.match(/^(###$|#options_(disable|optin)_)/)
|
2021-11-04 17:50:19 +00:00
|
|
|
},
|
|
|
|
function (val, key) {
|
|
|
|
return [key, val.domain]
|
2021-03-26 12:05:20 +00:00
|
|
|
})
|
2020-10-24 14:38:01 +00:00
|
|
|
}, function () {
|
2020-03-25 18:31:28 +00:00
|
|
|
ext_api.runtime.openOptionsPage();
|
2020-01-28 22:06:25 +00:00
|
|
|
});
|
2020-03-27 18:02:27 +00:00
|
|
|
}
|
2020-03-25 18:31:28 +00:00
|
|
|
|
2021-11-07 07:47:42 +00:00
|
|
|
function check_sites_updated() {
|
2022-02-22 16:35:16 +00:00
|
|
|
let sites_updated_json = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/-/raw/master/sites_updated.json';
|
|
|
|
fetch(sites_updated_json)
|
2021-11-07 07:47:42 +00:00
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
2021-11-14 12:40:46 +00:00
|
|
|
expandSiteRules(json, true);
|
2021-11-07 07:47:42 +00:00
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites_updated: json
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}).catch(function (err) {
|
|
|
|
false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_rules(sites, sites_updated, sites_custom) {
|
2021-11-04 17:50:19 +00:00
|
|
|
initSetRules();
|
|
|
|
for (let site in sites) {
|
|
|
|
let site_domain = sites[site].toLowerCase();
|
|
|
|
let custom = false;
|
|
|
|
if (!site_domain.match(/^(###$|#options_)/)) {
|
|
|
|
let rule = {};
|
2022-04-13 15:48:30 +00:00
|
|
|
let site_default = defaultSites.hasOwnProperty(site) ? site : Object.keys(defaultSites).find(default_key => compareKey(default_key, site));
|
|
|
|
if (site_default) {
|
|
|
|
rule = defaultSites[site_default];
|
2022-04-19 19:37:22 +00:00
|
|
|
if (sites_updated.hasOwnProperty(site_default) && !sites_updated[site_default].new_site)
|
2022-04-13 15:48:30 +00:00
|
|
|
rule = sites_updated[site_default];
|
2021-11-13 10:43:09 +00:00
|
|
|
} else if (sites_updated.hasOwnProperty(site)) { // updated (new) sites
|
|
|
|
rule = sites_updated[site];
|
|
|
|
} else if (sites_custom.hasOwnProperty(site)) { // custom (new) sites
|
2021-11-04 17:50:19 +00:00
|
|
|
rule = sites_custom[site];
|
|
|
|
custom = true;
|
2021-11-07 08:34:11 +00:00
|
|
|
} else
|
|
|
|
continue;
|
2021-11-04 17:50:19 +00:00
|
|
|
let domains = [site_domain];
|
|
|
|
let group = false;
|
|
|
|
if (rule.hasOwnProperty('group')) {
|
|
|
|
domains = rule.group;
|
|
|
|
group = true;
|
|
|
|
}
|
|
|
|
let rule_default = {};
|
|
|
|
if (rule.hasOwnProperty('exception')) {
|
|
|
|
for (let key in rule)
|
|
|
|
rule_default[key] = rule[key];
|
|
|
|
}
|
|
|
|
for (let domain of domains) {
|
|
|
|
let custom_in_group = false;
|
|
|
|
if (rule_default.hasOwnProperty('exception')) {
|
2022-01-23 17:14:07 +00:00
|
|
|
let exception_rule = rule_default.exception.filter(x => domain === x.domain || (typeof x.domain !== 'string' && x.domain.includes(domain)));
|
2021-11-04 17:50:19 +00:00
|
|
|
if (exception_rule.length > 0)
|
|
|
|
rule = exception_rule[0];
|
|
|
|
else
|
|
|
|
rule = rule_default;
|
|
|
|
}
|
|
|
|
// custom domain for default site(group)
|
|
|
|
if (!custom) {
|
|
|
|
let isCustomSite = matchDomain(customSites_domains, domain);
|
|
|
|
let customSite_title = isCustomSite ? Object.keys(customSites).find(key => customSites[key].domain === isCustomSite) : '';
|
|
|
|
if (customSite_title) {
|
|
|
|
// add default block_regex
|
|
|
|
let block_regex_default = '';
|
|
|
|
if (rule.hasOwnProperty('block_regex'))
|
|
|
|
block_regex_default = rule.block_regex;
|
2021-11-07 07:47:42 +00:00
|
|
|
rule = {};
|
|
|
|
for (let key in sites_custom[customSite_title])
|
|
|
|
rule[key] = sites_custom[customSite_title][key];
|
2021-11-04 17:50:19 +00:00
|
|
|
if (block_regex_default) {
|
|
|
|
if (rule.hasOwnProperty('block_regex')) {
|
|
|
|
if (block_regex_default instanceof RegExp)
|
|
|
|
block_regex_default = block_regex_default.source;
|
|
|
|
rule.block_regex = '(' + block_regex_default + '|' + rule.block_regex.replace(/(^\/|\/$)/g, '') + ')';
|
|
|
|
} else
|
|
|
|
rule.block_regex = block_regex_default;
|
|
|
|
}
|
|
|
|
if (group)
|
|
|
|
custom_in_group = true;
|
|
|
|
else
|
|
|
|
custom = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addCookieRules(rule, custom || custom_in_group);
|
|
|
|
|
|
|
|
if (rule.allow_cookies > 0 && !allow_cookies.includes(domain))
|
|
|
|
allow_cookies.push(domain);
|
|
|
|
if (rule.remove_cookies > 0 && !remove_cookies.includes(domain))
|
|
|
|
remove_cookies.push(domain);
|
|
|
|
if (rule.hasOwnProperty('remove_cookies_select_drop'))
|
|
|
|
remove_cookies_select_drop[domain] = rule.remove_cookies_select_drop;
|
|
|
|
if (rule.hasOwnProperty('remove_cookies_select_hold'))
|
|
|
|
remove_cookies_select_hold[domain] = rule.remove_cookies_select_hold;
|
|
|
|
if (rule.hasOwnProperty('block_regex')) {
|
|
|
|
if (rule.block_regex instanceof RegExp)
|
|
|
|
blockedRegexes[domain] = rule.block_regex;
|
2022-01-13 16:22:38 +00:00
|
|
|
else {
|
|
|
|
try {
|
2022-08-03 18:12:52 +00:00
|
|
|
blockedRegexes[domain] = new RegExp(rule.block_regex.replace(/{domain}/g, domain.replace(/\./g, '\\.').replace(/(^\/|\/$)/g, '')));
|
2022-01-13 16:22:38 +00:00
|
|
|
} catch (e) {
|
|
|
|
false;
|
|
|
|
}
|
|
|
|
}
|
2021-11-04 17:50:19 +00:00
|
|
|
}
|
|
|
|
if (rule.useragent) {
|
|
|
|
switch (rule.useragent) {
|
|
|
|
case 'googlebot':
|
|
|
|
if (!use_google_bot.includes(domain))
|
|
|
|
use_google_bot.push(domain);
|
|
|
|
break;
|
|
|
|
case 'bingbot':
|
|
|
|
if (!use_bing_bot.includes(domain))
|
|
|
|
use_bing_bot.push(domain);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rule.referer) {
|
|
|
|
switch (rule.referer) {
|
|
|
|
case 'facebook':
|
|
|
|
if (!use_facebook_referer.includes(domain))
|
|
|
|
use_facebook_referer.push(domain);
|
|
|
|
break;
|
|
|
|
case 'google':
|
|
|
|
if (!use_google_referer.includes(domain))
|
|
|
|
use_google_referer.push(domain);
|
|
|
|
break;
|
|
|
|
case 'twitter':
|
|
|
|
if (!use_twitter_referer.includes(domain))
|
|
|
|
use_twitter_referer.push(domain);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-12-21 16:36:48 +00:00
|
|
|
if (rule.random_ip) {
|
|
|
|
random_ip[domain] = rule.random_ip;
|
|
|
|
}
|
2021-11-17 16:45:33 +00:00
|
|
|
// updated
|
|
|
|
if (rule.amp_redirect)
|
2021-12-22 19:28:59 +00:00
|
|
|
amp_redirect[domain] = rule.amp_redirect.paywall ? rule.amp_redirect : {paywall: rule.amp_redirect};
|
2021-11-18 16:55:25 +00:00
|
|
|
if (rule.cs_code)
|
|
|
|
cs_code[domain] = rule.cs_code;
|
2021-11-04 17:50:19 +00:00
|
|
|
// custom
|
|
|
|
if (rule.googlebot > 0)
|
|
|
|
use_google_bot.push(domain);
|
|
|
|
if (rule.block_javascript > 0)
|
|
|
|
block_js_custom.push(domain);
|
|
|
|
if (rule.block_javascript_ext > 0)
|
|
|
|
block_js_custom_ext.push(domain);
|
|
|
|
if (rule.amp_unhide > 0)
|
|
|
|
amp_unhide.push(domain);
|
2022-02-22 18:23:36 +00:00
|
|
|
if (rule.ld_json) {
|
|
|
|
ld_json[domain] = rule.ld_json;
|
|
|
|
if (!dompurify_sites.includes(domain))
|
|
|
|
dompurify_sites.push(domain);
|
|
|
|
}
|
2022-08-01 18:49:58 +00:00
|
|
|
if (rule.ld_google_webcache) {
|
|
|
|
ld_google_webcache[domain] = rule.ld_google_webcache;
|
|
|
|
if (!dompurify_sites.includes(domain))
|
|
|
|
dompurify_sites.push(domain);
|
|
|
|
}
|
2021-11-04 17:50:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-21 16:36:48 +00:00
|
|
|
use_random_ip = Object.keys(random_ip);
|
2021-11-04 17:50:19 +00:00
|
|
|
change_headers = use_google_bot.concat(use_bing_bot, use_facebook_referer, use_google_referer, use_twitter_referer, use_random_ip);
|
|
|
|
disableJavascriptOnListedSites();
|
|
|
|
}
|
|
|
|
|
2021-11-07 07:47:42 +00:00
|
|
|
// add grouped sites to en/disabledSites (and exclude sites)
|
2021-11-04 17:50:19 +00:00
|
|
|
function add_grouped_enabled_domains(groups) {
|
2020-12-07 17:10:59 +00:00
|
|
|
for (let key in groups) {
|
|
|
|
if (enabledSites.includes(key))
|
|
|
|
enabledSites = enabledSites.concat(groups[key]);
|
|
|
|
else
|
|
|
|
disabledSites = disabledSites.concat(groups[key]);
|
2021-01-05 17:53:59 +00:00
|
|
|
for (let site of excludedSites) {
|
|
|
|
if (enabledSites.includes(site)) {
|
|
|
|
enabledSites.splice(enabledSites.indexOf(site), 1);
|
|
|
|
disabledSites.push(site);
|
|
|
|
}
|
|
|
|
}
|
2020-12-07 17:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 17:50:19 +00:00
|
|
|
// Get the enabled sites (from local storage) & set_rules for sites
|
2020-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.get({
|
2020-10-24 14:38:01 +00:00
|
|
|
sites: {},
|
2021-11-14 12:40:46 +00:00
|
|
|
sites_default: Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/)),
|
2021-01-05 17:53:59 +00:00
|
|
|
sites_custom: {},
|
2021-11-07 07:47:42 +00:00
|
|
|
sites_updated: {},
|
2021-10-16 06:58:31 +00:00
|
|
|
sites_excluded: [],
|
2021-10-17 13:16:44 +00:00
|
|
|
ext_version_old: '2.3.9.0',
|
2021-11-10 16:46:22 +00:00
|
|
|
optIn: false,
|
|
|
|
optInUpdate: true
|
2020-02-28 15:23:17 +00:00
|
|
|
}, function (items) {
|
2020-10-24 14:38:01 +00:00
|
|
|
var sites = items.sites;
|
2021-11-07 07:47:42 +00:00
|
|
|
optionSites = sites;
|
2021-10-15 13:11:10 +00:00
|
|
|
var sites_default = items.sites_default;
|
2021-11-13 10:43:09 +00:00
|
|
|
customSites = items.sites_custom;
|
|
|
|
customSites_domains = Object.values(customSites).map(x => x.domain);
|
|
|
|
updatedSites = items.sites_updated;
|
2021-12-02 17:02:07 +00:00
|
|
|
updatedSites_domains_new = Object.values(updatedSites).filter(x => (x.domain && !defaultSites_domains.includes(x.domain) || x.group)).map(x => x.group ? x.group.filter(y => !defaultSites_domains.includes(y)) : x.domain).flat();
|
2021-10-17 13:16:44 +00:00
|
|
|
var ext_version_old = items.ext_version_old;
|
|
|
|
optin_setcookie = items.optIn;
|
2021-11-10 16:46:22 +00:00
|
|
|
optin_update = items.optInUpdate;
|
2021-01-05 17:53:59 +00:00
|
|
|
excludedSites = items.sites_excluded;
|
2020-02-28 15:23:17 +00:00
|
|
|
|
2021-11-06 08:24:44 +00:00
|
|
|
enabledSites = Object.values(sites).filter(function (val) {
|
|
|
|
return (val !== '' && val !== '###');
|
|
|
|
}).map(function (val) {
|
|
|
|
return val.toLowerCase();
|
2021-06-22 19:54:00 +00:00
|
|
|
});
|
2021-10-15 13:11:10 +00:00
|
|
|
|
|
|
|
// Enable new sites by default (opt-in)
|
2021-11-14 12:40:46 +00:00
|
|
|
updatedSites_new = Object.keys(updatedSites).filter(x => updatedSites[x].domain && !defaultSites_domains.includes(updatedSites[x].domain));
|
|
|
|
for (let site_updated_new of updatedSites_new)
|
|
|
|
defaultSites[site_updated_new] = updatedSites[site_updated_new];
|
|
|
|
if (ext_version > ext_version_old || updatedSites_new.length > 0) {
|
2021-10-16 06:58:31 +00:00
|
|
|
if (enabledSites.includes('#options_enable_new_sites')) {
|
2021-12-04 11:12:43 +00:00
|
|
|
let sites_new = Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/) && !sites_default.some(key => compareKey(key, x)));
|
2021-11-14 12:40:46 +00:00
|
|
|
for (let site_new of sites_new)
|
2021-11-13 10:43:09 +00:00
|
|
|
sites[site_new] = defaultSites[site_new].domain;
|
2021-10-16 06:58:31 +00:00
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites: sites
|
|
|
|
});
|
2022-08-10 17:48:00 +00:00
|
|
|
} else {
|
|
|
|
ext_api.management.getSelf(function (result) {
|
|
|
|
if ((result.installType === 'development' || (result.installType !== 'development' && !enabledSites.includes('#options_on_update')))) {
|
2022-10-12 17:53:12 +00:00
|
|
|
let new_groups = ['###_de_rp_medien', '###_de_westfalen_medien', '###_es_grupo_vocento', '###_es_unidad', '###_fr_gcf', '###_it_gedi', '###_nl_dpg_media', '###_usa_cbj', '###_usa_chronicle', '###_usa_genomeweb'];
|
2022-10-04 16:43:23 +00:00
|
|
|
let open_options = new_groups.some(group => !enabledSites.includes(group) && grouped_sites[group].some(domain => enabledSites.includes(domain) && !customSites_domains.includes(domain)))
|
|
|
|
|| (!enabledSites.includes('uol.com.br') && (enabledSites.includes('crusoe.uol.com.br') || enabledSites.includes('###_br_folha')))
|
|
|
|
|| (!enabledSites.includes('iltalehti.fi') && enabledSites('###_fi_alma_talent'));
|
2022-08-10 17:48:00 +00:00
|
|
|
if (open_options)
|
|
|
|
ext_api.runtime.openOptionsPage();
|
|
|
|
}
|
|
|
|
});
|
2021-10-15 13:11:10 +00:00
|
|
|
}
|
2021-11-14 12:40:46 +00:00
|
|
|
sites_default = Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/));
|
2021-10-15 13:11:10 +00:00
|
|
|
ext_api.storage.local.set({
|
2021-10-16 06:58:31 +00:00
|
|
|
sites_default: sites_default,
|
|
|
|
ext_version_old: ext_version
|
2021-10-15 13:11:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-24 08:01:13 +00:00
|
|
|
disabledSites = defaultSites_grouped_domains.concat(customSites_domains).filter(x => !enabledSites.includes(x));
|
2021-11-04 17:50:19 +00:00
|
|
|
add_grouped_enabled_domains(grouped_sites);
|
2021-11-07 07:47:42 +00:00
|
|
|
set_rules(sites, updatedSites, customSites);
|
2022-09-09 12:30:20 +00:00
|
|
|
if (enabledSites.includes('#options_optin_update_rules')) {
|
2021-11-07 07:47:42 +00:00
|
|
|
check_sites_updated();
|
2022-09-09 12:30:20 +00:00
|
|
|
sites_custom_ext_json = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/-/raw/master/custom/sites_custom.json';
|
|
|
|
}
|
2022-09-11 18:12:12 +00:00
|
|
|
check_sites_custom_ext();
|
2021-11-10 16:46:22 +00:00
|
|
|
if (optin_update)
|
|
|
|
check_update();
|
2020-10-24 14:38:01 +00:00
|
|
|
});
|
2020-02-28 15:23:17 +00:00
|
|
|
|
2020-10-24 14:38:01 +00:00
|
|
|
// Listen for changes to options
|
|
|
|
ext_api.storage.onChanged.addListener(function (changes, namespace) {
|
2020-10-31 19:06:38 +00:00
|
|
|
if (namespace === 'sync')
|
|
|
|
return;
|
2020-11-10 17:15:18 +00:00
|
|
|
for (let key in changes) {
|
2020-10-24 14:38:01 +00:00
|
|
|
var storageChange = changes[key];
|
|
|
|
if (key === 'sites') {
|
|
|
|
var sites = storageChange.newValue;
|
2021-11-04 17:50:19 +00:00
|
|
|
optionSites = sites;
|
2021-11-06 08:24:44 +00:00
|
|
|
enabledSites = Object.values(sites).filter(function (val) {
|
|
|
|
return (val !== '' && val !== '###');
|
|
|
|
}).map(function (val) {
|
|
|
|
return val.toLowerCase();
|
2020-02-28 15:23:17 +00:00
|
|
|
});
|
2022-04-24 08:01:13 +00:00
|
|
|
disabledSites = defaultSites_grouped_domains.concat(customSites_domains).filter(x => !enabledSites.includes(x));
|
2021-11-04 17:50:19 +00:00
|
|
|
add_grouped_enabled_domains(grouped_sites);
|
2021-11-07 07:47:42 +00:00
|
|
|
set_rules(sites, updatedSites, customSites);
|
2020-02-28 15:23:17 +00:00
|
|
|
}
|
2020-10-24 14:38:01 +00:00
|
|
|
if (key === 'sites_custom') {
|
2020-11-29 11:08:21 +00:00
|
|
|
var sites_custom = storageChange.newValue ? storageChange.newValue : {};
|
|
|
|
var sites_custom_old = storageChange.oldValue ? storageChange.oldValue : {};
|
2020-10-24 14:38:01 +00:00
|
|
|
customSites = sites_custom;
|
|
|
|
customSites_domains = Object.values(sites_custom).map(x => x.domain);
|
2021-11-04 17:50:19 +00:00
|
|
|
|
|
|
|
// add/remove custom sites in options (not for default site(group))
|
|
|
|
var sites_custom_added = Object.keys(sites_custom).filter(x => !Object.keys(sites_custom_old).includes(x) && !defaultSites.hasOwnProperty(x) && !defaultSites_domains.includes(sites_custom[x].domain));
|
|
|
|
var sites_custom_removed = Object.keys(sites_custom_old).filter(x => !Object.keys(sites_custom).includes(x) && !defaultSites.hasOwnProperty(x) && !defaultSites_domains.includes(sites_custom_old[x].domain));
|
|
|
|
|
2020-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.get({
|
2020-10-24 14:38:01 +00:00
|
|
|
sites: {}
|
|
|
|
}, function (items) {
|
|
|
|
var sites = items.sites;
|
2021-11-04 17:50:19 +00:00
|
|
|
if (sites_custom_added.concat(sites_custom_removed).length > 0) {
|
|
|
|
for (let key of sites_custom_added)
|
|
|
|
sites[key] = sites_custom[key].domain;
|
|
|
|
for (let key of sites_custom_removed)
|
|
|
|
delete sites[key];
|
|
|
|
|
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites: sites
|
|
|
|
}, function () {
|
|
|
|
true;
|
|
|
|
});
|
|
|
|
} else
|
2021-11-07 07:47:42 +00:00
|
|
|
set_rules(sites, updatedSites, customSites);
|
2020-10-24 14:38:01 +00:00
|
|
|
});
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
2021-11-07 07:47:42 +00:00
|
|
|
if (key === 'sites_updated') {
|
|
|
|
var sites_updated = storageChange.newValue ? storageChange.newValue : {};
|
|
|
|
updatedSites = sites_updated;
|
2021-12-02 17:02:07 +00:00
|
|
|
updatedSites_domains_new = Object.values(updatedSites).filter(x => (x.domain && !defaultSites_domains.includes(x.domain) || x.group)).map(x => x.group ? x.group.filter(y => !defaultSites_domains.includes(y)) : x.domain).flat();
|
2021-11-14 12:40:46 +00:00
|
|
|
updatedSites_new = Object.keys(updatedSites).filter(x => updatedSites[x].domain && !defaultSites_domains.includes(updatedSites[x].domain));
|
|
|
|
if (updatedSites_new.length > 0) {
|
|
|
|
if (enabledSites.includes('#options_enable_new_sites')) {
|
|
|
|
for (let site_updated_new of updatedSites_new)
|
|
|
|
optionSites[site_updated_new] = updatedSites[site_updated_new].domain;
|
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites: optionSites
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
set_rules(optionSites, updatedSites, customSites);
|
2021-11-07 07:47:42 +00:00
|
|
|
}
|
2021-01-05 17:53:59 +00:00
|
|
|
if (key === 'sites_excluded') {
|
|
|
|
var sites_excluded = storageChange.newValue ? storageChange.newValue : [];
|
|
|
|
var sites_excluded_old = storageChange.oldValue ? storageChange.oldValue : [];
|
|
|
|
excludedSites = sites_excluded;
|
|
|
|
|
|
|
|
// add/remove excluded sites in en/disabledSites
|
|
|
|
var sites_excluded_added = sites_excluded.filter(x => !sites_excluded_old.includes(x));
|
|
|
|
var sites_excluded_removed = sites_excluded_old.filter(x => !sites_excluded.includes(x));
|
|
|
|
|
|
|
|
for (let site of sites_excluded_added) {
|
|
|
|
if (enabledSites.includes(site)) {
|
|
|
|
enabledSites.splice(enabledSites.indexOf(site), 1);
|
|
|
|
disabledSites.push(site);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let site of sites_excluded_removed) {
|
|
|
|
if (disabledSites.includes(site)) {
|
|
|
|
disabledSites.splice(disabledSites.indexOf(site), 1);
|
|
|
|
enabledSites.push(site);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-16 06:58:31 +00:00
|
|
|
if (key === 'ext_version_new') {
|
|
|
|
ext_version_new = storageChange.newValue;
|
2021-05-02 05:51:25 +00:00
|
|
|
}
|
2021-10-17 13:16:44 +00:00
|
|
|
if (key === 'optIn') {
|
|
|
|
optin_setcookie = storageChange.newValue;
|
|
|
|
}
|
2021-11-10 16:46:22 +00:00
|
|
|
if (key === 'optInUpdate') {
|
|
|
|
optin_update = storageChange.newValue;
|
|
|
|
}
|
2021-01-05 17:53:59 +00:00
|
|
|
// reset disableJavascriptOnListedSites eventListener
|
|
|
|
ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites);
|
|
|
|
ext_api.webRequest.handlerBehaviorChanged();
|
|
|
|
|
2020-10-24 14:38:01 +00:00
|
|
|
// Refresh the current tab
|
2021-06-12 16:19:48 +00:00
|
|
|
refreshCurrentTab();
|
2020-10-24 14:38:01 +00:00
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Set and show default options on install
|
2020-03-25 18:31:28 +00:00
|
|
|
ext_api.runtime.onInstalled.addListener(function (details) {
|
2017-07-08 17:40:29 +00:00
|
|
|
if (details.reason == "install") {
|
2020-02-25 21:47:05 +00:00
|
|
|
setDefaultOptions();
|
2017-07-08 17:40:29 +00:00
|
|
|
} else if (details.reason == "update") {
|
2020-08-22 17:21:32 +00:00
|
|
|
ext_api.management.getSelf(function (result) {
|
2020-08-26 15:53:26 +00:00
|
|
|
if (enabledSites.includes('#options_on_update') && result.installType !== 'development')
|
2020-08-22 17:21:32 +00:00
|
|
|
ext_api.runtime.openOptionsPage(); // User updated extension (non-developer mode)
|
|
|
|
});
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-03 17:15:21 +00:00
|
|
|
// repubblica.it bypass
|
2020-03-25 18:31:28 +00:00
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
2020-03-03 17:15:21 +00:00
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var updatedUrl = details.url.replace('/pwa/', '/ws/detail/');
|
|
|
|
return { redirectUrl: updatedUrl };
|
|
|
|
},
|
|
|
|
{urls:["*://*.repubblica.it/pwa/*"], types:["main_frame"]},
|
2020-10-17 08:51:24 +00:00
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2022-08-01 17:08:31 +00:00
|
|
|
// Google AMP cache redirect
|
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
var url = details.url.split('?')[0];
|
|
|
|
var updatedUrl;
|
|
|
|
if (matchUrlDomain('cdn.ampproject.org', url))
|
|
|
|
updatedUrl = 'https://' + url.split(/cdn\.ampproject\.org\/[a-z]\/s\//)[1];
|
|
|
|
else if (matchUrlDomain('google.com', url))
|
|
|
|
updatedUrl = 'https://' + url.split(/\.google\.com\/amp\/s\//)[1];
|
|
|
|
return { redirectUrl: decodeURIComponent(updatedUrl) };
|
|
|
|
},
|
|
|
|
{urls:["*://*.cdn.ampproject.org/*/s/*", "*://*.google.com/amp/s/*"], types:["main_frame"]},
|
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2022-03-04 15:14:14 +00:00
|
|
|
// inkl bypass
|
2020-10-17 08:51:24 +00:00
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var updatedUrl = details.url.replace(/etok=[\w]*&/, '');
|
2022-03-04 15:14:14 +00:00
|
|
|
if (details.url.includes('/signin?') && details.url.includes('redirect_to='))
|
|
|
|
updatedUrl = 'https://www.inkl.com' + decodeURIComponent(updatedUrl.split('redirect_to=')[1]);
|
2020-10-17 08:51:24 +00:00
|
|
|
return { redirectUrl: updatedUrl };
|
|
|
|
},
|
|
|
|
{urls:["*://*.inkl.com/*"], types:["main_frame"]},
|
2020-03-03 17:15:21 +00:00
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2021-04-11 17:52:54 +00:00
|
|
|
// m.faz.net set user-agent to mobile
|
2022-06-24 09:46:16 +00:00
|
|
|
const userAgentMobile = "Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36";
|
2021-01-01 11:23:29 +00:00
|
|
|
ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-02 13:03:52 +00:00
|
|
|
let headers = details.requestHeaders;
|
|
|
|
headers = headers.map(function (header) {
|
|
|
|
if (header.name.toLowerCase() === 'user-agent')
|
2022-06-24 09:46:16 +00:00
|
|
|
header.value = userAgentMobile;
|
2021-01-02 13:03:52 +00:00
|
|
|
return header;
|
2020-04-25 15:18:12 +00:00
|
|
|
});
|
2021-01-01 11:23:29 +00:00
|
|
|
return {
|
2021-01-02 13:03:52 +00:00
|
|
|
requestHeaders: headers
|
2021-01-01 11:23:29 +00:00
|
|
|
};
|
2020-04-25 15:18:12 +00:00
|
|
|
}, {
|
2021-01-01 11:23:29 +00:00
|
|
|
urls: ["*://m.faz.net/*"],
|
|
|
|
types: ["xmlhttprequest"]
|
2020-04-25 15:18:12 +00:00
|
|
|
},
|
2021-01-01 11:23:29 +00:00
|
|
|
["blocking", "requestHeaders"]);
|
2020-04-25 15:18:12 +00:00
|
|
|
|
2022-06-24 09:46:16 +00:00
|
|
|
// wap.business-standard.com/article-amp/ set user-agent to mobile
|
2021-04-11 17:52:54 +00:00
|
|
|
ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let headers = details.requestHeaders;
|
|
|
|
headers = headers.map(function (header) {
|
|
|
|
if (header.name.toLowerCase() === 'user-agent')
|
2022-06-24 09:46:16 +00:00
|
|
|
header.value = userAgentMobile;
|
2021-04-11 17:52:54 +00:00
|
|
|
return header;
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
requestHeaders: headers
|
|
|
|
};
|
|
|
|
}, {
|
2022-06-24 09:46:16 +00:00
|
|
|
urls: ["*://wap.business-standard.com/article-amp/*"],
|
2021-04-11 17:52:54 +00:00
|
|
|
types: ["main_frame"]
|
|
|
|
},
|
|
|
|
["blocking", "requestHeaders"]);
|
|
|
|
|
2021-05-21 06:04:59 +00:00
|
|
|
// economictimes redirect
|
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var updatedUrl = details.url.split('?')[0].replace('economictimes.indiatimes.com', 'm.economictimes.com');
|
|
|
|
return { redirectUrl: updatedUrl };
|
|
|
|
},
|
|
|
|
{urls:["*://economictimes.indiatimes.com/*?from=mdr"], types:["main_frame"]},
|
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2021-07-19 15:54:59 +00:00
|
|
|
// infzm.com redirect to wap (mobile)
|
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var updatedUrl = details.url.replace('.com/contents/', '.com/wap/#/content/');
|
|
|
|
return { redirectUrl: updatedUrl };
|
|
|
|
},
|
|
|
|
{urls:["*://www.infzm.com/contents/*"], types:["main_frame"]},
|
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2022-05-23 17:31:36 +00:00
|
|
|
// telegraaf.nl redirect error-page
|
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let updatedUrl = details.url.split('&')[0].replace('error?ref=/', '');;
|
|
|
|
return { redirectUrl: updatedUrl };
|
|
|
|
},
|
|
|
|
{urls:["*://www.telegraaf.nl/error?ref=/*"], types:["main_frame"]},
|
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2022-01-24 16:57:17 +00:00
|
|
|
// Australia News Corp redirect subscribe to amp
|
|
|
|
var au_news_corp_subscr = au_news_corp_domains.map(domain => '*://www.' + domain + '/subscribe/*');
|
2021-09-26 08:10:29 +00:00
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
2022-02-04 07:50:55 +00:00
|
|
|
if (!isSiteEnabled(details) || details.url.includes('/digitalprinteditions') || !(details.url.includes('dest=') && details.url.split('dest=')[1].split('&')[0])) {
|
2021-09-26 08:10:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-01-28 13:53:45 +00:00
|
|
|
var updatedUrl = decodeURIComponent(details.url.split('dest=')[1].split('&')[0]);
|
2022-02-09 11:56:03 +00:00
|
|
|
if (!matchUrlDomain('theaustralian.com.au', details.url))
|
2022-01-28 13:53:45 +00:00
|
|
|
updatedUrl += '?amp';
|
|
|
|
else
|
|
|
|
updatedUrl = updatedUrl.replace('www.', 'amp.');
|
|
|
|
return {
|
|
|
|
redirectUrl: updatedUrl
|
|
|
|
};
|
|
|
|
}, {
|
|
|
|
urls: au_news_corp_subscr,
|
|
|
|
types: ["main_frame"]
|
2021-09-26 08:10:29 +00:00
|
|
|
},
|
2022-01-28 13:53:45 +00:00
|
|
|
["blocking"]);
|
2021-09-26 08:10:29 +00:00
|
|
|
|
2020-10-21 14:48:59 +00:00
|
|
|
// fix nytimes x-frame-options (hidden iframe content)
|
|
|
|
ext_api.webRequest.onHeadersReceived.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-02 13:03:52 +00:00
|
|
|
var headers = details.responseHeaders;
|
2021-01-06 18:50:12 +00:00
|
|
|
headers = headers.map(function (header) {
|
2021-01-02 13:03:52 +00:00
|
|
|
if (header.name === 'x-frame-options')
|
|
|
|
header.value = 'SAMEORIGIN';
|
|
|
|
return header;
|
2020-10-21 14:48:59 +00:00
|
|
|
});
|
|
|
|
return {
|
2021-01-02 13:03:52 +00:00
|
|
|
responseHeaders: headers
|
2020-10-21 14:48:59 +00:00
|
|
|
};
|
|
|
|
}, {
|
|
|
|
urls: ["*://*.nytimes.com/*"]
|
|
|
|
},
|
|
|
|
['blocking', 'responseHeaders']);
|
|
|
|
|
2021-05-18 15:12:15 +00:00
|
|
|
// block inline script
|
2022-10-27 14:18:29 +00:00
|
|
|
var block_js_inline = ["*://*.crusoe.uol.com.br/*", "*://*.elpais.com/*", "*://*.lavoz.com.ar/*", "*://*.nautil.us/*", "*://*.rugbypass.com/*", "*://*.theglobeandmail.com/*/article-*"];
|
2022-01-23 20:48:14 +00:00
|
|
|
if (block_js_inline.length)
|
2021-01-18 17:43:04 +00:00
|
|
|
ext_api.webRequest.onHeadersReceived.addListener(function (details) {
|
2022-04-21 17:52:47 +00:00
|
|
|
let url_path = details.url.split('?')[0];
|
2022-07-29 16:20:36 +00:00
|
|
|
let excluded = (matchUrlDomain('crusoe.uol.com.br', details.url) && (optin_setcookie || !url_path.match(/\.br\/(diario|edicoes)\/.+/)))
|
|
|
|
|| (matchUrlDomain('elpais.com', details.url) && (url_path.includes('/elpais.com') || !url_path.includes('.html')))
|
2022-10-15 09:08:46 +00:00
|
|
|
|| (matchUrlDomain('nautil.us', details.url) && !details.url.match(/((\w)+(\-)+){3,}/))
|
2022-10-27 14:18:29 +00:00
|
|
|
|| (matchUrlDomain('rugbypass.com', details.url) && !details.url.includes('.com/plus/'))
|
2022-10-15 09:08:46 +00:00
|
|
|
|| (matchUrlDomain('theglobeandmail.com', details.url) && !details.url.includes('?rel=premium'));
|
2022-04-07 18:13:49 +00:00
|
|
|
if (!isSiteEnabled(details) || excluded)
|
2021-01-18 17:43:04 +00:00
|
|
|
return;
|
|
|
|
var headers = details.responseHeaders;
|
|
|
|
headers.push({
|
|
|
|
'name': 'Content-Security-Policy',
|
|
|
|
'value': "script-src *;"
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
responseHeaders: headers
|
|
|
|
};
|
|
|
|
}, {
|
|
|
|
'types': ['main_frame', 'sub_frame'],
|
2021-05-18 15:12:15 +00:00
|
|
|
'urls': block_js_inline
|
2021-01-18 17:43:04 +00:00
|
|
|
},
|
|
|
|
['blocking', 'responseHeaders']);
|
|
|
|
|
2021-12-10 17:16:56 +00:00
|
|
|
var block_js = [
|
|
|
|
"*://*.blueconic.net/*",
|
|
|
|
"*://*.cxense.com/*",
|
2022-09-21 16:31:24 +00:00
|
|
|
"*://*.ensighten.com/*/Bootstrap.js*",
|
2021-12-10 17:16:56 +00:00
|
|
|
"*://*.evolok.net/*",
|
2022-02-07 17:27:10 +00:00
|
|
|
"*://*.newsmemory.com/?meter*",
|
2021-12-10 17:16:56 +00:00
|
|
|
"*://*.onecount.net/*",
|
|
|
|
"*://*.piano.io/*",
|
|
|
|
"*://*.poool.fr/*",
|
|
|
|
"*://*.qiota.com/*",
|
|
|
|
"*://*.tribdss.com/*",
|
2022-03-09 16:16:17 +00:00
|
|
|
"*://*.weborama.fr/*",
|
2022-01-14 14:39:50 +00:00
|
|
|
"*://*.zephr.com/zephr-browser/*",
|
2022-07-10 11:44:20 +00:00
|
|
|
"*://*/*/ev-widgets.min.js*",
|
2022-02-16 18:14:05 +00:00
|
|
|
"*://*/c/assets/pigeon.js*",
|
2022-08-02 15:02:13 +00:00
|
|
|
"*://*/wp-content/*/ev-em.min.js*",
|
2022-06-04 08:39:40 +00:00
|
|
|
"*://*/zephr/features*",
|
2022-08-13 14:56:45 +00:00
|
|
|
"*://api.pico.tools/*",
|
2021-12-10 17:16:56 +00:00
|
|
|
"*://cdn.ampproject.org/v*/amp-access-*.*js",
|
|
|
|
"*://cdn.ampproject.org/v*/amp-subscriptions-*.*js",
|
2022-04-26 19:39:02 +00:00
|
|
|
"*://cdn.ampproject.org/v*/amp*-ad-*.*js",
|
|
|
|
"*://cdn.ampproject.org/v*/amp-analytics-*.*js",
|
|
|
|
"*://cdn.ampproject.org/v*/amp-fx-flying-carpet-*.*js",
|
2021-12-10 17:16:56 +00:00
|
|
|
"*://cdn.tinypass.com/*",
|
|
|
|
"*://js.matheranalytics.com/*",
|
|
|
|
"*://js.pelcro.com/*",
|
|
|
|
"*://loader-cdn.azureedge.net/prod/*/loader.min.js*",
|
2022-10-12 17:35:31 +00:00
|
|
|
"*://olytics.omeda.com/*",
|
2021-12-10 17:16:56 +00:00
|
|
|
];
|
2020-03-28 13:59:26 +00:00
|
|
|
|
2020-01-28 22:06:25 +00:00
|
|
|
// Disable javascript for these sites/general paywall-scripts
|
2020-03-28 13:59:26 +00:00
|
|
|
function disableJavascriptOnListedSites() {
|
2020-10-24 14:38:01 +00:00
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
2021-01-19 18:41:27 +00:00
|
|
|
let header_referer = details.originUrl ? details.originUrl : details.initiator;
|
2022-04-14 06:03:01 +00:00
|
|
|
if (!(isSiteEnabled(details)
|
2022-04-14 18:43:16 +00:00
|
|
|
|| (['script'].includes(details.type)
|
2022-08-02 15:02:13 +00:00
|
|
|
&& ((enabledSites.includes('###_wp_evolok') && details.url.match(/\/(wp-content\/.+\/ev-em|evolok\/.+\/ev-widgets)\.min\.js/))
|
2022-06-04 08:39:40 +00:00
|
|
|
|| (enabledSites.includes('###_wp_pigeon') && details.url.includes('/c/assets/pigeon.js'))
|
|
|
|
|| (enabledSites.includes('zephr.com') && details.url.includes('/zephr/features')))))
|
2022-09-13 06:51:11 +00:00
|
|
|
|| matchUrlDomain(excludedSites.concat(disabledSites, ['asia.nikkei.com', 'businesspost.ie', 'cambridge.org', 'japantimes.co.jp']), header_referer)) {
|
2020-10-24 14:38:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
cancel: true
|
|
|
|
};
|
|
|
|
}, {
|
|
|
|
urls: block_js,
|
|
|
|
types: ["script", "xmlhttprequest"]
|
|
|
|
},
|
|
|
|
["blocking"]);
|
2020-03-28 13:59:26 +00:00
|
|
|
}
|
2019-05-12 23:31:18 +00:00
|
|
|
|
2021-02-22 18:49:41 +00:00
|
|
|
if (typeof browser !== 'object') {
|
2021-02-21 08:21:39 +00:00
|
|
|
var focus_changed = false;
|
|
|
|
ext_api.windows.onFocusChanged.addListener((windowId) => {
|
|
|
|
if (windowId > 0)
|
|
|
|
focus_changed = true;
|
|
|
|
});
|
2021-02-22 18:49:41 +00:00
|
|
|
}
|
2021-02-21 08:21:39 +00:00
|
|
|
|
2020-03-25 18:31:28 +00:00
|
|
|
var extraInfoSpec = ['blocking', 'requestHeaders'];
|
|
|
|
if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'))
|
|
|
|
extraInfoSpec.push('extraHeaders');
|
|
|
|
|
|
|
|
ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
2020-09-11 14:52:50 +00:00
|
|
|
if (details.type === 'main_frame') {
|
|
|
|
let current_date_str = currentDateStr();
|
|
|
|
if (last_date_str < current_date_str) {
|
|
|
|
bpc_count_daily_users(current_date_str);
|
|
|
|
last_date_str = current_date_str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 18:23:00 +00:00
|
|
|
var requestHeaders = details.requestHeaders;
|
|
|
|
|
|
|
|
var header_referer = '';
|
2022-01-05 19:40:38 +00:00
|
|
|
if (details.originUrl)
|
|
|
|
header_referer = details.originUrl;
|
|
|
|
else {
|
|
|
|
for (let n in requestHeaders) {
|
|
|
|
if (requestHeaders[n].name.toLowerCase() == 'referer') {
|
|
|
|
header_referer = requestHeaders[n].value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 06:49:28 +00:00
|
|
|
var blocked_referer_domains = ['timeshighereducation.com'];
|
2022-01-05 19:40:38 +00:00
|
|
|
if (!header_referer && details.initiator) {
|
|
|
|
header_referer = details.initiator;
|
|
|
|
if (!blocked_referer && matchUrlDomain(blocked_referer_domains, details.url) && ['script', 'xmlhttprequest'].includes(details.type)) {
|
|
|
|
for (let domain of blocked_referer_domains)
|
|
|
|
restrictions[domain] = new RegExp('((\\/|\\.)' + domain.replace(/\./g, '\\.') + '($|\\/$)|' + restrictions[domain].toString().replace(/(^\/|\/$)/g, '') + ')');
|
|
|
|
blocked_referer = true;
|
|
|
|
}
|
2020-09-11 14:52:50 +00:00
|
|
|
}
|
2021-06-21 20:42:46 +00:00
|
|
|
}
|
2020-01-13 18:15:37 +00:00
|
|
|
|
2022-07-26 15:33:57 +00:00
|
|
|
function customAddRules(custom_domains, custom_cookies = '', custom_block_regex = '', custom_useragent = '', custom_referer = '', custom_amp_unhide = false) {
|
2022-03-14 18:39:05 +00:00
|
|
|
let custom_domain = urlHost(header_referer).replace(/^(www|m|account|amp|edition|eu)\./, '');
|
2022-07-26 15:33:57 +00:00
|
|
|
if (custom_cookies) {
|
|
|
|
if (custom_cookies.allow_cookies && !allow_cookies.includes(custom_domain))
|
|
|
|
allow_cookies.push(custom_domain);
|
|
|
|
if (custom_cookies.remove_cookies && !remove_cookies.includes(custom_domain))
|
|
|
|
remove_cookies.push(custom_domain);
|
|
|
|
}
|
2022-05-29 13:52:54 +00:00
|
|
|
if (custom_block_regex) {
|
|
|
|
if ((typeof custom_block_regex === 'string') && custom_block_regex.includes('{domain}'))
|
|
|
|
custom_block_regex = new RegExp(custom_block_regex.replace('{domain}', custom_domain.replace(/\./g, '\\.')));
|
2022-03-14 18:39:05 +00:00
|
|
|
blockedRegexes[custom_domain] = custom_block_regex;
|
2022-05-29 13:52:54 +00:00
|
|
|
}
|
2022-03-14 18:39:05 +00:00
|
|
|
if (custom_useragent) {
|
|
|
|
if (custom_useragent === 'googlebot') {
|
|
|
|
if (!use_google_bot.includes(custom_domain))
|
|
|
|
use_google_bot.push(custom_domain);
|
|
|
|
change_headers.push(custom_domain);
|
|
|
|
}
|
2021-02-07 08:45:57 +00:00
|
|
|
}
|
2022-03-14 18:39:05 +00:00
|
|
|
if (custom_referer) {
|
|
|
|
if (custom_referer === 'twitter') {
|
|
|
|
if (!use_twitter_referer.includes(custom_domain))
|
|
|
|
use_twitter_referer.push(custom_domain);
|
|
|
|
change_headers.push(custom_domain);
|
|
|
|
}
|
2022-01-25 17:15:31 +00:00
|
|
|
}
|
2022-03-14 18:39:05 +00:00
|
|
|
if (custom_amp_unhide) {
|
|
|
|
if (!amp_unhide.includes(custom_domain))
|
|
|
|
amp_unhide.push(custom_domain);
|
2021-02-28 10:32:38 +00:00
|
|
|
}
|
2022-03-14 18:39:05 +00:00
|
|
|
custom_domains.push(custom_domain);
|
|
|
|
if (!enabledSites.includes(custom_domain))
|
|
|
|
enabledSites.push(custom_domain);
|
|
|
|
return custom_domains;
|
2021-08-16 20:49:58 +00:00
|
|
|
}
|
|
|
|
|
2022-08-21 06:59:42 +00:00
|
|
|
if (!matchUrlDomain(excludedSites, header_referer)) {
|
2022-04-06 15:17:13 +00:00
|
|
|
|
2022-03-14 18:39:05 +00:00
|
|
|
// remove cookies for sites medium platform (custom domains)
|
2022-04-28 15:52:26 +00:00
|
|
|
var medium_custom_domain = (matchUrlDomain('cdn-client.medium.com', details.url) && ['script'].includes(details.type) && !matchUrlDomain(medium_custom_domains.concat(['medium.com']), header_referer) && enabledSites.includes('###_medium_custom'));
|
2022-03-14 18:39:05 +00:00
|
|
|
if (medium_custom_domain)
|
2022-04-28 15:52:26 +00:00
|
|
|
medium_custom_domains = customAddRules(medium_custom_domains);
|
2022-09-25 07:33:43 +00:00
|
|
|
else {
|
|
|
|
// remove cookies for Leaky Paywall/WordPress sites (opt-in to custom sites)
|
2022-09-26 14:44:11 +00:00
|
|
|
var leaky_paywall_domain = (details.url.match(/\/leaky-paywall(-|\/)/) && ['script'].includes(details.type) && !matchUrlDomain(leaky_paywall_domains.concat(['griffithreview.com', 'nknews.org']), header_referer) && enabledSites.includes('###_wp_leaky_paywall'));
|
2022-09-25 07:33:43 +00:00
|
|
|
if (leaky_paywall_domain)
|
|
|
|
leaky_paywall_domains = customAddRules(leaky_paywall_domains);
|
2022-08-17 06:49:28 +00:00
|
|
|
else {
|
|
|
|
// remove cookies & set googlebot-useragent for sites substack platform (custom domains)
|
2022-08-21 06:59:42 +00:00
|
|
|
var substack_custom_domain = (matchUrlDomain('substackcdn.com', details.url) && ['script', 'stylesheet'].includes(details.type) && !matchUrlDomain(substack_custom_domains.concat(['substack.com']), header_referer) && enabledSites.includes('###_substack_custom'));
|
2022-08-17 06:49:28 +00:00
|
|
|
if (substack_custom_domain)
|
|
|
|
substack_custom_domains = customAddRules(substack_custom_domains, '', '', 'googlebot');
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
|
|
|
let header_referer_hostname = urlHost(header_referer);
|
2022-08-21 06:59:42 +00:00
|
|
|
let url_hostname = urlHost(details.url);
|
2022-05-06 16:46:36 +00:00
|
|
|
if (header_referer_hostname.match(/\.(com|net)\.au$/)) {
|
|
|
|
// block Piano.io for regional Australian Community Media sites (opt-in to custom sites)
|
|
|
|
var au_comm_media_domain = (details.url.startsWith('https://' + header_referer_hostname + '/promotions/website_content_esov/') && ['xmlhttprequest'].includes(details.type) && !matchUrlDomain(au_comm_media_domains, header_referer) && enabledSites.includes('###_au_comm_media'));
|
|
|
|
if (au_comm_media_domain)
|
2022-07-26 15:33:57 +00:00
|
|
|
au_comm_media_domains = customAddRules(au_comm_media_domains, {allow_cookies: 1}, blockedRegexes['canberratimes.com.au']);
|
2022-05-06 16:46:36 +00:00
|
|
|
else if (header_referer_hostname.endsWith('.com.au')) {
|
|
|
|
// enable regional The West Australian sites (opt-in to custom sites)
|
|
|
|
var au_thewest_domain = (details.url.startsWith('https://images.thewest.com.au/') && ['image'].includes(details.type) &&
|
|
|
|
!matchUrlDomain(au_thewest_domains, header_referer) && enabledSites.includes('thewest.com.au'));
|
|
|
|
if (au_thewest_domain)
|
2022-07-26 15:33:57 +00:00
|
|
|
au_thewest_domains = customAddRules(au_thewest_domains, {allow_cookies: 1});
|
2022-05-06 16:46:36 +00:00
|
|
|
}
|
2022-04-13 15:48:30 +00:00
|
|
|
} else if (header_referer_hostname.endsWith('.ch')) {
|
|
|
|
// set googlebot-useragent for regional nzz.ch sites (opt-in to custom sites)
|
|
|
|
var ch_media_domain = (matchUrlDomain('static-chmedia.ch', details.url) && ['script'].includes(details.type) && !matchUrlDomain(ch_media_domains, header_referer) && enabledSites.includes('nzz.ch'));
|
|
|
|
if (ch_media_domain)
|
2022-07-26 15:33:57 +00:00
|
|
|
ch_media_domains = customAddRules(ch_media_domains, {allow_cookies: 1}, blockedRegexes['nzz.ch'], 'googlebot');
|
2022-05-29 13:52:54 +00:00
|
|
|
} else if (header_referer_hostname.endsWith('.cl')) {
|
|
|
|
// block scripts for regional El Mercurio sites (opt-in to custom sites)
|
|
|
|
var cl_emol_region_domain = (matchUrlDomain('impresa.soy-chile.cl', details.url) && ['xmlhttprequest'].includes(details.type) && !matchUrlDomain(cl_emol_region_domains, header_referer) && enabledSites.includes('elmercurio.com'));
|
|
|
|
if (cl_emol_region_domain) {
|
2022-07-26 15:33:57 +00:00
|
|
|
cl_emol_region_domains = customAddRules(cl_emol_region_domains, '', "(\\.{domain}\\/impresa\\/.+\\/assets\\/(vendor|\\d)\\.js|pram\\.pasedigital\\.cl\\/API\\/User\\/Status\\?)");
|
|
|
|
}
|
2022-03-14 18:39:05 +00:00
|
|
|
} else if (header_referer_hostname.endsWith('.de')) {
|
|
|
|
// set googlebot-useragent for additional Funke sites (opt-in to custom sites)
|
|
|
|
var de_funke_domain = (matchUrlDomain('funkedigital.de', details.url) && ['script'].includes(details.type) && !matchUrlDomain(de_funke_medien_domains, header_referer) && enabledSites.includes('###_de_funke_medien'));
|
|
|
|
if (de_funke_domain)
|
2022-07-26 15:33:57 +00:00
|
|
|
de_funke_medien_domains = customAddRules(de_funke_medien_domains, {allow_cookies: 1}, blockedRegexes['waz.de'], 'googlebot');
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
|
|
|
// block script for additional Madsack/RND sites (opt-in to custom sites)
|
2022-08-21 06:59:42 +00:00
|
|
|
var de_madsack_domain = (matchUrlDomain('rndtech.de', details.url) && ['script', 'font'].includes(details.type) && !matchUrlDomain(de_madsack_domains.concat(['madsack.de', 'madsack-medien-campus.de']), header_referer) && enabledSites.includes('###_de_madsack'));
|
2022-04-06 15:17:13 +00:00
|
|
|
if (de_madsack_domain)
|
2022-07-26 15:33:57 +00:00
|
|
|
de_madsack_domains = customAddRules(de_madsack_domains, {allow_cookies: 1}, blockedRegexes['haz.de']);
|
2022-03-14 18:39:05 +00:00
|
|
|
}
|
2022-04-29 15:58:48 +00:00
|
|
|
} else if (header_referer_hostname.match(/\.(es|cat)$/) || matchUrlDomain(['diariocordoba.com', 'elperiodicodearagon.com', 'elperiodicoextremadura.com', 'elperiodicomediterraneo.com', 'emporda.info'], header_referer)) {
|
|
|
|
// block Piano.io for unlisted Grupo Prensa Ibérica (opt-in to custom sites)
|
2022-08-21 06:59:42 +00:00
|
|
|
var es_epiberica_domain = (url_hostname.startsWith('estaticos-cdn.') && ['script', 'font', 'stylesheet'].includes(details.type) && !matchUrlDomain(es_epiberica_domains, header_referer) && enabledSites.includes('###_es_epiberica'));
|
2022-04-29 15:58:48 +00:00
|
|
|
if (es_epiberica_domain)
|
2022-07-26 15:33:57 +00:00
|
|
|
es_epiberica_domains = customAddRules(es_epiberica_domains, {allow_cookies: 1}, blockedRegexes['epe.es']);
|
2022-09-23 10:14:57 +00:00
|
|
|
} else if (header_referer_hostname.endsWith('.fr')) {
|
|
|
|
// block Poool.fr for Groupe Centre France sites (opt-in to custom sites)
|
|
|
|
var fr_gcf_domain = (details.url.match(/\.fr\/static\/bloc\/ripolinage\/header\/cf-header\//) && ['script', 'stylesheet'].includes(details.type) && !matchUrlDomain(fr_gcf_domains, header_referer) && enabledSites.includes('###_fr_gcf'));
|
|
|
|
if (fr_gcf_domain)
|
|
|
|
fr_gcf_domains = customAddRules(fr_gcf_domains, {allow_cookies: 1}, blockedRegexes['lamontagne.fr']);
|
2022-05-02 15:29:37 +00:00
|
|
|
} else if (header_referer_hostname.endsWith('.nl')) {
|
|
|
|
// block Evolok for Mediahuis Noord sites (opt-in to custom sites)
|
|
|
|
var nl_mediahuis_noord_domain = (matchUrlDomain('ndcmediagroep.nl', details.url) && ['script'].includes(details.type) && !matchUrlDomain(nl_mediahuis_noord_domains, header_referer) && enabledSites.includes('###_nl_mediahuis_noord'));
|
|
|
|
if (nl_mediahuis_noord_domain)
|
2022-07-26 15:33:57 +00:00
|
|
|
nl_mediahuis_noord_domains = customAddRules(nl_mediahuis_noord_domains, {allow_cookies: 1}, blockedRegexes['lc.nl']);
|
2022-08-22 19:23:43 +00:00
|
|
|
} else if (header_referer_hostname.match(/\.(ca|com|net|org)$/)) {
|
2022-07-26 15:33:57 +00:00
|
|
|
// remove cookies for Groupe Capitales Médias sites
|
2022-07-31 06:31:05 +00:00
|
|
|
var ca_gcm_domain = (matchUrlDomain('gcm.omerlocdn.com', details.url) && ['xmlhttprequest'].includes(details.type) && !matchUrlDomain(ca_gcm_domains, header_referer) && enabledSites.includes('###_ca_gcm'));
|
2022-07-26 15:33:57 +00:00
|
|
|
if (ca_gcm_domain)
|
|
|
|
ca_gcm_domains = customAddRules(ca_gcm_domains, {allow_cookies: 1, remove_cookies: 1});
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
2022-07-26 15:33:57 +00:00
|
|
|
// block TinyPass for Postmedia Network sites
|
|
|
|
var ca_postmedia_domain = (matchUrlDomain('postmedia.digital', details.url) && ['script'].includes(details.type) && !matchUrlDomain(ca_postmedia_domains.concat(['canada.com', 'canoe.com', 'driving.ca']), header_referer) && enabledSites.includes('###_ca_postmedia'));
|
|
|
|
if (ca_postmedia_domain)
|
|
|
|
ca_postmedia_domains = customAddRules(ca_postmedia_domains, {allow_cookies: 1}, blockedRegexes['nationalpost.com']);
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
2022-07-26 15:33:57 +00:00
|
|
|
// set googlebot-useragent for Gannett sites
|
|
|
|
var usa_gannett_domain = (matchUrlDomain('gannett-cdn.com', details.url) && ['xmlhttprequest'].includes(details.type) && !matchUrlDomain(usa_gannett_domains.concat(['usatoday.com']), header_referer) && enabledSites.includes('###_usa_gannett'));
|
|
|
|
if (usa_gannett_domain)
|
|
|
|
usa_gannett_domains = customAddRules(usa_gannett_domains, '', blockedRegexes['azcentral.com'], 'googlebot', '', true);
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
2022-09-21 16:31:24 +00:00
|
|
|
var usa_hearst_comm_domain = (matchUrlDomain('treg.hearstnp.com', details.url) && ['script'].includes(details.type) && !matchUrlDomain(usa_hearst_comm_domains.concat(['sfgate.com']), header_referer) && enabledSites.includes('###_usa_hearst_comm'));
|
2022-07-26 15:33:57 +00:00
|
|
|
if (usa_hearst_comm_domain)
|
2022-09-21 16:31:24 +00:00
|
|
|
usa_hearst_comm_domains = customAddRules(usa_hearst_comm_domains, {allow_cookies: 1}, blockedRegexes['houstonchronicle.com']);
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
2022-07-26 15:33:57 +00:00
|
|
|
// block script for additional Lee Enterprises sites (opt-in to custom sites)
|
|
|
|
var usa_lee_ent_domain = (details.url.match(/\.townnews\.com\/(central\.)?leetemplates\.com\//) && ['script'].includes(details.type) &&
|
|
|
|
!matchUrlDomain(usa_lee_ent_domains, header_referer) && enabledSites.includes('###_usa_lee_ent'));
|
|
|
|
if (usa_lee_ent_domain)
|
|
|
|
usa_lee_ent_domains = customAddRules(usa_lee_ent_domains, '', blockedRegexes['buffalonews.com']);
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
2022-07-26 15:33:57 +00:00
|
|
|
// block script for TownNews sites (Blox CMS; opt-in to custom sites)
|
|
|
|
var usa_townnews_domain = (details.url.match(/\.townnews\.com\/.+\/tncms\//) && ['script'].includes(details.type) &&
|
2022-09-24 07:09:46 +00:00
|
|
|
!matchUrlDomain(usa_townnews_domains.concat(usa_lee_ent_domains, ['townnews.com', 'galvnews.com', 'nola.com', 'theadvocate.com']), header_referer) && enabledSites.includes('###_usa_townnews'));
|
2022-07-26 15:33:57 +00:00
|
|
|
if (usa_townnews_domain)
|
|
|
|
usa_townnews_domains = customAddRules(usa_townnews_domains, '', /\.com\/shared-content\/art\/tncms\/user\/user\.js/);
|
2022-03-14 18:39:05 +00:00
|
|
|
else {
|
2022-07-26 15:33:57 +00:00
|
|
|
// block script for additional McClatchy sites (opt-in to custom sites)
|
|
|
|
var usa_mcc_domain = (((matchUrlDomain('mcclatchyinteractive.com', details.url) && ['script'].includes(details.type)) ||
|
2022-07-26 16:20:19 +00:00
|
|
|
(matchUrlDomain('mcclatchy.com', details.url) && ['image'].includes(details.type))) &&
|
|
|
|
!matchUrlDomain(usa_mcc_domains.concat(['mcclatchy.com']), header_referer) && enabledSites.includes('###_usa_mcc'));
|
2022-07-26 15:33:57 +00:00
|
|
|
if (usa_mcc_domain)
|
|
|
|
usa_mcc_domains = customAddRules(usa_mcc_domains, '', blockedRegexes['bnd.com']);
|
|
|
|
else {
|
|
|
|
// block script for additional MediaNews Group sites (opt-in to custom sites)
|
|
|
|
var usa_mng_domain = (details.url.match(/\.com\/wp-content\/plugins\/dfm(-|_).+\.js/) && ['script'].includes(details.type) &&
|
|
|
|
!matchUrlDomain(usa_mng_domains, header_referer) && enabledSites.includes('###_usa_mng'));
|
|
|
|
if (usa_mng_domain)
|
|
|
|
usa_mng_domains = customAddRules(usa_mng_domains, '', blockedRegexes['denverpost.com']);
|
2022-09-08 06:34:16 +00:00
|
|
|
else if (header_referer_hostname.match(/\.com$/)) {
|
2022-09-18 14:41:03 +00:00
|
|
|
// block cookies for Madavor Media sites
|
|
|
|
var usa_madavor_domain = (details.url.match(/\.com\/wp-content\/(plugins|themes)\/madavor-/) && ['script'].includes(details.type) && details.url.includes(header_referer_hostname) && !matchUrlDomain(usa_madavor_domains, header_referer) && enabledSites.includes('###_usa_madavor'));
|
|
|
|
if (usa_madavor_domain)
|
|
|
|
usa_madavor_domains = customAddRules(usa_madavor_domains);
|
|
|
|
else {
|
|
|
|
// set googlebot-useragent for PEI Media sites
|
|
|
|
var usa_pei_domain = (details.url.match(/\.com\/wp-content\/plugins\/pragmatic-pei-rebranding\/assets\/img\/.+-logo\.svg$/) && ['image', 'xmlhttprequest'].includes(details.type) && details.url.includes(header_referer_hostname) && !matchUrlDomain(usa_pei_domains, header_referer) && enabledSites.includes('###_usa_pei'));
|
|
|
|
if (usa_pei_domain)
|
|
|
|
usa_pei_domains = customAddRules(usa_pei_domains, {allow_cookies: 1}, '', 'googlebot');
|
|
|
|
}
|
2022-09-08 06:34:16 +00:00
|
|
|
}
|
2022-07-26 15:33:57 +00:00
|
|
|
}
|
2022-03-14 18:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 06:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-14 15:48:33 +00:00
|
|
|
}
|
2022-09-25 07:33:43 +00:00
|
|
|
}
|
2021-08-14 15:48:33 +00:00
|
|
|
|
2022-04-06 15:17:13 +00:00
|
|
|
} // not in excludedSites
|
|
|
|
|
2020-06-01 16:01:43 +00:00
|
|
|
// block external javascript for custom sites (optional)
|
2020-08-22 11:52:43 +00:00
|
|
|
var domain_blockjs_ext = matchUrlDomain(block_js_custom_ext, header_referer);
|
2021-01-26 20:27:43 +00:00
|
|
|
if (domain_blockjs_ext && !matchUrlDomain(domain_blockjs_ext, details.url) && details.type === 'script' && isSiteEnabled({url: header_referer})) {
|
2020-06-01 16:01:43 +00:00
|
|
|
return { cancel: true };
|
|
|
|
}
|
2020-03-27 18:02:27 +00:00
|
|
|
|
2019-11-27 18:23:00 +00:00
|
|
|
// check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
|
2020-05-01 10:58:36 +00:00
|
|
|
var blockedDomains = Object.keys(blockedRegexes);
|
2020-05-06 19:05:34 +00:00
|
|
|
var domain = matchUrlDomain(blockedDomains, header_referer);
|
2021-11-04 17:50:19 +00:00
|
|
|
if (domain && details.url.match(blockedRegexes[domain]) && isSiteEnabled({url: header_referer}))
|
2021-10-19 17:38:57 +00:00
|
|
|
return { cancel: true };
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2020-11-03 16:34:30 +00:00
|
|
|
// load toggleIcon.js (icon for dark or incognito mode in Chrome))
|
2021-02-16 16:49:29 +00:00
|
|
|
if (typeof browser !== 'object' && ['main_frame', 'xmlhttprequest'].includes(details.type)) {
|
2020-11-03 16:34:30 +00:00
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2021-12-15 16:44:52 +00:00
|
|
|
if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
|
2020-11-03 16:34:30 +00:00
|
|
|
ext_api.tabs.executeScript({
|
2021-03-27 07:31:03 +00:00
|
|
|
file: 'options/toggleIcon.js',
|
2020-11-03 16:34:30 +00:00
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-23 16:44:54 +00:00
|
|
|
let allow_ext_source = medium_custom_domain;
|
|
|
|
let bpc_amp_site = false;
|
2021-01-01 11:23:29 +00:00
|
|
|
|
2022-07-26 15:33:57 +00:00
|
|
|
if (isSiteEnabled({url: header_referer}) && ['script', 'xmlhttprequest', 'image'].includes(details.type)) {
|
2021-12-08 16:45:19 +00:00
|
|
|
bpc_amp_site = matchUrlDomain('cdn.ampproject.org', details.url);
|
2022-02-08 18:41:59 +00:00
|
|
|
allow_ext_source = allow_ext_source || bpc_amp_site ||
|
|
|
|
(matchUrlDomain('elespanol.com', header_referer) && matchUrlDomain('eestatic.com', details.url)) ||
|
|
|
|
(matchUrlDomain('elmercurio.com', header_referer) && matchUrlDomain('emol.cl', details.url)) ||
|
|
|
|
(matchUrlDomain('law360.com', header_referer) && matchUrlDomain('law360news.com', details.url)) ||
|
2022-07-28 16:22:35 +00:00
|
|
|
(matchUrlDomain('lesechos.fr', header_referer) && matchUrlDomain('lesechos.com', details.url)) ||
|
2022-02-08 18:41:59 +00:00
|
|
|
(matchUrlDomain('marketwatch.com', header_referer) && matchUrlDomain('wsj.net', details.url)) ||
|
|
|
|
(matchUrlDomain('nationalgeographic.com', header_referer) && matchUrlDomain('natgeofe.com', details.url)) ||
|
|
|
|
(matchUrlDomain('usatoday.com', header_referer) && matchUrlDomain('gannett-cdn.com', details.url)) ||
|
2022-07-26 15:33:57 +00:00
|
|
|
(matchUrlDomain(ca_gcm_domains, header_referer) && matchUrlDomain('gcm.omerlocdn.com', details.url)) ||
|
2022-08-04 15:38:34 +00:00
|
|
|
(matchUrlDomain(it_gedi_domains, header_referer) && matchUrlDomain(['repstatic.it'], details.url));
|
2022-02-08 18:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isSiteEnabled(details) && !allow_ext_source) {
|
2019-11-27 18:23:00 +00:00
|
|
|
return;
|
2018-11-24 22:10:21 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 07:04:58 +00:00
|
|
|
// block javascript of (sub)domain for custom sites (optional)
|
2020-08-22 11:52:43 +00:00
|
|
|
var domain_blockjs = matchUrlDomain(block_js_custom, details.url);
|
2021-01-26 20:27:43 +00:00
|
|
|
if (domain_blockjs && matchUrlDomain(domain_blockjs, details.url) && details.type === 'script') {
|
2020-06-04 07:04:58 +00:00
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
|
2017-07-08 17:40:29 +00:00
|
|
|
var tabId = details.tabId;
|
2020-03-27 18:02:27 +00:00
|
|
|
|
2019-04-06 23:34:30 +00:00
|
|
|
var useUserAgentMobile = false;
|
2017-07-08 17:40:29 +00:00
|
|
|
var setReferer = false;
|
2022-02-04 07:50:55 +00:00
|
|
|
|
2022-10-14 13:53:54 +00:00
|
|
|
var ignore_types = ['font', 'image', 'stylesheet'];
|
|
|
|
if (matchUrlDomain(au_news_corp_domains, details.url))
|
|
|
|
ignore_types = ['font', 'image', 'stylesheet', 'other', 'script', 'xmlhttprequest'];
|
|
|
|
|
|
|
|
if (matchUrlDomain(change_headers, details.url) && !ignore_types.includes(details.type)) {
|
2022-02-04 07:50:55 +00:00
|
|
|
var mobile = details.requestHeaders.filter(x => x.name.toLowerCase() === "user-agent" && x.value.toLowerCase().includes("mobile")).length;
|
2021-07-24 08:07:06 +00:00
|
|
|
var googlebotEnabled = matchUrlDomain(use_google_bot, details.url) &&
|
2022-10-21 10:44:02 +00:00
|
|
|
!(matchUrlDomain('abc.es', details.url) && mobile) &&
|
2021-07-24 08:07:06 +00:00
|
|
|
!(matchUrlDomain('barrons.com', details.url) && enabledSites.includes('#options_disable_gb_barrons')) &&
|
2022-08-07 17:04:12 +00:00
|
|
|
!(matchUrlDomain(['economictimes.com', 'economictimes.indiatimes.com'], details.url) && !details.url.split(/\?|#/)[0].endsWith('.cms')) &&
|
2022-05-14 07:36:13 +00:00
|
|
|
!(matchUrlDomain('theaustralian.com.au', details.url) && !details.url.startsWith('https://www.theaustralian.com.au/the-oz/')) &&
|
2022-10-14 13:53:54 +00:00
|
|
|
!(matchUrlDomain(au_news_corp_domains, details.url) && details.url.includes('?amp')) &&
|
2022-08-18 19:56:52 +00:00
|
|
|
!(matchUrlDomain('uol.com.br', details.url) && !matchUrlDomain('folha.uol.com.br', details.url)) &&
|
2022-09-02 16:57:57 +00:00
|
|
|
!(matchUrlDomain('wsj.com', details.url) && (enabledSites.includes('#options_disable_gb_wsj') || !details.url.includes('/articles/')));
|
2021-10-25 17:05:57 +00:00
|
|
|
var bingbotEnabled = matchUrlDomain(use_bing_bot, details.url) &&
|
|
|
|
!(matchUrlDomain('stratfor.com', details.url) && details.url.match(/(\/(\d){4}-([a-z]||-)+-forecast(-([a-z]|-)+)?|-forecast-(\d){4}-([a-z]|[0-9]||-)+)$/));
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2021-07-24 08:07:06 +00:00
|
|
|
// if referer exists, set it
|
2020-03-27 18:02:27 +00:00
|
|
|
requestHeaders = requestHeaders.map(function (requestHeader) {
|
2017-07-08 17:40:29 +00:00
|
|
|
if (requestHeader.name === 'Referer') {
|
2021-07-24 08:07:06 +00:00
|
|
|
if (googlebotEnabled || matchUrlDomain(use_google_referer, details.url)) {
|
2021-02-06 20:37:52 +00:00
|
|
|
requestHeader.value = 'https://www.google.com/';
|
|
|
|
} else if (matchUrlDomain(use_facebook_referer, details.url)) {
|
2019-02-13 09:33:45 +00:00
|
|
|
requestHeader.value = 'https://www.facebook.com/';
|
2021-02-04 20:44:25 +00:00
|
|
|
} else if (matchUrlDomain(use_twitter_referer, details.url)) {
|
|
|
|
requestHeader.value = 'https://t.co/';
|
2019-02-13 09:33:45 +00:00
|
|
|
}
|
|
|
|
setReferer = true;
|
|
|
|
}
|
2019-04-06 23:34:30 +00:00
|
|
|
if (requestHeader.name === 'User-Agent') {
|
2022-08-04 15:38:34 +00:00
|
|
|
useUserAgentMobile = requestHeader.value.toLowerCase().includes("mobile") && !matchUrlDomain(['telerama.fr'].concat(it_gedi_domains), details.url);
|
2019-04-06 23:34:30 +00:00
|
|
|
}
|
2019-02-13 09:33:45 +00:00
|
|
|
return requestHeader;
|
|
|
|
});
|
2017-07-08 17:40:29 +00:00
|
|
|
|
|
|
|
// otherwise add it
|
|
|
|
if (!setReferer) {
|
2021-07-24 08:07:06 +00:00
|
|
|
if (googlebotEnabled || matchUrlDomain(use_google_referer, details.url)) {
|
2017-07-08 17:40:29 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
2021-02-06 20:37:52 +00:00
|
|
|
value: 'https://www.google.com/'
|
2017-07-08 17:40:29 +00:00
|
|
|
});
|
2021-02-06 20:37:52 +00:00
|
|
|
} else if (matchUrlDomain(use_facebook_referer, details.url)) {
|
2021-02-04 20:44:25 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
2021-02-06 20:37:52 +00:00
|
|
|
value: 'https://www.facebook.com/'
|
2021-02-04 20:44:25 +00:00
|
|
|
});
|
2021-02-06 20:37:52 +00:00
|
|
|
} else if (matchUrlDomain(use_twitter_referer, details.url)) {
|
2017-07-08 17:40:29 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
2021-02-06 20:37:52 +00:00
|
|
|
value: 'https://t.co/'
|
2017-07-08 17:40:29 +00:00
|
|
|
});
|
|
|
|
}
|
2019-04-06 23:34:30 +00:00
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2019-05-12 20:44:03 +00:00
|
|
|
// override User-Agent to use Googlebot
|
2021-07-24 08:07:06 +00:00
|
|
|
if (googlebotEnabled) {
|
2019-04-06 23:34:30 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "User-Agent",
|
2020-11-02 17:52:40 +00:00
|
|
|
"value": useUserAgentMobile ? userAgentMobileG : userAgentDesktopG
|
2019-04-06 23:34:30 +00:00
|
|
|
})
|
2019-05-12 20:44:03 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "X-Forwarded-For",
|
|
|
|
"value": "66.249.66.1"
|
|
|
|
})
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 17:52:40 +00:00
|
|
|
// override User-Agent to use Bingbot
|
2021-10-25 17:05:57 +00:00
|
|
|
if (bingbotEnabled) {
|
2020-11-02 17:52:40 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "User-Agent",
|
|
|
|
"value": useUserAgentMobile ? userAgentMobileB : userAgentDesktopB
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-12 20:46:50 +00:00
|
|
|
// random IP for sites in use_random_ip
|
2021-12-21 16:36:48 +00:00
|
|
|
let domain_random;
|
|
|
|
if (domain_random = matchUrlDomain(use_random_ip, details.url)) {
|
2021-12-19 14:09:54 +00:00
|
|
|
let randomIP_val;
|
2021-12-21 16:36:48 +00:00
|
|
|
if (random_ip[domain_random] === 'eu')
|
|
|
|
randomIP_val = randomIP(185, 185);
|
2021-12-19 14:09:54 +00:00
|
|
|
else
|
|
|
|
randomIP_val = randomIP();
|
2020-12-03 15:52:33 +00:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "X-Forwarded-For",
|
2021-12-19 14:09:54 +00:00
|
|
|
"value": randomIP_val
|
2020-12-03 15:52:33 +00:00
|
|
|
})
|
|
|
|
}
|
2021-01-12 20:46:50 +00:00
|
|
|
}
|
2020-12-03 15:52:33 +00:00
|
|
|
|
2017-07-08 17:40:29 +00:00
|
|
|
// remove cookies before page load
|
2020-05-01 10:58:36 +00:00
|
|
|
if (!matchUrlDomain(allow_cookies, details.url)) {
|
|
|
|
requestHeaders = requestHeaders.map(function(requestHeader) {
|
|
|
|
if (requestHeader.name === 'Cookie') {
|
|
|
|
requestHeader.value = '';
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
2020-05-01 10:58:36 +00:00
|
|
|
return requestHeader;
|
|
|
|
});
|
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2020-09-14 19:29:13 +00:00
|
|
|
if (tabId !== -1) {
|
|
|
|
ext_api.tabs.get(tabId, function (currentTab) {
|
2022-01-25 18:28:38 +00:00
|
|
|
if (!ext_api.runtime.lastError && currentTab && (isSiteEnabled(currentTab) || medium_custom_domain)) {
|
2020-12-04 15:14:23 +00:00
|
|
|
if (currentTab.url !== currentTabUrl) {
|
|
|
|
csDone = false;
|
|
|
|
currentTabUrl = currentTab.url;
|
|
|
|
}
|
2021-03-27 10:53:38 +00:00
|
|
|
if ((!['font', 'stylesheet'].includes(details.type) || matchUrlDomain(cs_limit_except, currentTabUrl)) && !csDone) {
|
2021-06-29 17:59:15 +00:00
|
|
|
let lib_file = 'lib/empty.js';
|
2022-02-22 18:23:36 +00:00
|
|
|
if (matchUrlDomain(dompurify_sites, currentTabUrl))
|
2021-06-29 17:59:15 +00:00
|
|
|
lib_file = 'lib/purify.min.js';
|
2021-10-17 19:15:00 +00:00
|
|
|
var bg2csData = {
|
|
|
|
optin_setcookie: optin_setcookie,
|
|
|
|
amp_unhide: matchUrlDomain(amp_unhide, currentTabUrl)
|
|
|
|
};
|
2021-11-17 16:45:33 +00:00
|
|
|
let amp_redirect_domain = '';
|
|
|
|
if (amp_redirect_domain = matchUrlDomain(Object.keys(amp_redirect), currentTabUrl))
|
|
|
|
bg2csData.amp_redirect = amp_redirect[amp_redirect_domain];
|
2021-11-18 16:55:25 +00:00
|
|
|
let cs_code_domain = '';
|
|
|
|
if (cs_code_domain = matchUrlDomain(Object.keys(cs_code), currentTabUrl))
|
|
|
|
bg2csData.cs_code = cs_code[cs_code_domain];
|
2022-02-22 18:23:36 +00:00
|
|
|
let ld_json_domain = '';
|
|
|
|
if (ld_json_domain = matchUrlDomain(Object.keys(ld_json), currentTabUrl))
|
|
|
|
bg2csData.ld_json = ld_json[ld_json_domain];
|
2022-08-01 18:49:58 +00:00
|
|
|
let ld_google_webcache_domain = '';
|
|
|
|
if (ld_google_webcache_domain = matchUrlDomain(Object.keys(ld_google_webcache), currentTabUrl))
|
|
|
|
bg2csData.ld_google_webcache = ld_google_webcache[ld_google_webcache_domain];
|
2021-10-17 19:15:00 +00:00
|
|
|
ext_api.tabs.executeScript(tabId, {
|
|
|
|
code: 'var bg2csData = ' + JSON.stringify(bg2csData) + ';'
|
|
|
|
}, function () {
|
2021-06-29 17:59:15 +00:00
|
|
|
ext_api.tabs.executeScript(tabId, {
|
2021-10-17 19:15:00 +00:00
|
|
|
file: lib_file,
|
|
|
|
runAt: 'document_start'
|
2021-10-17 13:16:44 +00:00
|
|
|
}, function () {
|
|
|
|
ext_api.tabs.executeScript(tabId, {
|
2021-10-17 19:15:00 +00:00
|
|
|
file: 'contentScript.js',
|
2021-10-17 13:16:44 +00:00
|
|
|
runAt: 'document_start'
|
2021-10-17 19:15:00 +00:00
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
})
|
2021-10-17 13:16:44 +00:00
|
|
|
});
|
2021-10-17 19:15:00 +00:00
|
|
|
});
|
2020-12-04 15:14:23 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-14 19:29:13 +00:00
|
|
|
});
|
2022-10-13 06:01:45 +00:00
|
|
|
} else { //El Mercurio Regionales, lequipe.fr, arcinfo.ch
|
2020-09-14 19:29:13 +00:00
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2021-12-15 16:44:52 +00:00
|
|
|
if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
|
2021-12-17 20:22:10 +00:00
|
|
|
let currentTab = tabs[0];
|
|
|
|
if (isSiteEnabled(currentTab)) {
|
|
|
|
let lib_file = 'lib/empty.js';
|
2022-10-13 06:01:45 +00:00
|
|
|
if (matchUrlDomain(dompurify_sites, currentTab.url))
|
2021-12-17 20:22:10 +00:00
|
|
|
lib_file = 'lib/purify.min.js';
|
2020-09-14 19:29:13 +00:00
|
|
|
ext_api.tabs.executeScript({
|
2021-12-17 20:22:10 +00:00
|
|
|
file: lib_file,
|
2020-09-14 19:29:13 +00:00
|
|
|
runAt: 'document_start'
|
2021-12-17 20:22:10 +00:00
|
|
|
}, function () {
|
|
|
|
ext_api.tabs.executeScript({
|
|
|
|
file: 'contentScript.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
})
|
2020-09-14 19:29:13 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
}
|
2020-09-14 19:29:13 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
|
|
|
|
return { requestHeaders: requestHeaders };
|
|
|
|
}, {
|
|
|
|
urls: ['<all_urls>']
|
2020-03-25 18:31:28 +00:00
|
|
|
}, extraInfoSpec);
|
|
|
|
// extraInfoSpec is ['blocking', 'requestHeaders'] + possible 'extraHeaders'
|
2017-07-08 17:40:29 +00:00
|
|
|
|
2022-09-09 12:30:20 +00:00
|
|
|
function check_sites_custom_ext() {
|
|
|
|
fetch(sites_custom_ext_json)
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
|
|
|
customSitesExt = Object.values(json).map(x => x.domain);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}).catch(function (err) {
|
|
|
|
false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var customSitesExt = [];
|
|
|
|
var sites_custom_ext_json = 'custom/sites_custom.json';
|
|
|
|
|
2020-05-01 10:58:36 +00:00
|
|
|
ext_api.tabs.onUpdated.addListener(function (tabId, info, tab) { updateBadge(tab); });
|
2021-12-24 07:32:45 +00:00
|
|
|
ext_api.tabs.onActivated.addListener(function (activeInfo) { if (activeInfo.tabId) ext_api.tabs.get(activeInfo.tabId, updateBadge); });
|
2020-05-01 10:58:36 +00:00
|
|
|
|
2020-11-02 15:57:47 +00:00
|
|
|
function updateBadge(activeTab) {
|
2020-11-15 20:10:03 +00:00
|
|
|
if (ext_api.runtime.lastError || !activeTab)
|
2020-11-02 15:57:47 +00:00
|
|
|
return;
|
2020-08-20 17:01:12 +00:00
|
|
|
let badgeText = '';
|
|
|
|
let color = 'red';
|
|
|
|
let currentUrl = activeTab.url;
|
|
|
|
if (currentUrl) {
|
|
|
|
if (isSiteEnabled({url: currentUrl})) {
|
|
|
|
badgeText = 'ON';
|
|
|
|
color = 'red';
|
|
|
|
} else if (matchUrlDomain(enabledSites, currentUrl)) {
|
|
|
|
badgeText = 'ON-';
|
2020-11-02 15:57:47 +00:00
|
|
|
color = 'orange';
|
2020-08-20 17:01:12 +00:00
|
|
|
} else if (matchUrlDomain(disabledSites, currentUrl)) {
|
|
|
|
badgeText = 'OFF';
|
2020-11-02 15:57:47 +00:00
|
|
|
color = 'blue';
|
2022-04-27 18:40:58 +00:00
|
|
|
} else if (matchUrlDomain(nofix_sites, currentUrl)) {
|
|
|
|
badgeText = 'X';
|
2022-09-29 07:24:42 +00:00
|
|
|
color = 'silver';
|
2020-08-20 17:01:12 +00:00
|
|
|
}
|
2021-10-16 06:58:31 +00:00
|
|
|
if (ext_version_new)
|
2021-05-02 05:51:25 +00:00
|
|
|
badgeText = '^' + badgeText;
|
2020-11-02 15:57:47 +00:00
|
|
|
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
|
|
|
|
let isCustomSite = matchUrlDomain(customSites_domains, currentUrl);
|
2021-12-02 17:02:07 +00:00
|
|
|
let isUpdatedSite = matchUrlDomain(updatedSites_domains_new, currentUrl);
|
|
|
|
if (!isDefaultSite && (isCustomSite || isUpdatedSite)) {
|
2020-11-02 15:57:47 +00:00
|
|
|
ext_api.permissions.contains({
|
2021-12-02 17:02:07 +00:00
|
|
|
origins: ['*://*.' + (isCustomSite || isUpdatedSite) + '/*']
|
2020-11-02 15:57:47 +00:00
|
|
|
}, function (result) {
|
|
|
|
if (!result)
|
2021-12-02 17:02:07 +00:00
|
|
|
badgeText = enabledSites.includes(isCustomSite || isUpdatedSite) ? 'C' : '';
|
2020-11-02 15:57:47 +00:00
|
|
|
if (color && badgeText)
|
|
|
|
ext_api.browserAction.setBadgeBackgroundColor({color: color});
|
|
|
|
ext_api.browserAction.setBadgeText({text: badgeText});
|
|
|
|
});
|
2020-11-01 16:46:29 +00:00
|
|
|
} else {
|
2022-09-12 17:54:50 +00:00
|
|
|
if (!badgeText && matchUrlDomain(customSitesExt, currentUrl))
|
2022-09-09 12:30:20 +00:00
|
|
|
badgeText = '+C';
|
2020-11-02 15:57:47 +00:00
|
|
|
if (color && badgeText)
|
|
|
|
ext_api.browserAction.setBadgeBackgroundColor({color: color});
|
2020-11-01 16:46:29 +00:00
|
|
|
ext_api.browserAction.setBadgeText({text: badgeText});
|
2020-11-02 15:57:47 +00:00
|
|
|
}
|
2021-12-15 16:44:52 +00:00
|
|
|
} else
|
|
|
|
ext_api.browserAction.setBadgeText({text: badgeText});
|
2020-03-03 21:37:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 06:58:31 +00:00
|
|
|
var ext_version_new;
|
2021-05-02 05:51:25 +00:00
|
|
|
function check_update() {
|
2022-02-22 16:35:16 +00:00
|
|
|
let manifest_new = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/raw/master/manifest.json';
|
|
|
|
fetch(manifest_new)
|
2021-05-02 05:51:25 +00:00
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
|
|
|
ext_api.management.getSelf(function (result) {
|
|
|
|
var installType = result.installType;
|
2021-10-16 06:58:31 +00:00
|
|
|
var ext_version_len = (installType === 'development') ? 7 : 5;
|
|
|
|
ext_version_new = json['version'];
|
|
|
|
if (ext_version_new.substring(0, ext_version_len) <= ext_version.substring(0, ext_version_len))
|
|
|
|
ext_version_new = '';
|
2021-05-02 05:51:25 +00:00
|
|
|
ext_api.storage.local.set({
|
2021-10-16 06:58:31 +00:00
|
|
|
ext_version_new: ext_version_new
|
2021-05-02 05:51:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
2021-12-14 16:23:40 +00:00
|
|
|
}).catch(function (err) {
|
|
|
|
false;
|
2021-05-02 05:51:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-20 17:01:12 +00:00
|
|
|
function site_switch() {
|
2021-11-19 15:46:52 +00:00
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2021-12-15 16:44:52 +00:00
|
|
|
if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
|
2021-11-19 15:46:52 +00:00
|
|
|
let currentUrl = tabs[0].url;
|
|
|
|
let isDefaultSite = matchUrlDomain(defaultSites_grouped_domains, currentUrl);
|
|
|
|
if (!isDefaultSite) {
|
|
|
|
let isDefaultSiteGroup = matchUrlDomain(defaultSites_domains, currentUrl);
|
|
|
|
if (isDefaultSiteGroup)
|
|
|
|
isDefaultSite = Object.keys(grouped_sites).find(key => grouped_sites[key].includes(isDefaultSiteGroup));
|
|
|
|
}
|
|
|
|
if (!isDefaultSite) {
|
|
|
|
let sites_updated_domains_new = Object.values(updatedSites).filter(x => x.domain && !defaultSites_domains.includes(x.domain));
|
|
|
|
let isUpdatedSite = matchUrlDomain(sites_updated_domains_new, currentUrl);
|
|
|
|
if (isUpdatedSite)
|
|
|
|
isDefaultSite = isUpdatedSite;
|
|
|
|
}
|
|
|
|
let defaultSite_title = isDefaultSite ? Object.keys(defaultSites).find(key => defaultSites[key].domain === isDefaultSite) : '';
|
|
|
|
let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl);
|
|
|
|
let customSite_title = isCustomSite ? Object.keys(customSites).find(key => customSites[key].domain === isCustomSite) : '';
|
|
|
|
let site_title = defaultSite_title || customSite_title;
|
|
|
|
let domain = isDefaultSite || isCustomSite;
|
|
|
|
if (domain && site_title) {
|
|
|
|
let added_site = [];
|
|
|
|
let removed_site = [];
|
|
|
|
if (enabledSites.includes(domain))
|
|
|
|
removed_site.push(site_title);
|
|
|
|
else
|
|
|
|
added_site.push(site_title);
|
|
|
|
ext_api.storage.local.get({
|
|
|
|
sites: {}
|
|
|
|
}, function (items) {
|
|
|
|
var sites = items.sites;
|
|
|
|
for (let key of added_site)
|
|
|
|
sites[key] = domain;
|
2021-12-04 11:12:43 +00:00
|
|
|
for (let key of removed_site) {
|
|
|
|
key = Object.keys(sites).find(sites_key => compareKey(sites_key, key));
|
2021-11-19 15:46:52 +00:00
|
|
|
delete sites[key];
|
2021-12-04 11:12:43 +00:00
|
|
|
}
|
2021-11-19 15:46:52 +00:00
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites: sites
|
|
|
|
}, function () {
|
|
|
|
true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-03-03 21:37:45 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 10:32:38 +00:00
|
|
|
function remove_cookies_fn(domainVar, exclusions = false) {
|
2021-02-17 18:11:27 +00:00
|
|
|
ext_api.cookies.getAllCookieStores(function (cookieStores) {
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2021-12-24 07:32:45 +00:00
|
|
|
if (!ext_api.runtime.lastError && tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
|
2021-02-17 18:11:27 +00:00
|
|
|
let tabId = tabs[0].id;
|
2021-02-28 10:32:38 +00:00
|
|
|
let storeId = '0';
|
2021-02-17 18:11:27 +00:00
|
|
|
for (let store of cookieStores) {
|
|
|
|
if (store.tabIds.includes(tabId))
|
|
|
|
storeId = store.id;
|
|
|
|
}
|
2021-02-22 18:49:41 +00:00
|
|
|
storeId = storeId.toString();
|
2021-11-09 16:18:34 +00:00
|
|
|
if (domainVar === 'asia.nikkei.com')
|
|
|
|
domainVar = 'nikkei.com';
|
2021-02-22 18:49:41 +00:00
|
|
|
var cookie_get_options = {
|
|
|
|
domain: domainVar
|
|
|
|
};
|
|
|
|
if (storeId !== 'null')
|
|
|
|
cookie_get_options.storeId = storeId;
|
|
|
|
var cookie_remove_options = {};
|
|
|
|
ext_api.cookies.getAll(cookie_get_options, function (cookies) {
|
2021-02-17 18:11:27 +00:00
|
|
|
for (let cookie of cookies) {
|
2021-02-28 10:32:38 +00:00
|
|
|
if (exclusions) {
|
|
|
|
var rc_domain = cookie.domain.replace(/^(\.?www\.|\.)/, '');
|
|
|
|
// hold specific cookie(s) from remove_cookies domains
|
|
|
|
if ((rc_domain in remove_cookies_select_hold) && remove_cookies_select_hold[rc_domain].includes(cookie.name)) {
|
|
|
|
continue; // don't remove specific cookie
|
|
|
|
}
|
|
|
|
// drop only specific cookie(s) from remove_cookies domains
|
|
|
|
if ((rc_domain in remove_cookies_select_drop) && !(remove_cookies_select_drop[rc_domain].includes(cookie.name))) {
|
|
|
|
continue; // only remove specific cookie
|
|
|
|
}
|
|
|
|
// hold on to consent-cookie
|
|
|
|
if (cookie.name.match(/(consent|^optanon)/i)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-02-17 18:11:27 +00:00
|
|
|
}
|
2021-02-23 16:44:54 +00:00
|
|
|
cookie.domain = cookie.domain.replace(/^\./, '');
|
2021-02-22 18:49:41 +00:00
|
|
|
cookie_remove_options = {
|
2021-02-17 18:11:27 +00:00
|
|
|
url: (cookie.secure ? "https://" : "http://") + cookie.domain + cookie.path,
|
2021-02-22 18:49:41 +00:00
|
|
|
name: cookie.name
|
|
|
|
};
|
|
|
|
if (storeId !== 'null')
|
|
|
|
cookie_remove_options.storeId = storeId;
|
|
|
|
ext_api.cookies.remove(cookie_remove_options);
|
2021-02-17 18:11:27 +00:00
|
|
|
}
|
|
|
|
});
|
2021-01-02 11:48:07 +00:00
|
|
|
}
|
2021-02-17 18:11:27 +00:00
|
|
|
});
|
|
|
|
})
|
2021-02-28 10:32:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove cookies after page load
|
|
|
|
ext_api.webRequest.onCompleted.addListener(function (details) {
|
2022-04-28 15:52:26 +00:00
|
|
|
let domain = matchUrlDomain(remove_cookies, details.url);
|
2021-11-16 17:00:53 +00:00
|
|
|
let types = ['main_frame', 'sub_frame', 'xmlhttprequest', 'other'];
|
2022-04-28 15:52:26 +00:00
|
|
|
if (['medium.com'].concat(medium_custom_domains).includes(domain))
|
2021-11-16 17:00:53 +00:00
|
|
|
types = ['main_frame', 'image'];
|
2022-04-28 15:52:26 +00:00
|
|
|
if (domain && types.includes(details.type) && enabledSites.includes(domain)) {
|
|
|
|
remove_cookies_fn(domain, true);
|
2021-07-22 15:09:36 +00:00
|
|
|
}
|
2017-07-08 17:40:29 +00:00
|
|
|
}, {
|
2020-10-24 14:38:01 +00:00
|
|
|
urls: ["<all_urls>"]
|
2018-08-28 23:15:23 +00:00
|
|
|
});
|
2019-02-10 23:43:12 +00:00
|
|
|
|
2020-10-12 15:31:51 +00:00
|
|
|
function clear_cookies() {
|
2020-10-24 14:38:01 +00:00
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2021-12-15 16:44:52 +00:00
|
|
|
if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
|
2020-10-24 14:38:01 +00:00
|
|
|
ext_api.tabs.executeScript({
|
2021-03-27 07:31:03 +00:00
|
|
|
file: 'options/clearCookies.js',
|
2020-10-24 14:38:01 +00:00
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
2020-10-12 15:31:51 +00:00
|
|
|
}
|
2020-10-24 14:38:01 +00:00
|
|
|
});
|
|
|
|
ext_api.tabs.update(tabs[0].id, {
|
|
|
|
url: tabs[0].url
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-10-12 15:31:51 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 17:39:46 +00:00
|
|
|
var chrome_scheme = 'light';
|
2020-09-08 14:38:18 +00:00
|
|
|
ext_api.runtime.onMessage.addListener(function (message, sender) {
|
2021-02-17 18:11:27 +00:00
|
|
|
if (message.request === 'clear_cookies') {
|
|
|
|
clear_cookies();
|
|
|
|
}
|
2020-10-24 14:38:01 +00:00
|
|
|
// clear cookies for domain
|
|
|
|
if (message.domain) {
|
2021-02-28 10:32:38 +00:00
|
|
|
remove_cookies_fn(message.domain);
|
2021-02-17 18:11:27 +00:00
|
|
|
}
|
|
|
|
if (message.request === 'site_switch') {
|
|
|
|
site_switch();
|
|
|
|
}
|
2021-12-02 17:02:07 +00:00
|
|
|
if (message.request === 'check_sites_updated') {
|
|
|
|
check_sites_updated();
|
|
|
|
}
|
2021-02-17 18:11:27 +00:00
|
|
|
if (message.request === 'popup_show_toggle') {
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2021-12-15 16:44:52 +00:00
|
|
|
if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
|
2021-02-17 18:11:27 +00:00
|
|
|
let currentUrl = tabs[0].url;
|
|
|
|
let domain;
|
|
|
|
let isExcludedSite = matchUrlDomain(excludedSites, currentUrl);
|
|
|
|
if (!isExcludedSite) {
|
|
|
|
let isDefaultSiteGrouped = matchUrlDomain(defaultSites_domains, currentUrl);
|
|
|
|
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
|
|
|
|
let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl);
|
|
|
|
domain = isDefaultSiteGrouped || (!isDefaultSite && isCustomSite);
|
|
|
|
}
|
|
|
|
ext_api.runtime.sendMessage({
|
|
|
|
msg: "popup_show_toggle",
|
|
|
|
data: {
|
|
|
|
domain: domain,
|
|
|
|
enabled: enabledSites.includes(domain)
|
|
|
|
}
|
2020-10-12 15:31:51 +00:00
|
|
|
});
|
2020-10-24 14:38:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-06-09 19:32:35 +00:00
|
|
|
if (message.request === 'refreshCurrentTab') {
|
|
|
|
refreshCurrentTab();
|
|
|
|
}
|
2022-04-09 15:07:30 +00:00
|
|
|
if (message.request === 'getExtSrc' && message.data) {
|
|
|
|
fetch(message.data.url)
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.text().then(html => {
|
|
|
|
if (message.data.base64) {
|
|
|
|
html = decode_utf8(atob(html));
|
|
|
|
message.data.selector_source = 'body';
|
|
|
|
}
|
|
|
|
let parser = new DOMParser();
|
|
|
|
let doc = parser.parseFromString(html, 'text/html');
|
|
|
|
let article_new = doc.querySelector(message.data.selector_source);
|
2022-08-02 17:05:09 +00:00
|
|
|
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});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-04-09 15:07:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch(function (err) {
|
|
|
|
message.data.html = '';
|
|
|
|
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});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-02-21 08:21:39 +00:00
|
|
|
if (message.scheme && (![chrome_scheme, 'undefined'].includes(message.scheme) || focus_changed)) {
|
2020-10-29 17:39:46 +00:00
|
|
|
let icon_path = {path: {'128': 'bypass.png'}};
|
|
|
|
if (message.scheme === 'dark')
|
|
|
|
icon_path = {path: {'128': 'bypass-dark.png'}};
|
|
|
|
ext_api.browserAction.setIcon(icon_path);
|
|
|
|
chrome_scheme = message.scheme;
|
2021-02-21 08:21:39 +00:00
|
|
|
focus_changed = false;
|
2020-10-29 17:39:46 +00:00
|
|
|
}
|
2020-12-04 15:14:23 +00:00
|
|
|
if (message.csDone) {
|
|
|
|
csDone = true;
|
|
|
|
//console.log('msg.csDone: ' + csDone);
|
|
|
|
}
|
2020-09-08 14:38:18 +00:00
|
|
|
});
|
|
|
|
|
2021-03-07 13:03:22 +00:00
|
|
|
// show the opt-in tab on installation
|
2020-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.get(["optInShown", "customShown"], function (result) {
|
2020-10-24 14:38:01 +00:00
|
|
|
if (!result.optInShown || !result.customShown) {
|
|
|
|
ext_api.tabs.create({
|
2021-03-30 18:52:32 +00:00
|
|
|
url: "options/optin/opt-in.html"
|
2020-10-24 14:38:01 +00:00
|
|
|
});
|
2020-10-31 19:06:38 +00:00
|
|
|
ext_api.storage.local.set({
|
2020-10-24 14:38:01 +00:00
|
|
|
"optInShown": true,
|
|
|
|
"customShown": true
|
|
|
|
});
|
|
|
|
}
|
2020-09-08 14:38:18 +00:00
|
|
|
});
|
|
|
|
|
2021-04-03 17:03:46 +00:00
|
|
|
// restore custom sites opt-in on reload (chrome-only, load upacked)
|
|
|
|
if (typeof browser !== 'object') {
|
|
|
|
ext_api.storage.local.get({
|
|
|
|
sites: {},
|
|
|
|
customOptIn: false
|
|
|
|
}, function (result) {
|
|
|
|
let options_restore_custom = Object.values(result.sites).includes('#options_restore_custom');
|
|
|
|
if (result.customOptIn && options_restore_custom) {
|
|
|
|
ext_api.permissions.contains({
|
|
|
|
origins: ["<all_urls>"]
|
|
|
|
}, function (result_perm) {
|
|
|
|
if (!result_perm) {
|
|
|
|
ext_api.tabs.create({
|
|
|
|
url: "options/optin/opt-in.html"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-04 17:50:19 +00:00
|
|
|
function filterObject(obj, filterFn, mapFn = function (val, key) {
|
|
|
|
return [key, val];
|
|
|
|
}) {
|
2021-03-26 12:05:20 +00:00
|
|
|
return Object.fromEntries(Object.entries(obj).
|
2021-11-04 17:50:19 +00:00
|
|
|
filter(([key, val]) => filterFn(val, key)).map(([key, val]) => mapFn(val, key)));
|
2021-03-26 12:05:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 11:12:43 +00:00
|
|
|
function compareKey(firstStr, secondStr) {
|
|
|
|
return firstStr.toLowerCase().replace(/\s\(.*\)/, '') === secondStr.toLowerCase().replace(/\s\(.*\)/, '');
|
|
|
|
}
|
|
|
|
|
2019-02-10 23:43:12 +00:00
|
|
|
function isSiteEnabled(details) {
|
2020-10-24 14:38:01 +00:00
|
|
|
var enabledSite = matchUrlDomain(enabledSites, details.url);
|
2021-03-07 13:03:22 +00:00
|
|
|
if (!ext_name.startsWith('Bypass Paywalls Clean'))
|
2020-10-24 14:38:01 +00:00
|
|
|
enabledSite = '';
|
|
|
|
if (enabledSite in restrictions) {
|
|
|
|
return restrictions[enabledSite].test(details.url);
|
|
|
|
}
|
|
|
|
return !!enabledSite;
|
2020-05-01 10:58:36 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 19:40:38 +00:00
|
|
|
function matchDomain(domains, hostname = '') {
|
2020-10-24 14:38:01 +00:00
|
|
|
var matched_domain = false;
|
|
|
|
if (typeof domains === 'string')
|
|
|
|
domains = [domains];
|
|
|
|
domains.some(domain => (hostname === domain || hostname.endsWith('.' + domain)) && (matched_domain = domain));
|
|
|
|
return matched_domain;
|
2020-05-01 10:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function urlHost(url) {
|
2020-10-24 14:38:01 +00:00
|
|
|
if (url && url.startsWith('http')) {
|
|
|
|
try {
|
|
|
|
return new URL(url).hostname;
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`url not valid: ${url} error: ${e}`);
|
2020-05-01 10:58:36 +00:00
|
|
|
}
|
2020-10-24 14:38:01 +00:00
|
|
|
}
|
|
|
|
return url;
|
2020-05-01 10:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function matchUrlDomain(domains, url) {
|
2020-10-24 14:38:01 +00:00
|
|
|
return matchDomain(domains, urlHost(url));
|
2019-02-10 23:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getParameterByName(name, url) {
|
|
|
|
name = name.replace(/[\[\]]/g, '\\$&');
|
|
|
|
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
|
|
|
|
results = regex.exec(url);
|
|
|
|
if (!results) return null;
|
|
|
|
if (!results[2]) return '';
|
|
|
|
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
|
|
|
}
|
2020-01-28 22:06:25 +00:00
|
|
|
|
|
|
|
function stripQueryStringAndHashFromPath(url) {
|
|
|
|
return url.split("?")[0].split("#")[0];
|
2020-03-25 18:31:28 +00:00
|
|
|
}
|
2020-12-03 15:52:33 +00:00
|
|
|
|
2022-04-09 15:07:30 +00:00
|
|
|
function decode_utf8(str) {
|
|
|
|
return decodeURIComponent(escape(str));
|
|
|
|
}
|
|
|
|
|
2020-12-03 15:52:33 +00:00
|
|
|
function randomInt(max) {
|
|
|
|
return Math.floor(Math.random() * Math.floor(max));
|
|
|
|
}
|
|
|
|
|
2021-12-19 14:09:54 +00:00
|
|
|
function randomIP(range_low = 0, range_high = 223) {
|
2020-12-03 15:52:33 +00:00
|
|
|
let rndmIP = [];
|
2021-12-19 14:09:54 +00:00
|
|
|
for (let n = 0; n < 4; n++) {
|
|
|
|
if (n === 0)
|
2021-12-21 16:36:48 +00:00
|
|
|
rndmIP.push(range_low + randomInt(range_high - range_low + 1));
|
2021-12-19 14:09:54 +00:00
|
|
|
else
|
|
|
|
rndmIP.push(randomInt(255) + 1);
|
|
|
|
}
|
2020-12-03 15:52:33 +00:00
|
|
|
return rndmIP.join('.');
|
|
|
|
}
|
2021-06-09 19:32:35 +00:00
|
|
|
|
|
|
|
// Refresh the current tab
|
|
|
|
function refreshCurrentTab() {
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2021-12-15 16:44:52 +00:00
|
|
|
if (tabs && tabs[0] && tabs[0].url && tabs[0].url.startsWith('http')) {
|
2021-06-12 16:19:48 +00:00
|
|
|
if (ext_api.runtime.lastError)
|
|
|
|
return;
|
2021-06-09 19:32:35 +00:00
|
|
|
ext_api.tabs.update(tabs[0].id, {
|
|
|
|
url: tabs[0].url
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|