2017-07-08 19:40:29 +02:00
|
|
|
'use strict';
|
2020-05-01 12:58:36 +02:00
|
|
|
var ext_api = (typeof browser === 'object') ? browser : chrome;
|
2021-11-07 08:47:42 +01:00
|
|
|
var url_loc = (typeof browser === 'object') ? 'firefox' : 'chrome';
|
2021-10-16 08:58:31 +02:00
|
|
|
var manifestData = ext_api.runtime.getManifest();
|
|
|
|
var ext_name = manifestData.name;
|
|
|
|
var ext_version = manifestData.version;
|
2022-11-08 20:40:49 +01:00
|
|
|
var navigator_ua = navigator.userAgent;
|
|
|
|
var navigator_ua_mobile = navigator_ua.toLowerCase().includes('mobile');
|
2022-11-17 17:20:50 +01:00
|
|
|
var kiwi_browser = navigator_ua_mobile && (url_loc === 'chrome') && !navigator_ua.toLowerCase().includes('yabrowser');
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2022-12-07 13:14:32 +01:00
|
|
|
if (typeof ext_api.action !== 'object') {
|
|
|
|
ext_api.action = ext_api.browserAction;
|
|
|
|
}
|
|
|
|
|
2023-06-27 12:26:17 +02:00
|
|
|
var dompurify_sites = [];
|
2023-05-08 20:05:06 +02:00
|
|
|
var optin_setcookie = false;
|
2021-11-10 17:46:22 +01:00
|
|
|
var optin_update = true;
|
2022-01-05 20:40:38 +01:00
|
|
|
var blocked_referer = false;
|
2020-12-04 16:14:23 +01:00
|
|
|
|
2020-02-25 22:47:05 +01:00
|
|
|
// defaultSites are loaded from sites.js at installation extension
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2022-01-05 20:40:38 +01:00
|
|
|
var restrictions = {
|
2021-08-03 20:03:11 +02:00
|
|
|
'bloomberg.com': /^((?!\.bloomberg\.com\/news\/terminal\/).)*$/,
|
2023-02-28 18:16:44 +01:00
|
|
|
'bloombergadria.com': /^((?!\.bloombergadria\.com\/video\/).)*$/,
|
2022-07-01 15:47:47 +02:00
|
|
|
'dailywire.com': /^((?!\.dailywire\.com\/(episode|show|videos|watch)).)*$/,
|
2022-01-05 20:40:38 +01:00
|
|
|
'economictimes.com': /\.economictimes\.com($|\/($|(__assets|prime)(\/.+)?|.+\.cms))/,
|
2021-03-13 16:49:58 +01:00
|
|
|
'elespanol.com': /^((?!\/cronicaglobal\.elespanol\.com\/).)*$/,
|
2022-05-22 16:09:51 +02:00
|
|
|
'espn.com': /^((?!espn\.com\/watch).)*$/,
|
2022-09-04 09:13:36 +02:00
|
|
|
'esquire.com': /^((?!\/classic\.esquire\.com\/).)*$/,
|
2023-04-08 19:19:49 +02:00
|
|
|
'foreignaffairs.com': /^((?!\/reader\.foreignaffairs\.com\/).)*$/,
|
2023-04-01 09:28:21 +02:00
|
|
|
'hilltimes.com': /^((?!hilltimes\.com\/slideshow\/).)*$/,
|
2022-07-10 08:35:21 +02:00
|
|
|
'nytimes.com': /^((?!\/timesmachine\.nytimes\.com\/).)*$/,
|
2022-01-04 21:57:52 +01:00
|
|
|
'science.org': /^((?!\.science\.org\/doi\/).)*$/,
|
2022-01-05 20:40:38 +01:00
|
|
|
'timesofindia.com': /\.timesofindia\.com($|\/($|toi-plus(\/.+)?|.+\.cms))/,
|
2020-05-27 17:11:31 +02:00
|
|
|
'quora.com': /^((?!quora\.com\/search\?q=).)*$/,
|
2022-01-05 20:40:38 +01:00
|
|
|
'seekingalpha.com': /\/seekingalpha\.com($|\/($|(amp\/)?(article|news)\/|samw\/))/,
|
2023-01-18 17:19:26 +01:00
|
|
|
'statista.com': /^((?!\.statista\.com\/study\/).)*$/,
|
2023-05-17 18:14:27 +02:00
|
|
|
'tagesspiegel.de': /^((?!\/(background|checkpoint)\.tagesspiegel\.de\/).)*$/,
|
2021-02-15 19:06:51 +01:00
|
|
|
'techinasia.com': /\.techinasia\.com\/.+/,
|
2022-08-06 07:49:29 +02:00
|
|
|
'theatlantic.com': /^((?!\/newsletters\.theatlantic\.com\/).)*$/,
|
2022-08-10 19:19:51 +02:00
|
|
|
'thetimes.co.uk': /^((?!epaper\.thetimes\.co\.uk).)*$/,
|
2022-08-18 21:56:52 +02:00
|
|
|
'timeshighereducation.com': /\.timeshighereducation\.com\/((features|news|people)\/|.+((\w)+(\-)+){3,}.+|sites\/default\/files\/)/,
|
|
|
|
'uol.com.br': /^((?!(conta|email)\.uol\.com\.br).)*$/,
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
|
|
|
|
2021-12-19 11:13:00 +01:00
|
|
|
for (let domain of au_news_corp_domains)
|
|
|
|
restrictions[domain] = new RegExp('^((?!todayspaper\\.' + domain.replace(/\./g, '\\.') + '\\/).)*$');
|
2022-01-22 18:37:56 +01:00
|
|
|
if (typeof browser !== 'object') {
|
2022-04-21 19:52:47 +02:00
|
|
|
for (let domain of [])
|
2022-01-22 18:37:56 +01:00
|
|
|
restrictions[domain] = new RegExp('((\\/|\\.)' + domain.replace(/\./g, '\\.') + '\\/$|' + restrictions[domain].toString().replace(/(^\/|\/$)/g, '') + ')');
|
|
|
|
}
|
2021-12-19 11:13:00 +01:00
|
|
|
|
2021-11-04 18:50:19 +01: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
|
2022-12-09 17:08:18 +01:00
|
|
|
var use_google_bot, use_bing_bot, use_facebook_bot;
|
2021-11-04 18:50:19 +01:00
|
|
|
// Set Referer
|
|
|
|
var use_facebook_referer, use_google_referer, use_twitter_referer;
|
|
|
|
// Set random IP-address
|
2021-12-21 17:36:48 +01:00
|
|
|
var random_ip = {};
|
|
|
|
var use_random_ip = [];
|
2021-11-04 18:50:19 +01:00
|
|
|
// concat all sites with change of headers (useragent, referer or random ip)
|
|
|
|
var change_headers;
|
2021-01-12 21:46:50 +01:00
|
|
|
|
2022-11-03 20:43:36 +01:00
|
|
|
// block paywall-scripts
|
2021-11-04 18:50:19 +01:00
|
|
|
var blockedRegexes = {};
|
2022-11-02 21:58:15 +01:00
|
|
|
var blockedRegexesDomains = [];
|
|
|
|
var blockedRegexesGeneral = {};
|
2022-11-03 20:43:36 +01:00
|
|
|
var blockedJsInline = {};
|
|
|
|
var blockedJsInlineDomains = [];
|
2021-11-04 18:50:19 +01:00
|
|
|
|
|
|
|
// unhide text on amp-page
|
|
|
|
var amp_unhide;
|
2021-11-17 17:45:33 +01:00
|
|
|
// redirect to amp-page
|
|
|
|
var amp_redirect;
|
2021-11-18 17:55:25 +01:00
|
|
|
// code for contentScript
|
|
|
|
var cs_code;
|
2023-05-07 13:13:41 +02:00
|
|
|
// load text from json (script[type="application/ld+json"])
|
2022-02-22 19:23:36 +01:00
|
|
|
var ld_json;
|
2023-05-07 13:13:41 +02:00
|
|
|
// load text from json (script#__NEXT_DATA__)
|
|
|
|
var ld_json_next;
|
2022-08-01 20:49:58 +02:00
|
|
|
// load text from Google webcache
|
|
|
|
var ld_google_webcache;
|
2023-02-19 12:36:09 +01:00
|
|
|
// add external link to article
|
|
|
|
var add_ext_link;
|
2021-11-04 18:50:19 +01: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 = [];
|
2022-12-09 17:08:18 +01:00
|
|
|
use_facebook_bot = [];
|
2021-11-04 18:50:19 +01:00
|
|
|
use_facebook_referer = [];
|
|
|
|
use_google_referer = [];
|
|
|
|
use_twitter_referer = [];
|
2021-12-21 17:36:48 +01:00
|
|
|
random_ip = {};
|
2021-11-04 18:50:19 +01:00
|
|
|
change_headers = [];
|
|
|
|
amp_unhide = [];
|
2021-11-17 17:45:33 +01:00
|
|
|
amp_redirect = {};
|
2021-11-18 17:55:25 +01:00
|
|
|
cs_code = {};
|
2022-02-22 19:23:36 +01:00
|
|
|
ld_json = {};
|
2023-05-07 13:13:41 +02:00
|
|
|
ld_json_next = {};
|
2022-08-01 20:49:58 +02:00
|
|
|
ld_google_webcache = {};
|
2023-02-19 12:36:09 +01:00
|
|
|
add_ext_link = {};
|
2021-11-04 18:50:19 +01:00
|
|
|
block_js_custom = [];
|
|
|
|
block_js_custom_ext = [];
|
|
|
|
blockedRegexes = {};
|
2022-11-02 21:58:15 +01:00
|
|
|
blockedRegexesDomains = [];
|
|
|
|
blockedRegexesGeneral = {};
|
2022-11-03 20:43:36 +01:00
|
|
|
blockedJsInline = {};
|
|
|
|
blockedJsInlineDomains = [];
|
2022-12-07 13:14:32 +01:00
|
|
|
init_custom_flex_domains();
|
2021-11-04 18:50:19 +01:00
|
|
|
}
|
2020-07-06 19:30:48 +02:00
|
|
|
|
2022-11-21 08:09:07 +01: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)";
|
2020-11-02 18:52:40 +01:00
|
|
|
|
2022-11-21 08:09:07 +01:00
|
|
|
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)";
|
|
|
|
|
2022-12-09 17:08:18 +01:00
|
|
|
const userAgentDesktopF = 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)';
|
2019-04-07 01:34:30 +02:00
|
|
|
|
2017-07-08 19:40:29 +02:00
|
|
|
var enabledSites = [];
|
2020-08-20 19:01:12 +02:00
|
|
|
var disabledSites = [];
|
2021-11-04 18:50:19 +01:00
|
|
|
var optionSites = {};
|
2020-08-20 19:01:12 +02:00
|
|
|
var customSites = {};
|
|
|
|
var customSites_domains = [];
|
2021-11-07 08:47:42 +01:00
|
|
|
var updatedSites = {};
|
2021-11-14 13:40:46 +01:00
|
|
|
var updatedSites_new = [];
|
2021-12-02 18:02:07 +01:00
|
|
|
var updatedSites_domains_new = [];
|
2021-01-05 18:53:59 +01:00
|
|
|
var excludedSites = [];
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2020-01-28 23:06:25 +01:00
|
|
|
function setDefaultOptions() {
|
2020-10-31 20:06:38 +01:00
|
|
|
ext_api.storage.local.set({
|
2021-03-26 13:05:20 +01:00
|
|
|
sites: filterObject(defaultSites, function (val, key) {
|
2022-05-17 20:30:08 +02:00
|
|
|
return val.domain && !val.domain.match(/^(###$|#options_(disable|optin)_)/)
|
2021-11-04 18:50:19 +01:00
|
|
|
},
|
|
|
|
function (val, key) {
|
|
|
|
return [key, val.domain]
|
2021-03-26 13:05:20 +01:00
|
|
|
})
|
2020-10-24 16:38:01 +02:00
|
|
|
}, function () {
|
2020-03-25 19:31:28 +01:00
|
|
|
ext_api.runtime.openOptionsPage();
|
2020-01-28 23:06:25 +01:00
|
|
|
});
|
2020-03-27 19:02:27 +01:00
|
|
|
}
|
2020-03-25 19:31:28 +01:00
|
|
|
|
2021-11-07 08:47:42 +01:00
|
|
|
function check_sites_updated() {
|
2022-02-22 17:35:16 +01: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 08:47:42 +01:00
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
2021-11-14 13:40:46 +01:00
|
|
|
expandSiteRules(json, true);
|
2021-11-07 08:47:42 +01:00
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites_updated: json
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}).catch(function (err) {
|
|
|
|
false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-17 17:20:50 +01:00
|
|
|
function prep_regex_str(str, domain = '') {
|
|
|
|
if (domain)
|
|
|
|
str = str.replace(/{domain}/g, domain.replace(/\./g, '\\.'));
|
|
|
|
return str.replace(/^\//, '').replace(/\/\//g, '/').replace(/([^\\])\/$/, "$1")
|
|
|
|
}
|
|
|
|
|
2023-05-28 09:34:59 +02:00
|
|
|
function addRules(domain, rule) {
|
|
|
|
if (rule.hasOwnProperty('remove_cookies_select_drop') || rule.hasOwnProperty('remove_cookies_select_hold')) {
|
|
|
|
rule.allow_cookies = 1;
|
|
|
|
rule.remove_cookies = 1;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
blockedRegexes[domain] = new RegExp(prep_regex_str(rule.block_regex, domain));
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`regex not valid, error: ${e}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rule.hasOwnProperty('block_regex_general')) {
|
|
|
|
if (rule.block_regex_general instanceof RegExp)
|
|
|
|
blockedRegexesGeneral[domain] = {block_regex: rule.block_regex_general};
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
blockedRegexesGeneral[domain] = {block_regex: new RegExp(prep_regex_str(rule.block_regex_general, domain))};
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`regex not valid, error: ${e}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
blockedRegexesGeneral[domain]['excluded_domains'] = rule.excluded_domains ? rule.excluded_domains : [];
|
|
|
|
}
|
|
|
|
if (rule.hasOwnProperty('block_js_inline')) {
|
|
|
|
if (rule.block_js_inline instanceof RegExp)
|
|
|
|
blockedJsInline[domain] = rule.block_js_inline;
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
blockedJsInline[domain] = new RegExp(prep_regex_str(rule.block_js_inline, domain));
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`regex not valid, error: ${e}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
case 'facebookbot':
|
|
|
|
if (!use_facebook_bot.includes(domain))
|
|
|
|
use_facebook_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rule.random_ip) {
|
|
|
|
random_ip[domain] = rule.random_ip;
|
|
|
|
}
|
|
|
|
if (rule.amp_unhide > 0 && !amp_unhide.includes(domain))
|
|
|
|
amp_unhide.push(domain);
|
|
|
|
if (rule.amp_redirect)
|
|
|
|
amp_redirect[domain] = rule.amp_redirect.paywall ? rule.amp_redirect : {paywall: rule.amp_redirect};
|
|
|
|
if (rule.cs_code) {
|
|
|
|
if (typeof rule.cs_code === 'string') {
|
|
|
|
try {
|
|
|
|
rule.cs_code = JSON.parse(rule.cs_code);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`cs_code not valid: ${rule.cs_code} error: ${e}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof rule.cs_code === 'object')
|
|
|
|
cs_code[domain] = rule.cs_code;
|
|
|
|
}
|
|
|
|
if (rule.ld_json)
|
|
|
|
ld_json[domain] = rule.ld_json;
|
|
|
|
if (rule.ld_json_next)
|
|
|
|
ld_json_next[domain] = rule.ld_json_next;
|
|
|
|
if (rule.ld_google_webcache)
|
|
|
|
ld_google_webcache[domain] = rule.ld_google_webcache;
|
2023-06-27 12:26:17 +02:00
|
|
|
if (rule.ld_json || rule.ld_json_next || rule.ld_google_webcache || rule.cs_dompurify)
|
2023-05-28 09:34:59 +02:00
|
|
|
if (!dompurify_sites.includes(domain))
|
|
|
|
dompurify_sites.push(domain);
|
|
|
|
if (rule.add_ext_link && rule.add_ext_link_type)
|
|
|
|
add_ext_link[domain] = {css: rule.add_ext_link, type: rule.add_ext_link_type};
|
|
|
|
|
|
|
|
// custom
|
|
|
|
if (rule.googlebot > 0)
|
|
|
|
use_google_bot.push(domain); // legacy
|
|
|
|
if (rule.block_js > 0 || rule.block_javascript > 0)
|
|
|
|
block_js_custom.push(domain);
|
|
|
|
if (rule.block_js_ext > 0 || rule.block_javascript_ext > 0)
|
|
|
|
block_js_custom_ext.push(domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
function customFlexAddRules(custom_domain, rule) {
|
|
|
|
addRules(custom_domain, rule);
|
|
|
|
if (blockedRegexes[custom_domain])
|
|
|
|
blockedRegexesDomains.push(custom_domain);
|
|
|
|
if (blockedJsInline[custom_domain]) {
|
|
|
|
blockedJsInlineDomains.push(custom_domain);
|
|
|
|
disableJavascriptInline();
|
|
|
|
}
|
|
|
|
if (rule.useragent || rule.referer || rule.random_ip)
|
|
|
|
change_headers.push(custom_domain);
|
|
|
|
if (rule.random_ip)
|
|
|
|
use_random_ip.push(custom_domain);
|
|
|
|
ext_api.tabs.reload({bypassCache: true});
|
|
|
|
}
|
|
|
|
|
2021-11-07 08:47:42 +01:00
|
|
|
function set_rules(sites, sites_updated, sites_custom) {
|
2021-11-04 18:50:19 +01: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 17:48:30 +02: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];
|
2023-05-13 19:13:03 +02:00
|
|
|
let site_updated = Object.keys(sites_updated).find(updated_key => compareKey(updated_key, site));
|
2023-06-25 19:05:10 +02:00
|
|
|
if (site_updated && !(sites_updated[site_updated].new_site || (sites_updated[site_updated].upd_version && (sites_updated[site_updated].upd_version <= ext_version))))
|
2023-05-13 19:13:03 +02:00
|
|
|
rule = sites_updated[site_updated];
|
2021-11-13 11:43:09 +01: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 18:50:19 +01:00
|
|
|
rule = sites_custom[site];
|
|
|
|
custom = true;
|
2021-11-07 09:34:11 +01:00
|
|
|
} else
|
|
|
|
continue;
|
2021-11-04 18:50:19 +01: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 18:14:07 +01:00
|
|
|
let exception_rule = rule_default.exception.filter(x => domain === x.domain || (typeof x.domain !== 'string' && x.domain.includes(domain)));
|
2021-11-04 18:50:19 +01: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) : '';
|
2023-04-20 20:56:23 +02:00
|
|
|
if (customSite_title && !rule.add_ext_link) {
|
2021-11-04 18:50:19 +01:00
|
|
|
// add default block_regex
|
|
|
|
let block_regex_default = '';
|
|
|
|
if (rule.hasOwnProperty('block_regex'))
|
|
|
|
block_regex_default = rule.block_regex;
|
2021-11-07 08:47:42 +01:00
|
|
|
rule = {};
|
|
|
|
for (let key in sites_custom[customSite_title])
|
|
|
|
rule[key] = sites_custom[customSite_title][key];
|
2021-11-04 18:50:19 +01:00
|
|
|
if (block_regex_default) {
|
|
|
|
if (rule.hasOwnProperty('block_regex')) {
|
|
|
|
if (block_regex_default instanceof RegExp)
|
|
|
|
block_regex_default = block_regex_default.source;
|
2022-11-17 17:20:50 +01:00
|
|
|
rule.block_regex = '(' + block_regex_default + '|' + prep_regex_str(rule.block_regex, domain) + ')';
|
2021-11-04 18:50:19 +01:00
|
|
|
} else
|
|
|
|
rule.block_regex = block_regex_default;
|
|
|
|
}
|
|
|
|
if (group)
|
|
|
|
custom_in_group = true;
|
|
|
|
else
|
|
|
|
custom = true;
|
|
|
|
}
|
|
|
|
}
|
2023-05-28 09:34:59 +02:00
|
|
|
addRules(domain, rule);
|
2021-11-04 18:50:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-02 21:58:15 +01:00
|
|
|
blockedRegexesDomains = Object.keys(blockedRegexes);
|
2022-11-03 20:43:36 +01:00
|
|
|
blockedJsInlineDomains = Object.keys(blockedJsInline);
|
2022-11-05 15:09:46 +01:00
|
|
|
disableJavascriptInline();
|
2021-12-21 17:36:48 +01:00
|
|
|
use_random_ip = Object.keys(random_ip);
|
2022-12-09 17:08:18 +01:00
|
|
|
change_headers = use_google_bot.concat(use_bing_bot, use_facebook_bot, use_facebook_referer, use_google_referer, use_twitter_referer, use_random_ip);
|
2021-11-04 18:50:19 +01:00
|
|
|
}
|
|
|
|
|
2021-11-07 08:47:42 +01:00
|
|
|
// add grouped sites to en/disabledSites (and exclude sites)
|
2021-11-04 18:50:19 +01:00
|
|
|
function add_grouped_enabled_domains(groups) {
|
2020-12-07 18:10:59 +01:00
|
|
|
for (let key in groups) {
|
|
|
|
if (enabledSites.includes(key))
|
|
|
|
enabledSites = enabledSites.concat(groups[key]);
|
|
|
|
else
|
|
|
|
disabledSites = disabledSites.concat(groups[key]);
|
2021-01-05 18:53:59 +01:00
|
|
|
for (let site of excludedSites) {
|
|
|
|
if (enabledSites.includes(site)) {
|
|
|
|
enabledSites.splice(enabledSites.indexOf(site), 1);
|
|
|
|
disabledSites.push(site);
|
|
|
|
}
|
|
|
|
}
|
2020-12-07 18:10:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 18:50:19 +01:00
|
|
|
// Get the enabled sites (from local storage) & set_rules for sites
|
2020-10-31 20:06:38 +01:00
|
|
|
ext_api.storage.local.get({
|
2020-10-24 16:38:01 +02:00
|
|
|
sites: {},
|
2021-11-14 13:40:46 +01:00
|
|
|
sites_default: Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/)),
|
2021-01-05 18:53:59 +01:00
|
|
|
sites_custom: {},
|
2022-12-07 13:14:32 +01:00
|
|
|
sites_updated: {},
|
2021-10-16 08:58:31 +02:00
|
|
|
sites_excluded: [],
|
2021-10-17 15:16:44 +02:00
|
|
|
ext_version_old: '2.3.9.0',
|
2023-05-08 20:05:06 +02:00
|
|
|
optIn: false,
|
2021-11-10 17:46:22 +01:00
|
|
|
optInUpdate: true
|
2020-02-28 16:23:17 +01:00
|
|
|
}, function (items) {
|
2020-10-24 16:38:01 +02:00
|
|
|
var sites = items.sites;
|
2021-11-07 08:47:42 +01:00
|
|
|
optionSites = sites;
|
2021-10-15 15:11:10 +02:00
|
|
|
var sites_default = items.sites_default;
|
2021-11-13 11:43:09 +01:00
|
|
|
customSites = items.sites_custom;
|
2023-05-17 18:14:27 +02:00
|
|
|
customSites = filterObject(customSites, function (val, key) {
|
|
|
|
return !(val.add_ext_link && (!val.add_ext_link_type || val.add_ext_link_type === 'google_search_tool'))
|
|
|
|
});
|
2021-11-13 11:43:09 +01:00
|
|
|
customSites_domains = Object.values(customSites).map(x => x.domain);
|
|
|
|
updatedSites = items.sites_updated;
|
2021-12-02 18:02:07 +01: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 15:16:44 +02:00
|
|
|
var ext_version_old = items.ext_version_old;
|
2023-05-08 20:05:06 +02:00
|
|
|
optin_setcookie = items.optIn;
|
2021-11-10 17:46:22 +01:00
|
|
|
optin_update = items.optInUpdate;
|
2021-01-05 18:53:59 +01:00
|
|
|
excludedSites = items.sites_excluded;
|
2020-02-28 16:23:17 +01:00
|
|
|
|
2021-11-06 09:24:44 +01:00
|
|
|
enabledSites = Object.values(sites).filter(function (val) {
|
2022-11-20 17:02:21 +01:00
|
|
|
return (val && val !== '###' && (defaultSites_domains.concat(customSites_domains, updatedSites_domains_new).includes(val)));
|
|
|
|
}).map(function (val) {
|
|
|
|
return val.toLowerCase();
|
|
|
|
});
|
2021-10-15 15:11:10 +02:00
|
|
|
|
|
|
|
// Enable new sites by default (opt-in)
|
2021-11-14 13:40:46 +01: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 08:58:31 +02:00
|
|
|
if (enabledSites.includes('#options_enable_new_sites')) {
|
2021-12-04 12:12:43 +01: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 13:40:46 +01:00
|
|
|
for (let site_new of sites_new)
|
2021-11-13 11:43:09 +01:00
|
|
|
sites[site_new] = defaultSites[site_new].domain;
|
2021-10-16 08:58:31 +02:00
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites: sites
|
|
|
|
});
|
2022-08-10 19:48:00 +02:00
|
|
|
} else {
|
|
|
|
ext_api.management.getSelf(function (result) {
|
|
|
|
if ((result.installType === 'development' || (result.installType !== 'development' && !enabledSites.includes('#options_on_update')))) {
|
2023-06-27 12:26:17 +02:00
|
|
|
let new_groups = ['###_be_groupe_ipm', '###_ch_esh_medias', '###_it_gruppo_sae', '###_nl_eu_ftm'];
|
2023-02-12 16:56:57 +01: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('tinypass.com') && !enabledSites.includes('piano.io'));
|
2022-08-10 19:48:00 +02:00
|
|
|
if (open_options)
|
|
|
|
ext_api.runtime.openOptionsPage();
|
|
|
|
}
|
|
|
|
});
|
2021-10-15 15:11:10 +02:00
|
|
|
}
|
2021-11-14 13:40:46 +01:00
|
|
|
sites_default = Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/));
|
2021-10-15 15:11:10 +02:00
|
|
|
ext_api.storage.local.set({
|
2021-10-16 08:58:31 +02:00
|
|
|
sites_default: sites_default,
|
|
|
|
ext_version_old: ext_version
|
2021-10-15 15:11:10 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-24 10:01:13 +02:00
|
|
|
disabledSites = defaultSites_grouped_domains.concat(customSites_domains).filter(x => !enabledSites.includes(x));
|
2021-11-04 18:50:19 +01:00
|
|
|
add_grouped_enabled_domains(grouped_sites);
|
2021-11-07 08:47:42 +01:00
|
|
|
set_rules(sites, updatedSites, customSites);
|
2022-09-09 14:30:20 +02:00
|
|
|
if (enabledSites.includes('#options_optin_update_rules')) {
|
2021-11-07 08:47:42 +01:00
|
|
|
check_sites_updated();
|
2022-09-09 14:30:20 +02:00
|
|
|
sites_custom_ext_json = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/-/raw/master/custom/sites_custom.json';
|
|
|
|
}
|
2022-09-11 20:12:12 +02:00
|
|
|
check_sites_custom_ext();
|
2021-11-10 17:46:22 +01:00
|
|
|
if (optin_update)
|
|
|
|
check_update();
|
2020-10-24 16:38:01 +02:00
|
|
|
});
|
2020-02-28 16:23:17 +01:00
|
|
|
|
2020-10-24 16:38:01 +02:00
|
|
|
// Listen for changes to options
|
|
|
|
ext_api.storage.onChanged.addListener(function (changes, namespace) {
|
2020-10-31 20:06:38 +01:00
|
|
|
if (namespace === 'sync')
|
|
|
|
return;
|
2020-11-10 18:15:18 +01:00
|
|
|
for (let key in changes) {
|
2020-10-24 16:38:01 +02:00
|
|
|
var storageChange = changes[key];
|
|
|
|
if (key === 'sites') {
|
|
|
|
var sites = storageChange.newValue;
|
2021-11-04 18:50:19 +01:00
|
|
|
optionSites = sites;
|
2021-11-06 09:24:44 +01:00
|
|
|
enabledSites = Object.values(sites).filter(function (val) {
|
2022-11-20 17:02:21 +01:00
|
|
|
return (val && val !== '###' && (defaultSites_domains.concat(customSites_domains, updatedSites_domains_new).includes(val)));
|
|
|
|
}).map(function (val) {
|
|
|
|
return val.toLowerCase();
|
|
|
|
});
|
2022-04-24 10:01:13 +02:00
|
|
|
disabledSites = defaultSites_grouped_domains.concat(customSites_domains).filter(x => !enabledSites.includes(x));
|
2021-11-04 18:50:19 +01:00
|
|
|
add_grouped_enabled_domains(grouped_sites);
|
2021-11-07 08:47:42 +01:00
|
|
|
set_rules(sites, updatedSites, customSites);
|
2020-02-28 16:23:17 +01:00
|
|
|
}
|
2020-10-24 16:38:01 +02:00
|
|
|
if (key === 'sites_custom') {
|
2020-11-29 12:08:21 +01:00
|
|
|
var sites_custom = storageChange.newValue ? storageChange.newValue : {};
|
|
|
|
var sites_custom_old = storageChange.oldValue ? storageChange.oldValue : {};
|
2020-10-24 16:38:01 +02:00
|
|
|
customSites = sites_custom;
|
|
|
|
customSites_domains = Object.values(sites_custom).map(x => x.domain);
|
2021-11-04 18:50:19 +01: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 20:06:38 +01:00
|
|
|
ext_api.storage.local.get({
|
2020-10-24 16:38:01 +02:00
|
|
|
sites: {}
|
|
|
|
}, function (items) {
|
|
|
|
var sites = items.sites;
|
2021-11-04 18:50:19 +01: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 08:47:42 +01:00
|
|
|
set_rules(sites, updatedSites, customSites);
|
2020-10-24 16:38:01 +02:00
|
|
|
});
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
2021-11-07 08:47:42 +01:00
|
|
|
if (key === 'sites_updated') {
|
|
|
|
var sites_updated = storageChange.newValue ? storageChange.newValue : {};
|
|
|
|
updatedSites = sites_updated;
|
2021-12-02 18:02:07 +01: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 13:40:46 +01: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);
|
2022-12-07 13:14:32 +01:00
|
|
|
}
|
2021-01-05 18:53:59 +01: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 08:58:31 +02:00
|
|
|
if (key === 'ext_version_new') {
|
|
|
|
ext_version_new = storageChange.newValue;
|
2021-05-02 07:51:25 +02:00
|
|
|
}
|
2023-05-08 20:05:06 +02:00
|
|
|
if (key === 'optIn') {
|
|
|
|
optin_setcookie = storageChange.newValue;
|
|
|
|
}
|
2021-11-10 17:46:22 +01:00
|
|
|
if (key === 'optInUpdate') {
|
|
|
|
optin_update = storageChange.newValue;
|
|
|
|
}
|
2021-01-05 18:53:59 +01:00
|
|
|
|
2020-10-24 16:38:01 +02:00
|
|
|
// Refresh the current tab
|
2023-02-19 12:36:09 +01:00
|
|
|
let refresh = (url_loc === 'chrome') || ((typeof storageChange.newValue === 'string') && (storageChange.newValue !== storageChange.oldValue)) || ((typeof storageChange.newValue === 'object') && (Object.keys(storageChange.newValue).length !== Object.keys(storageChange.oldValue).length));
|
|
|
|
if (refresh)
|
2022-12-28 12:21:06 +01:00
|
|
|
refreshCurrentTab();
|
2020-10-24 16:38:01 +02:00
|
|
|
}
|
2017-07-08 19:40:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Set and show default options on install
|
2020-03-25 19:31:28 +01:00
|
|
|
ext_api.runtime.onInstalled.addListener(function (details) {
|
2017-07-08 19:40:29 +02:00
|
|
|
if (details.reason == "install") {
|
2020-02-25 22:47:05 +01:00
|
|
|
setDefaultOptions();
|
2017-07-08 19:40:29 +02:00
|
|
|
} else if (details.reason == "update") {
|
2020-08-22 19:21:32 +02:00
|
|
|
ext_api.management.getSelf(function (result) {
|
2020-08-26 17:53:26 +02:00
|
|
|
if (enabledSites.includes('#options_on_update') && result.installType !== 'development')
|
2020-08-22 19:21:32 +02:00
|
|
|
ext_api.runtime.openOptionsPage(); // User updated extension (non-developer mode)
|
|
|
|
});
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-01 19:08:31 +02: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 16:14:14 +01:00
|
|
|
// inkl bypass
|
2020-10-17 10:51:24 +02:00
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var updatedUrl = details.url.replace(/etok=[\w]*&/, '');
|
2022-03-04 16:14:14 +01: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 10:51:24 +02:00
|
|
|
return { redirectUrl: updatedUrl };
|
|
|
|
},
|
|
|
|
{urls:["*://*.inkl.com/*"], types:["main_frame"]},
|
2020-03-03 18:15:21 +01:00
|
|
|
["blocking"]
|
|
|
|
);
|
|
|
|
|
2021-04-11 19:52:54 +02:00
|
|
|
// m.faz.net set user-agent to mobile
|
2022-06-24 11:46:16 +02: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 12:23:29 +01:00
|
|
|
ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-02 14:03:52 +01:00
|
|
|
let headers = details.requestHeaders;
|
|
|
|
headers = headers.map(function (header) {
|
2023-02-27 17:17:21 +01:00
|
|
|
if (header.name.toLowerCase() === 'user-agent')
|
|
|
|
header.value = userAgentMobile;
|
|
|
|
return header;
|
|
|
|
});
|
2021-01-01 12:23:29 +01:00
|
|
|
return {
|
2021-01-02 14:03:52 +01:00
|
|
|
requestHeaders: headers
|
2021-01-01 12:23:29 +01:00
|
|
|
};
|
2020-04-25 17:18:12 +02:00
|
|
|
}, {
|
2021-01-01 12:23:29 +01:00
|
|
|
urls: ["*://m.faz.net/*"],
|
|
|
|
types: ["xmlhttprequest"]
|
2020-04-25 17:18:12 +02:00
|
|
|
},
|
2021-01-01 12:23:29 +01:00
|
|
|
["blocking", "requestHeaders"]);
|
2020-04-25 17:18:12 +02:00
|
|
|
|
2023-02-27 17:17:21 +01:00
|
|
|
// webcache.googleusercontent.com set user-agent to Chrome (on Firefox for Android)
|
|
|
|
if ((typeof browser !== 'object') && navigator_ua_mobile) {
|
|
|
|
ext_api.webRequest.onBeforeSendHeaders.addListener(function (details) {
|
|
|
|
let headers = details.requestHeaders;
|
|
|
|
headers = headers.map(function (header) {
|
|
|
|
if (header.name.toLowerCase() === 'user-agent')
|
|
|
|
header.value = userAgentMobile;
|
|
|
|
return header;
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
requestHeaders: headers
|
|
|
|
};
|
|
|
|
}, {
|
|
|
|
urls: ["*://webcache.googleusercontent.com/*"],
|
|
|
|
types: ["main_frame", "xmlhttprequest"]
|
|
|
|
},
|
|
|
|
["blocking", "requestHeaders"]);
|
|
|
|
}
|
|
|
|
|
2021-05-21 08:04:59 +02:00
|
|
|
// economictimes redirect
|
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
2023-01-19 08:31:41 +01:00
|
|
|
if (!isSiteEnabled(details) || details.url.includes('.com/epaper/')) {
|
2021-05-21 08:04:59 +02:00
|
|
|
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 17:54:59 +02: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 19:31:36 +02: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 17:57:17 +01:00
|
|
|
// Australia News Corp redirect subscribe to amp
|
2023-02-15 16:58:28 +01:00
|
|
|
var au_news_corp_no_amp_fix = ['adelaidenow.com.au', 'codesports.com.au', 'goldcoastbulletin.com.au', 'ntnews.com.au', 'thechronicle.com.au', 'themercury.com.au', 'weeklytimesnow.com.au'];
|
|
|
|
var au_news_corp_subscr = au_news_corp_domains.filter(domain => !au_news_corp_no_amp_fix.includes(domain)).map(domain => '*://www.' + domain + '/subscribe/*');
|
2021-09-26 10:10:29 +02:00
|
|
|
ext_api.webRequest.onBeforeRequest.addListener(function (details) {
|
2022-02-04 08:50:55 +01:00
|
|
|
if (!isSiteEnabled(details) || details.url.includes('/digitalprinteditions') || !(details.url.includes('dest=') && details.url.split('dest=')[1].split('&')[0])) {
|
2021-09-26 10:10:29 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-01-18 17:34:01 +01:00
|
|
|
var updatedUrl = decodeURIComponent(details.url.split('dest=')[1].split('&')[0]) + '?amp';
|
2022-01-28 14:53:45 +01:00
|
|
|
return {
|
|
|
|
redirectUrl: updatedUrl
|
|
|
|
};
|
|
|
|
}, {
|
|
|
|
urls: au_news_corp_subscr,
|
|
|
|
types: ["main_frame"]
|
2021-09-26 10:10:29 +02:00
|
|
|
},
|
2022-01-28 14:53:45 +01:00
|
|
|
["blocking"]);
|
2021-09-26 10:10:29 +02:00
|
|
|
|
2020-10-21 16:48:59 +02:00
|
|
|
// fix nytimes x-frame-options (hidden iframe content)
|
|
|
|
ext_api.webRequest.onHeadersReceived.addListener(function (details) {
|
|
|
|
if (!isSiteEnabled(details)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-01-02 14:03:52 +01:00
|
|
|
var headers = details.responseHeaders;
|
2021-01-06 19:50:12 +01:00
|
|
|
headers = headers.map(function (header) {
|
2021-01-02 14:03:52 +01:00
|
|
|
if (header.name === 'x-frame-options')
|
|
|
|
header.value = 'SAMEORIGIN';
|
|
|
|
return header;
|
2020-10-21 16:48:59 +02:00
|
|
|
});
|
|
|
|
return {
|
2021-01-02 14:03:52 +01:00
|
|
|
responseHeaders: headers
|
2020-10-21 16:48:59 +02:00
|
|
|
};
|
|
|
|
}, {
|
|
|
|
urls: ["*://*.nytimes.com/*"]
|
|
|
|
},
|
|
|
|
['blocking', 'responseHeaders']);
|
|
|
|
|
2022-11-05 15:09:46 +01:00
|
|
|
function blockJsInlineListener(details) {
|
|
|
|
let domain = matchUrlDomain(blockedJsInlineDomains, details.url);
|
|
|
|
let matched = domain && details.url.match(blockedJsInline[domain]);
|
2023-05-08 20:05:06 +02:00
|
|
|
if (matched && optin_setcookie && ['uol.com.br'].includes(domain))
|
|
|
|
matched = false;
|
2022-11-05 15:09:46 +01:00
|
|
|
if (!isSiteEnabled(details) || !matched)
|
|
|
|
return;
|
|
|
|
var headers = details.responseHeaders;
|
|
|
|
headers.push({
|
|
|
|
'name': 'Content-Security-Policy',
|
|
|
|
'value': "script-src *;"
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
responseHeaders: headers
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-03 20:43:36 +01:00
|
|
|
function disableJavascriptInline() {
|
|
|
|
// block inline script
|
2022-11-05 15:09:46 +01:00
|
|
|
ext_api.webRequest.onHeadersReceived.removeListener(blockJsInlineListener);
|
|
|
|
var block_js_inline_urls = [];
|
2022-11-03 20:43:36 +01:00
|
|
|
for (let domain in blockedJsInline)
|
2022-11-05 15:09:46 +01:00
|
|
|
block_js_inline_urls.push("*://*." + domain + "/*");
|
|
|
|
if (block_js_inline_urls.length)
|
|
|
|
ext_api.webRequest.onHeadersReceived.addListener(blockJsInlineListener, {
|
2022-11-03 20:43:36 +01:00
|
|
|
'types': ['main_frame', 'sub_frame'],
|
2022-11-05 15:09:46 +01:00
|
|
|
'urls': block_js_inline_urls
|
2022-11-03 20:43:36 +01:00
|
|
|
},
|
|
|
|
['blocking', 'responseHeaders']);
|
|
|
|
}
|
2021-01-18 18:43:04 +01:00
|
|
|
|
2021-02-22 19:49:41 +01:00
|
|
|
if (typeof browser !== 'object') {
|
2022-11-05 15:09:46 +01:00
|
|
|
var focus_changed = false;
|
|
|
|
ext_api.windows.onFocusChanged.addListener((windowId) => {
|
|
|
|
if (windowId > 0)
|
|
|
|
focus_changed = true;
|
|
|
|
});
|
2021-02-22 19:49:41 +01:00
|
|
|
}
|
2021-02-21 09:21:39 +01:00
|
|
|
|
2022-11-08 20:40:49 +01:00
|
|
|
function runOnTab(tab) {
|
|
|
|
let tabId = tab.id;
|
2022-11-06 17:02:23 +01:00
|
|
|
let url = tab.url;
|
|
|
|
let rc_domain = matchUrlDomain(remove_cookies, url);
|
|
|
|
let rc_domain_enabled = rc_domain && enabledSites.includes(rc_domain);
|
2023-05-08 20:05:06 +02:00
|
|
|
let lib_file = 'lib/empty.js';
|
|
|
|
if (matchUrlDomain(dompurify_sites, url))
|
|
|
|
lib_file = 'lib/purify.min.js';
|
2022-12-16 12:31:29 +01:00
|
|
|
var bg2csData = {};
|
2023-05-08 20:05:06 +02:00
|
|
|
if (optin_setcookie && matchUrlDomain(['crusoe.uol.com.br'], url))
|
|
|
|
bg2csData.optin_setcookie = 1;
|
2022-12-16 12:31:29 +01:00
|
|
|
if (matchUrlDomain(amp_unhide, url))
|
|
|
|
bg2csData.amp_unhide = 1;
|
2022-11-06 17:02:23 +01:00
|
|
|
let amp_redirect_domain = '';
|
|
|
|
if (amp_redirect_domain = matchUrlDomain(Object.keys(amp_redirect), url))
|
|
|
|
bg2csData.amp_redirect = amp_redirect[amp_redirect_domain];
|
|
|
|
let cs_code_domain = '';
|
|
|
|
if (cs_code_domain = matchUrlDomain(Object.keys(cs_code), url))
|
|
|
|
bg2csData.cs_code = cs_code[cs_code_domain];
|
|
|
|
let ld_json_domain = '';
|
|
|
|
if (ld_json_domain = matchUrlDomain(Object.keys(ld_json), url))
|
|
|
|
bg2csData.ld_json = ld_json[ld_json_domain];
|
2023-05-07 13:13:41 +02:00
|
|
|
let ld_json_next_domain = '';
|
|
|
|
if (ld_json_next_domain = matchUrlDomain(Object.keys(ld_json_next), url))
|
|
|
|
bg2csData.ld_json_next = ld_json_next[ld_json_next_domain];
|
2022-11-06 17:02:23 +01:00
|
|
|
let ld_google_webcache_domain = '';
|
|
|
|
if (ld_google_webcache_domain = matchUrlDomain(Object.keys(ld_google_webcache), url))
|
|
|
|
bg2csData.ld_google_webcache = ld_google_webcache[ld_google_webcache_domain];
|
2023-02-19 12:36:09 +01:00
|
|
|
let add_ext_link_domain = '';
|
|
|
|
if (add_ext_link_domain = matchUrlDomain(Object.keys(add_ext_link), url))
|
|
|
|
bg2csData.add_ext_link = add_ext_link[add_ext_link_domain];
|
2022-11-05 15:09:46 +01:00
|
|
|
let tab_runs = 5;
|
|
|
|
for (let n = 0; n < tab_runs; n++) {
|
|
|
|
setTimeout(function () {
|
2022-11-06 17:02:23 +01:00
|
|
|
// run contentScript.js on page
|
2022-11-05 15:09:46 +01:00
|
|
|
ext_api.tabs.executeScript(tabId, {
|
2023-05-08 20:05:06 +02:00
|
|
|
file: lib_file,
|
2022-12-16 12:31:29 +01:00
|
|
|
runAt: 'document_start'
|
2023-01-04 12:37:54 +01:00
|
|
|
}, function (res) {
|
2023-05-08 20:05:06 +02:00
|
|
|
if (ext_api.runtime.lastError)
|
2023-01-04 12:37:54 +01:00
|
|
|
return;
|
2023-05-08 20:05:06 +02:00
|
|
|
ext_api.tabs.executeScript(tabId, {
|
|
|
|
file: 'contentScript.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
})
|
2022-11-05 15:09:46 +01:00
|
|
|
});
|
2022-12-16 12:31:29 +01:00
|
|
|
// send bg2csData to contentScript.js
|
|
|
|
if (Object.keys(bg2csData).length) {
|
|
|
|
setTimeout(function () {
|
|
|
|
ext_api.tabs.sendMessage(tabId, {msg: "bg2cs", data: bg2csData});
|
|
|
|
}, 500);
|
|
|
|
}
|
2022-11-06 17:02:23 +01:00
|
|
|
// remove cookies after page load
|
2022-11-05 15:09:46 +01:00
|
|
|
if (rc_domain_enabled) {
|
|
|
|
remove_cookies_fn(rc_domain, true);
|
|
|
|
}
|
2022-12-16 12:31:29 +01:00
|
|
|
}, n * 200);
|
2022-11-05 15:09:46 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-08 20:40:49 +01:00
|
|
|
|
2022-12-07 13:14:32 +01:00
|
|
|
function runOnTab_once(tab) {
|
|
|
|
let tabId = tab.id;
|
|
|
|
let url = tab.url;
|
|
|
|
// load contentScript_once.js to identify custom site (flex) of group
|
2023-01-07 09:03:18 +01:00
|
|
|
if (!(matchUrlDomain(custom_flex_domains.concat(custom_flex_not_domains, customSites_domains, updatedSites_domains_new, excludedSites, nofix_sites), url) || matchUrlDomain(defaultSites_domains, url))) {
|
2022-12-07 13:14:32 +01:00
|
|
|
ext_api.tabs.executeScript(tabId, {
|
|
|
|
file: 'contentScript_once.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
2022-11-10 19:47:21 +01:00
|
|
|
}
|
2022-11-06 17:02:23 +01:00
|
|
|
// load toggleIcon.js (icon for dark or incognito mode in Chrome))
|
|
|
|
if (typeof browser !== 'object') {
|
|
|
|
ext_api.tabs.executeScript(tabId, {
|
|
|
|
file: 'options/toggleIcon.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-12-07 13:14:32 +01:00
|
|
|
|
2023-03-22 15:42:53 +01:00
|
|
|
var set_var_sites = ['nzherald.co.nz', 'theglobeandmail.com'].concat(de_madsack_domains);
|
2023-01-31 22:36:41 +01:00
|
|
|
function runOnTab_once_var(tab) {
|
|
|
|
let tabId = tab.id;
|
|
|
|
let url = tab.url;
|
|
|
|
let domain = matchUrlDomain(set_var_sites, url);
|
|
|
|
// load contentScript_once_var.js to set variables for site
|
|
|
|
if (domain && enabledSites.includes(domain)) {
|
|
|
|
ext_api.tabs.executeScript(tabId, {
|
|
|
|
file: 'contentScript_once_var.js',
|
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 13:14:32 +01:00
|
|
|
ext_api.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
|
|
let tab_status = changeInfo.status;
|
2023-01-31 22:36:41 +01:00
|
|
|
if (/^http/.test(tab.url)) {
|
|
|
|
if ((tab_status && tab_status === 'complete') || (changeInfo.url)) {
|
|
|
|
let timeout = changeInfo.url ? 500 : 0;
|
|
|
|
setTimeout(function () {
|
|
|
|
if (matchUrlDomain(enabledSites, tab.url)) {
|
|
|
|
runOnTab(tab);
|
|
|
|
}
|
|
|
|
runOnTab_once(tab);
|
|
|
|
}, timeout);
|
2022-12-07 13:14:32 +01:00
|
|
|
}
|
2023-01-31 22:36:41 +01:00
|
|
|
runOnTab_once_var(tab);
|
2022-12-07 13:14:32 +01:00
|
|
|
}
|
2022-11-05 15:09:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
setInterval(function () {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}, 60 * 60 * 1000);
|
2022-12-07 13:14:32 +01:00
|
|
|
|
2020-03-25 19:31:28 +01:00
|
|
|
var extraInfoSpec = ['blocking', 'requestHeaders'];
|
|
|
|
if (ext_api.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty('EXTRA_HEADERS'))
|
|
|
|
extraInfoSpec.push('extraHeaders');
|
|
|
|
|
|
|
|
ext_api.webRequest.onBeforeSendHeaders.addListener(function(details) {
|
2019-11-27 19:23:00 +01:00
|
|
|
var requestHeaders = details.requestHeaders;
|
|
|
|
|
|
|
|
var header_referer = '';
|
2022-01-05 20:40:38 +01: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 08:49:28 +02:00
|
|
|
var blocked_referer_domains = ['timeshighereducation.com'];
|
2022-01-05 20:40:38 +01: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 16:52:50 +02:00
|
|
|
}
|
2021-06-21 22:42:46 +02:00
|
|
|
}
|
2020-01-13 19:15:37 +01:00
|
|
|
|
2020-06-01 18:01:43 +02:00
|
|
|
// block external javascript for custom sites (optional)
|
2022-11-02 21:58:15 +01:00
|
|
|
if (['script'].includes(details.type)) {
|
|
|
|
let domain_blockjs_ext = matchUrlDomain(block_js_custom_ext, header_referer);
|
|
|
|
if (domain_blockjs_ext && !matchUrlDomain(domain_blockjs_ext, details.url) && isSiteEnabled({url: header_referer}))
|
|
|
|
return { cancel: true };
|
2020-06-01 18:01:43 +02:00
|
|
|
}
|
2020-03-27 19:02:27 +01:00
|
|
|
|
2019-11-27 19:23:00 +01:00
|
|
|
// check for blocked regular expression: domain enabled, match regex, block on an internal or external regex
|
2022-11-02 21:58:15 +01:00
|
|
|
if (['script', 'xmlhttprequest'].includes(details.type)) {
|
|
|
|
let domain = matchUrlDomain(blockedRegexesDomains, header_referer);
|
|
|
|
if (domain && details.url.match(blockedRegexes[domain]) && isSiteEnabled({url: header_referer}))
|
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
// block general paywall scripts
|
|
|
|
if (['script', 'xmlhttprequest'].includes(details.type)) {
|
|
|
|
for (let domain in blockedRegexesGeneral) {
|
2022-11-03 20:43:36 +01:00
|
|
|
if (details.url.match(blockedRegexesGeneral[domain].block_regex) && !(matchUrlDomain(excludedSites.concat(disabledSites, blockedRegexesGeneral[domain].excluded_domains), header_referer)))
|
2022-11-02 21:58:15 +01:00
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2022-11-05 15:09:46 +01:00
|
|
|
if (!isSiteEnabled(details)) {
|
2019-11-27 19:23:00 +01:00
|
|
|
return;
|
2018-11-24 23:10:21 +01:00
|
|
|
}
|
|
|
|
|
2020-06-04 09:04:58 +02:00
|
|
|
// block javascript of (sub)domain for custom sites (optional)
|
2020-08-22 13:52:43 +02:00
|
|
|
var domain_blockjs = matchUrlDomain(block_js_custom, details.url);
|
2021-01-26 21:27:43 +01:00
|
|
|
if (domain_blockjs && matchUrlDomain(domain_blockjs, details.url) && details.type === 'script') {
|
2020-06-04 09:04:58 +02:00
|
|
|
return { cancel: true };
|
|
|
|
}
|
|
|
|
|
2019-04-07 01:34:30 +02:00
|
|
|
var useUserAgentMobile = false;
|
2017-07-08 19:40:29 +02:00
|
|
|
var setReferer = false;
|
2022-02-04 08:50:55 +01:00
|
|
|
|
2022-10-14 15:53:54 +02: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 08:50:55 +01:00
|
|
|
var mobile = details.requestHeaders.filter(x => x.name.toLowerCase() === "user-agent" && x.value.toLowerCase().includes("mobile")).length;
|
2021-07-24 10:07:06 +02:00
|
|
|
var googlebotEnabled = matchUrlDomain(use_google_bot, details.url) &&
|
2022-11-11 13:51:07 +01:00
|
|
|
!(matchUrlDomain(es_grupo_vocento_domains, details.url) && mobile) &&
|
2021-07-24 10:07:06 +02:00
|
|
|
!(matchUrlDomain('barrons.com', details.url) && enabledSites.includes('#options_disable_gb_barrons')) &&
|
2022-08-07 19:04:12 +02:00
|
|
|
!(matchUrlDomain(['economictimes.com', 'economictimes.indiatimes.com'], details.url) && !details.url.split(/\?|#/)[0].endsWith('.cms')) &&
|
2023-02-15 16:58:28 +01:00
|
|
|
!(matchUrlDomain(au_news_corp_domains, details.url) && (details.url.includes('?amp') || (!matchUrlDomain(au_news_corp_no_amp_fix, details.url) && enabledSites.includes('#options_disable_gb_au_news_corp')))) &&
|
2022-08-18 21:56:52 +02:00
|
|
|
!(matchUrlDomain('uol.com.br', details.url) && !matchUrlDomain('folha.uol.com.br', details.url)) &&
|
2023-02-27 17:17:21 +01:00
|
|
|
!(matchUrlDomain('wsj.com', details.url) && (enabledSites.includes('#options_disable_gb_wsj') || (!details.url.includes('/articles/') && mobile)));
|
2023-06-29 15:43:50 +02:00
|
|
|
var bingbotEnabled = matchUrlDomain(use_bing_bot, details.url);
|
2022-12-09 17:08:18 +01:00
|
|
|
var facebookbotEnabled = matchUrlDomain(use_facebook_bot, details.url);
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2021-07-24 10:07:06 +02:00
|
|
|
// if referer exists, set it
|
2020-03-27 19:02:27 +01:00
|
|
|
requestHeaders = requestHeaders.map(function (requestHeader) {
|
2017-07-08 19:40:29 +02:00
|
|
|
if (requestHeader.name === 'Referer') {
|
2021-07-24 10:07:06 +02:00
|
|
|
if (googlebotEnabled || matchUrlDomain(use_google_referer, details.url)) {
|
2021-02-06 21:37:52 +01:00
|
|
|
requestHeader.value = 'https://www.google.com/';
|
|
|
|
} else if (matchUrlDomain(use_facebook_referer, details.url)) {
|
2019-02-13 10:33:45 +01:00
|
|
|
requestHeader.value = 'https://www.facebook.com/';
|
2021-02-04 21:44:25 +01:00
|
|
|
} else if (matchUrlDomain(use_twitter_referer, details.url)) {
|
|
|
|
requestHeader.value = 'https://t.co/';
|
2019-02-13 10:33:45 +01:00
|
|
|
}
|
|
|
|
setReferer = true;
|
|
|
|
}
|
2019-04-07 01:34:30 +02:00
|
|
|
if (requestHeader.name === 'User-Agent') {
|
2023-01-10 18:16:24 +01:00
|
|
|
useUserAgentMobile = requestHeader.value.toLowerCase().includes("mobile") && !matchUrlDomain(['telerama.fr'], details.url);
|
2019-04-07 01:34:30 +02:00
|
|
|
}
|
2019-02-13 10:33:45 +01:00
|
|
|
return requestHeader;
|
|
|
|
});
|
2017-07-08 19:40:29 +02:00
|
|
|
|
|
|
|
// otherwise add it
|
|
|
|
if (!setReferer) {
|
2021-07-24 10:07:06 +02:00
|
|
|
if (googlebotEnabled || matchUrlDomain(use_google_referer, details.url)) {
|
2017-07-08 19:40:29 +02:00
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
2021-02-06 21:37:52 +01:00
|
|
|
value: 'https://www.google.com/'
|
2017-07-08 19:40:29 +02:00
|
|
|
});
|
2021-02-06 21:37:52 +01:00
|
|
|
} else if (matchUrlDomain(use_facebook_referer, details.url)) {
|
2021-02-04 21:44:25 +01:00
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
2021-02-06 21:37:52 +01:00
|
|
|
value: 'https://www.facebook.com/'
|
2021-02-04 21:44:25 +01:00
|
|
|
});
|
2021-02-06 21:37:52 +01:00
|
|
|
} else if (matchUrlDomain(use_twitter_referer, details.url)) {
|
2017-07-08 19:40:29 +02:00
|
|
|
requestHeaders.push({
|
|
|
|
name: 'Referer',
|
2021-02-06 21:37:52 +01:00
|
|
|
value: 'https://t.co/'
|
2017-07-08 19:40:29 +02:00
|
|
|
});
|
|
|
|
}
|
2019-04-07 01:34:30 +02:00
|
|
|
}
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2019-05-12 22:44:03 +02:00
|
|
|
// override User-Agent to use Googlebot
|
2021-07-24 10:07:06 +02:00
|
|
|
if (googlebotEnabled) {
|
2019-04-07 01:34:30 +02:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "User-Agent",
|
2020-11-02 18:52:40 +01:00
|
|
|
"value": useUserAgentMobile ? userAgentMobileG : userAgentDesktopG
|
2019-04-07 01:34:30 +02:00
|
|
|
})
|
2019-05-12 22:44:03 +02:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "X-Forwarded-For",
|
|
|
|
"value": "66.249.66.1"
|
|
|
|
})
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 18:52:40 +01:00
|
|
|
// override User-Agent to use Bingbot
|
2021-10-25 19:05:57 +02:00
|
|
|
if (bingbotEnabled) {
|
2020-11-02 18:52:40 +01:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "User-Agent",
|
|
|
|
"value": useUserAgentMobile ? userAgentMobileB : userAgentDesktopB
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-09 17:08:18 +01:00
|
|
|
// override User-Agent to use Facebookbot
|
|
|
|
if (facebookbotEnabled) {
|
2022-11-21 08:09:07 +01:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "User-Agent",
|
2022-12-09 17:08:18 +01:00
|
|
|
"value": userAgentDesktopF
|
2022-11-21 08:09:07 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-12 21:46:50 +01:00
|
|
|
// random IP for sites in use_random_ip
|
2021-12-21 17:36:48 +01:00
|
|
|
let domain_random;
|
|
|
|
if (domain_random = matchUrlDomain(use_random_ip, details.url)) {
|
2021-12-19 15:09:54 +01:00
|
|
|
let randomIP_val;
|
2021-12-21 17:36:48 +01:00
|
|
|
if (random_ip[domain_random] === 'eu')
|
|
|
|
randomIP_val = randomIP(185, 185);
|
2021-12-19 15:09:54 +01:00
|
|
|
else
|
|
|
|
randomIP_val = randomIP();
|
2020-12-03 16:52:33 +01:00
|
|
|
requestHeaders.push({
|
|
|
|
"name": "X-Forwarded-For",
|
2021-12-19 15:09:54 +01:00
|
|
|
"value": randomIP_val
|
2020-12-03 16:52:33 +01:00
|
|
|
})
|
|
|
|
}
|
2021-01-12 21:46:50 +01:00
|
|
|
}
|
2020-12-03 16:52:33 +01:00
|
|
|
|
2017-07-08 19:40:29 +02:00
|
|
|
// remove cookies before page load
|
2020-05-01 12:58:36 +02:00
|
|
|
if (!matchUrlDomain(allow_cookies, details.url)) {
|
|
|
|
requestHeaders = requestHeaders.map(function(requestHeader) {
|
|
|
|
if (requestHeader.name === 'Cookie') {
|
|
|
|
requestHeader.value = '';
|
2017-07-08 19:40:29 +02:00
|
|
|
}
|
2020-05-01 12:58:36 +02:00
|
|
|
return requestHeader;
|
|
|
|
});
|
|
|
|
}
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2022-11-21 08:09:07 +01:00
|
|
|
if (kiwi_browser) {
|
|
|
|
let tabId = details.tabId;
|
|
|
|
if (tabId !== -1) {
|
2023-05-23 21:51:02 +02:00
|
|
|
if (['main_frame', 'sub_frame', 'xmlhttprequest'].includes(details.type)) {
|
2022-11-21 08:09:07 +01:00
|
|
|
ext_api.tabs.get(tabId, function (tab) {
|
|
|
|
if (!ext_api.runtime.lastError && tab && isSiteEnabled(tab)) {
|
|
|
|
runOnTab(tab);
|
|
|
|
}
|
2022-12-07 13:14:32 +01:00
|
|
|
runOnTab_once(tab);
|
2023-01-31 22:36:41 +01:00
|
|
|
runOnTab_once_var(tab);
|
2022-11-21 08:09:07 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (['xmlhttprequest'].includes(details.type)) {
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
2022-11-21 08:09:07 +01:00
|
|
|
let tab = tabs[0];
|
|
|
|
if (isSiteEnabled(tab)) {
|
|
|
|
runOnTab(tab);
|
|
|
|
}
|
2022-12-07 13:14:32 +01:00
|
|
|
runOnTab_once(tab);
|
2023-01-31 22:36:41 +01:00
|
|
|
runOnTab_once_var(tab);
|
2022-11-21 08:09:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-08 19:40:29 +02:00
|
|
|
return { requestHeaders: requestHeaders };
|
|
|
|
}, {
|
2022-12-07 13:14:32 +01:00
|
|
|
urls: ['*://*/*']
|
2020-03-25 19:31:28 +01:00
|
|
|
}, extraInfoSpec);
|
|
|
|
// extraInfoSpec is ['blocking', 'requestHeaders'] + possible 'extraHeaders'
|
2017-07-08 19:40:29 +02:00
|
|
|
|
2022-09-09 14:30:20 +02: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 12:58:36 +02:00
|
|
|
ext_api.tabs.onUpdated.addListener(function (tabId, info, tab) { updateBadge(tab); });
|
2021-12-24 08:32:45 +01:00
|
|
|
ext_api.tabs.onActivated.addListener(function (activeInfo) { if (activeInfo.tabId) ext_api.tabs.get(activeInfo.tabId, updateBadge); });
|
2020-05-01 12:58:36 +02:00
|
|
|
|
2020-11-02 16:57:47 +01:00
|
|
|
function updateBadge(activeTab) {
|
2022-11-26 17:18:57 +01:00
|
|
|
if (ext_api.runtime.lastError || !activeTab || (activeTab.url && activeTab.url.split('?')[0].includes('/archive.')))
|
2020-11-02 16:57:47 +01:00
|
|
|
return;
|
2020-08-20 19:01:12 +02: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 16:57:47 +01:00
|
|
|
color = 'orange';
|
2020-08-20 19:01:12 +02:00
|
|
|
} else if (matchUrlDomain(disabledSites, currentUrl)) {
|
|
|
|
badgeText = 'OFF';
|
2020-11-02 16:57:47 +01:00
|
|
|
color = 'blue';
|
2022-04-27 20:40:58 +02:00
|
|
|
} else if (matchUrlDomain(nofix_sites, currentUrl)) {
|
|
|
|
badgeText = 'X';
|
2022-09-29 09:24:42 +02:00
|
|
|
color = 'silver';
|
2020-08-20 19:01:12 +02:00
|
|
|
}
|
2021-10-16 08:58:31 +02:00
|
|
|
if (ext_version_new)
|
2021-05-02 07:51:25 +02:00
|
|
|
badgeText = '^' + badgeText;
|
2020-11-02 16:57:47 +01:00
|
|
|
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
|
|
|
|
let isCustomSite = matchUrlDomain(customSites_domains, currentUrl);
|
2021-12-02 18:02:07 +01:00
|
|
|
let isUpdatedSite = matchUrlDomain(updatedSites_domains_new, currentUrl);
|
|
|
|
if (!isDefaultSite && (isCustomSite || isUpdatedSite)) {
|
2020-11-02 16:57:47 +01:00
|
|
|
ext_api.permissions.contains({
|
2021-12-02 18:02:07 +01:00
|
|
|
origins: ['*://*.' + (isCustomSite || isUpdatedSite) + '/*']
|
2020-11-02 16:57:47 +01:00
|
|
|
}, function (result) {
|
|
|
|
if (!result)
|
2021-12-02 18:02:07 +01:00
|
|
|
badgeText = enabledSites.includes(isCustomSite || isUpdatedSite) ? 'C' : '';
|
2020-11-02 16:57:47 +01:00
|
|
|
if (color && badgeText)
|
2022-12-07 13:14:32 +01:00
|
|
|
ext_api.action.setBadgeBackgroundColor({color: color});
|
|
|
|
ext_api.action.setBadgeText({text: badgeText});
|
2020-11-02 16:57:47 +01:00
|
|
|
});
|
2020-11-01 17:46:29 +01:00
|
|
|
} else {
|
2022-09-12 19:54:50 +02:00
|
|
|
if (!badgeText && matchUrlDomain(customSitesExt, currentUrl))
|
2022-09-09 14:30:20 +02:00
|
|
|
badgeText = '+C';
|
2020-11-02 16:57:47 +01:00
|
|
|
if (color && badgeText)
|
2022-12-07 13:14:32 +01:00
|
|
|
ext_api.action.setBadgeBackgroundColor({color: color});
|
|
|
|
ext_api.action.setBadgeText({text: badgeText});
|
2020-11-02 16:57:47 +01:00
|
|
|
}
|
2021-12-15 17:44:52 +01:00
|
|
|
} else
|
2022-12-07 13:14:32 +01:00
|
|
|
ext_api.action.setBadgeText({text: badgeText});
|
2020-03-03 22:37:45 +01:00
|
|
|
}
|
|
|
|
|
2021-10-16 08:58:31 +02:00
|
|
|
var ext_version_new;
|
2021-05-02 07:51:25 +02:00
|
|
|
function check_update() {
|
2022-02-22 17:35:16 +01:00
|
|
|
let manifest_new = 'https://gitlab.com/magnolia1234/bypass-paywalls-' + url_loc + '-clean/raw/master/manifest.json';
|
|
|
|
fetch(manifest_new)
|
2021-05-02 07:51:25 +02:00
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(json => {
|
|
|
|
ext_api.management.getSelf(function (result) {
|
|
|
|
var installType = result.installType;
|
2021-10-16 08:58:31 +02: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 07:51:25 +02:00
|
|
|
ext_api.storage.local.set({
|
2021-10-16 08:58:31 +02:00
|
|
|
ext_version_new: ext_version_new
|
2021-05-02 07:51:25 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
2021-12-14 17:23:40 +01:00
|
|
|
}).catch(function (err) {
|
|
|
|
false;
|
2021-05-02 07:51:25 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-20 19:01:12 +02:00
|
|
|
function site_switch() {
|
2021-11-19 16:46:52 +01:00
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
2021-11-19 16:46:52 +01: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 12:12:43 +01:00
|
|
|
for (let key of removed_site) {
|
|
|
|
key = Object.keys(sites).find(sites_key => compareKey(sites_key, key));
|
2021-11-19 16:46:52 +01:00
|
|
|
delete sites[key];
|
2021-12-04 12:12:43 +01:00
|
|
|
}
|
2021-11-19 16:46:52 +01:00
|
|
|
ext_api.storage.local.set({
|
|
|
|
sites: sites
|
|
|
|
}, function () {
|
|
|
|
true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-03-03 22:37:45 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 11:32:38 +01:00
|
|
|
function remove_cookies_fn(domainVar, exclusions = false) {
|
2021-02-17 19:11:27 +01:00
|
|
|
ext_api.cookies.getAllCookieStores(function (cookieStores) {
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (!ext_api.runtime.lastError && tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
2021-02-17 19:11:27 +01:00
|
|
|
let tabId = tabs[0].id;
|
2021-02-28 11:32:38 +01:00
|
|
|
let storeId = '0';
|
2021-02-17 19:11:27 +01:00
|
|
|
for (let store of cookieStores) {
|
|
|
|
if (store.tabIds.includes(tabId))
|
|
|
|
storeId = store.id;
|
|
|
|
}
|
2021-02-22 19:49:41 +01:00
|
|
|
storeId = storeId.toString();
|
2021-11-09 17:18:34 +01:00
|
|
|
if (domainVar === 'asia.nikkei.com')
|
|
|
|
domainVar = 'nikkei.com';
|
2021-02-22 19:49:41 +01: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 19:11:27 +01:00
|
|
|
for (let cookie of cookies) {
|
2021-02-28 11:32:38 +01: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 19:11:27 +01:00
|
|
|
}
|
2021-02-23 17:44:54 +01:00
|
|
|
cookie.domain = cookie.domain.replace(/^\./, '');
|
2021-02-22 19:49:41 +01:00
|
|
|
cookie_remove_options = {
|
2021-02-17 19:11:27 +01:00
|
|
|
url: (cookie.secure ? "https://" : "http://") + cookie.domain + cookie.path,
|
2021-02-22 19:49:41 +01:00
|
|
|
name: cookie.name
|
|
|
|
};
|
|
|
|
if (storeId !== 'null')
|
|
|
|
cookie_remove_options.storeId = storeId;
|
|
|
|
ext_api.cookies.remove(cookie_remove_options);
|
2021-02-17 19:11:27 +01:00
|
|
|
}
|
|
|
|
});
|
2021-01-02 12:48:07 +01:00
|
|
|
}
|
2021-02-17 19:11:27 +01:00
|
|
|
});
|
|
|
|
})
|
2021-02-28 11:32:38 +01:00
|
|
|
}
|
|
|
|
|
2020-10-12 17:31:51 +02:00
|
|
|
function clear_cookies() {
|
2020-10-24 16:38:01 +02:00
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
2020-10-24 16:38:01 +02:00
|
|
|
ext_api.tabs.executeScript({
|
2021-03-27 08:31:03 +01:00
|
|
|
file: 'options/clearCookies.js',
|
2020-10-24 16:38:01 +02:00
|
|
|
runAt: 'document_start'
|
|
|
|
}, function (res) {
|
|
|
|
if (ext_api.runtime.lastError || res[0]) {
|
|
|
|
return;
|
2020-10-12 17:31:51 +02:00
|
|
|
}
|
2020-10-24 16:38:01 +02:00
|
|
|
});
|
|
|
|
ext_api.tabs.update(tabs[0].id, {
|
|
|
|
url: tabs[0].url
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-10-12 17:31:51 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 18:39:46 +01:00
|
|
|
var chrome_scheme = 'light';
|
2020-09-08 16:38:18 +02:00
|
|
|
ext_api.runtime.onMessage.addListener(function (message, sender) {
|
2021-02-17 19:11:27 +01:00
|
|
|
if (message.request === 'clear_cookies') {
|
|
|
|
clear_cookies();
|
|
|
|
}
|
2020-10-24 16:38:01 +02:00
|
|
|
// clear cookies for domain
|
2022-12-03 18:13:37 +01:00
|
|
|
if (message.request === 'clear_cookies_domain' && message.data) {
|
|
|
|
remove_cookies_fn(message.data.domain);
|
2021-02-17 19:11:27 +01:00
|
|
|
}
|
2023-01-31 22:36:41 +01:00
|
|
|
if (message.request === 'custom_domain' && message.data && message.data.domain) {
|
2022-12-07 13:14:32 +01:00
|
|
|
let custom_domain = message.data.domain;
|
|
|
|
let group = message.data.group;
|
|
|
|
if (group) {
|
2023-05-17 18:14:27 +02:00
|
|
|
let nofix_groups = ['###_be_mediahuis', '###_ch_tamedia', '###_de_rp_aachen_medien', '###_fi_alma_talent', '###_it_citynews', '###_substack_custom'];
|
2023-05-05 16:30:17 +02:00
|
|
|
if (!custom_flex_domains.includes(custom_domain)) {
|
|
|
|
if (enabledSites.includes(group)) {
|
2023-05-13 19:13:03 +02:00
|
|
|
let rules = Object.values(defaultSites).filter(x => x.domain === group)[0];
|
|
|
|
if (rules) {
|
2023-05-24 20:13:55 +02:00
|
|
|
if (group === '###_de_madsack') {
|
2023-05-13 19:13:03 +02:00
|
|
|
if (!set_var_sites.includes(custom_domain))
|
|
|
|
set_var_sites.push(custom_domain);
|
2023-05-24 20:13:55 +02:00
|
|
|
} else if (group === '###_usa_townnews') {
|
|
|
|
if (!dompurify_sites.includes(custom_domain))
|
|
|
|
dompurify_sites.push(custom_domain);
|
|
|
|
}
|
2023-05-13 19:13:03 +02:00
|
|
|
} else
|
|
|
|
rules = Object.values(customSites).filter(x => x.domain === group)[0];
|
2023-05-05 16:30:17 +02:00
|
|
|
if (rules) {
|
|
|
|
custom_flex_domains.push(custom_domain);
|
|
|
|
if (!enabledSites.includes(custom_domain))
|
|
|
|
enabledSites.push(custom_domain);
|
2023-05-28 09:34:59 +02:00
|
|
|
customFlexAddRules(custom_domain, rules);
|
2023-05-05 16:30:17 +02:00
|
|
|
}
|
|
|
|
} else if (disabledSites.includes(group))
|
|
|
|
custom_flex_not_domains.push(custom_domain);
|
2023-01-09 17:00:43 +01:00
|
|
|
else if (nofix_groups.includes(group))
|
2023-01-07 09:03:18 +01:00
|
|
|
nofix_sites.push(custom_domain);
|
2023-05-05 16:30:17 +02:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
custom_flex_not_domains.push(custom_domain);
|
2022-12-07 13:14:32 +01:00
|
|
|
}
|
2021-02-17 19:11:27 +01:00
|
|
|
if (message.request === 'site_switch') {
|
|
|
|
site_switch();
|
|
|
|
}
|
2021-12-02 18:02:07 +01:00
|
|
|
if (message.request === 'check_sites_updated') {
|
|
|
|
check_sites_updated();
|
|
|
|
}
|
2021-02-17 19:11:27 +01:00
|
|
|
if (message.request === 'popup_show_toggle') {
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
2021-02-17 19:11:27 +01:00
|
|
|
let currentUrl = tabs[0].url;
|
|
|
|
let domain;
|
|
|
|
let isExcludedSite = matchUrlDomain(excludedSites, currentUrl);
|
|
|
|
if (!isExcludedSite) {
|
|
|
|
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
|
|
|
|
let isCustomSite = matchUrlDomain(Object.values(customSites_domains), currentUrl);
|
2022-12-03 18:13:37 +01:00
|
|
|
domain = isDefaultSite || isCustomSite;
|
|
|
|
if (domain)
|
|
|
|
ext_api.runtime.sendMessage({
|
|
|
|
msg: "popup_show_toggle",
|
|
|
|
data: {
|
|
|
|
domain: domain,
|
|
|
|
enabled: enabledSites.includes(domain)
|
|
|
|
}
|
|
|
|
});
|
2021-02-17 19:11:27 +01:00
|
|
|
}
|
2020-10-24 16:38:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-06-09 21:32:35 +02:00
|
|
|
if (message.request === 'refreshCurrentTab') {
|
2022-12-14 08:30:03 +01:00
|
|
|
ext_api.tabs.reload({bypassCache: true});
|
2021-06-09 21:32:35 +02:00
|
|
|
}
|
2022-04-09 17:07:30 +02: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';
|
|
|
|
}
|
2022-11-05 15:09:46 +01:00
|
|
|
message.data.html = html;
|
|
|
|
if (typeof DOMParser === 'function') {
|
|
|
|
let parser = new DOMParser();
|
|
|
|
let doc = parser.parseFromString(html, 'text/html');
|
|
|
|
let article_new = doc.querySelector(message.data.selector_source);
|
|
|
|
if (article_new)
|
|
|
|
message.data.html = article_new.outerHTML;
|
2022-08-02 19:05:09 +02:00
|
|
|
}
|
2022-11-05 15:09:46 +01:00
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
2022-11-05 15:09:46 +01:00
|
|
|
ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data});
|
|
|
|
}
|
|
|
|
});
|
2022-04-09 17:07:30 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch(function (err) {
|
|
|
|
message.data.html = '';
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
2022-04-09 17:07:30 +02:00
|
|
|
ext_api.tabs.sendMessage(sender.tab.id, {msg: "showExtSrc", data: message.data});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-02-21 09:21:39 +01:00
|
|
|
if (message.scheme && (![chrome_scheme, 'undefined'].includes(message.scheme) || focus_changed)) {
|
2020-10-29 18:39:46 +01:00
|
|
|
let icon_path = {path: {'128': 'bypass.png'}};
|
|
|
|
if (message.scheme === 'dark')
|
|
|
|
icon_path = {path: {'128': 'bypass-dark.png'}};
|
2022-12-07 13:14:32 +01:00
|
|
|
ext_api.action.setIcon(icon_path);
|
2020-10-29 18:39:46 +01:00
|
|
|
chrome_scheme = message.scheme;
|
2021-02-21 09:21:39 +01:00
|
|
|
focus_changed = false;
|
2020-10-29 18:39:46 +01:00
|
|
|
}
|
2020-09-08 16:38:18 +02:00
|
|
|
});
|
|
|
|
|
2023-05-08 20:05:06 +02:00
|
|
|
// show the opt-in tab on installation
|
|
|
|
ext_api.storage.local.get(["optInShown", "customShown"], function (result) {
|
|
|
|
if (!result.optInShown || !result.customShown) {
|
|
|
|
ext_api.tabs.create({
|
|
|
|
url: "options/optin/opt-in.html"
|
|
|
|
});
|
|
|
|
ext_api.storage.local.set({
|
|
|
|
"optInShown": true,
|
|
|
|
"customShown": true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-04 18:50:19 +01:00
|
|
|
function filterObject(obj, filterFn, mapFn = function (val, key) {
|
|
|
|
return [key, val];
|
|
|
|
}) {
|
2021-03-26 13:05:20 +01:00
|
|
|
return Object.fromEntries(Object.entries(obj).
|
2021-11-04 18:50:19 +01:00
|
|
|
filter(([key, val]) => filterFn(val, key)).map(([key, val]) => mapFn(val, key)));
|
2021-03-26 13:05:20 +01:00
|
|
|
}
|
|
|
|
|
2021-12-04 12:12:43 +01:00
|
|
|
function compareKey(firstStr, secondStr) {
|
|
|
|
return firstStr.toLowerCase().replace(/\s\(.*\)/, '') === secondStr.toLowerCase().replace(/\s\(.*\)/, '');
|
|
|
|
}
|
|
|
|
|
2019-02-11 00:43:12 +01:00
|
|
|
function isSiteEnabled(details) {
|
2020-10-24 16:38:01 +02:00
|
|
|
var enabledSite = matchUrlDomain(enabledSites, details.url);
|
2021-03-07 14:03:22 +01:00
|
|
|
if (!ext_name.startsWith('Bypass Paywalls Clean'))
|
2020-10-24 16:38:01 +02:00
|
|
|
enabledSite = '';
|
|
|
|
if (enabledSite in restrictions) {
|
|
|
|
return restrictions[enabledSite].test(details.url);
|
|
|
|
}
|
|
|
|
return !!enabledSite;
|
2020-05-01 12:58:36 +02:00
|
|
|
}
|
|
|
|
|
2022-01-05 20:40:38 +01:00
|
|
|
function matchDomain(domains, hostname = '') {
|
2020-10-24 16:38:01 +02: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 12:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function urlHost(url) {
|
2022-12-03 18:13:37 +01:00
|
|
|
if (/^http/.test(url)) {
|
2020-10-24 16:38:01 +02:00
|
|
|
try {
|
|
|
|
return new URL(url).hostname;
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`url not valid: ${url} error: ${e}`);
|
2020-05-01 12:58:36 +02:00
|
|
|
}
|
2020-10-24 16:38:01 +02:00
|
|
|
}
|
|
|
|
return url;
|
2020-05-01 12:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function matchUrlDomain(domains, url) {
|
2020-10-24 16:38:01 +02:00
|
|
|
return matchDomain(domains, urlHost(url));
|
2019-02-11 00:43:12 +01:00
|
|
|
}
|
|
|
|
|
2022-12-07 13:14:32 +01:00
|
|
|
function prepHostname(hostname) {
|
|
|
|
return hostname.replace(/^(www|m|account|amp(\d)?|edition|eu|mobil|wap)\./, '');
|
|
|
|
}
|
|
|
|
|
2019-02-11 00:43:12 +01: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 23:06:25 +01:00
|
|
|
|
|
|
|
function stripQueryStringAndHashFromPath(url) {
|
|
|
|
return url.split("?")[0].split("#")[0];
|
2020-03-25 19:31:28 +01:00
|
|
|
}
|
2020-12-03 16:52:33 +01:00
|
|
|
|
2022-04-09 17:07:30 +02:00
|
|
|
function decode_utf8(str) {
|
|
|
|
return decodeURIComponent(escape(str));
|
|
|
|
}
|
|
|
|
|
2020-12-03 16:52:33 +01:00
|
|
|
function randomInt(max) {
|
|
|
|
return Math.floor(Math.random() * Math.floor(max));
|
|
|
|
}
|
|
|
|
|
2021-12-19 15:09:54 +01:00
|
|
|
function randomIP(range_low = 0, range_high = 223) {
|
2020-12-03 16:52:33 +01:00
|
|
|
let rndmIP = [];
|
2021-12-19 15:09:54 +01:00
|
|
|
for (let n = 0; n < 4; n++) {
|
|
|
|
if (n === 0)
|
2021-12-21 17:36:48 +01:00
|
|
|
rndmIP.push(range_low + randomInt(range_high - range_low + 1));
|
2021-12-19 15:09:54 +01:00
|
|
|
else
|
|
|
|
rndmIP.push(randomInt(255) + 1);
|
|
|
|
}
|
2020-12-03 16:52:33 +01:00
|
|
|
return rndmIP.join('.');
|
|
|
|
}
|
2022-12-16 12:31:29 +01:00
|
|
|
|
|
|
|
// Refresh the current tab (http)
|
|
|
|
function refreshCurrentTab() {
|
|
|
|
ext_api.tabs.query({
|
|
|
|
active: true,
|
|
|
|
currentWindow: true
|
|
|
|
}, function (tabs) {
|
|
|
|
if (tabs && tabs[0] && /^http/.test(tabs[0].url)) {
|
|
|
|
if (ext_api.runtime.lastError)
|
|
|
|
return;
|
|
|
|
ext_api.tabs.update(tabs[0].id, {
|
|
|
|
url: tabs[0].url
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|