Update group rules (post-release)

This commit is contained in:
magnolia1234 2021-11-14 13:40:46 +01:00
parent 237ccbbd13
commit 903ce7af4a
5 changed files with 103 additions and 76 deletions

View file

@ -93,12 +93,13 @@ var optionSites = {};
var customSites = {};
var customSites_domains = [];
var updatedSites = {};
var updatedSites_new = [];
var excludedSites = [];
function setDefaultOptions() {
ext_api.storage.local.set({
sites: filterObject(defaultSites, function (val, key) {
return !val.domain.match(/^(###$|#options_disable_)/)
return val.domain && !val.domain.match(/^(###$|#options_disable_)/)
},
function (val, key) {
return [key, val.domain]
@ -115,7 +116,7 @@ function check_sites_updated() {
.then(response => {
if (response.ok) {
response.json().then(json => {
expandSiteRules(json);
expandSiteRules(json, true);
ext_api.storage.local.set({
sites_updated: json
});
@ -269,7 +270,7 @@ function add_grouped_enabled_domains(groups) {
// Get the enabled sites (from local storage) & set_rules for sites
ext_api.storage.local.get({
sites: {},
sites_default: Object.keys(defaultSites).filter(x => !defaultSites[x].domain.match(/^(#options_|###$)/)),
sites_default: Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/)),
sites_custom: {},
sites_updated: {},
sites_excluded: [],
@ -295,17 +296,19 @@ ext_api.storage.local.get({
});
// Enable new sites by default (opt-in)
if (ext_version > ext_version_old) {
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) {
if (enabledSites.includes('#options_enable_new_sites')) {
let sites_new = Object.keys(defaultSites).filter(x => !defaultSites[x].domain.match(/^(#options_|###$)/) && !sites_default.includes(x));
for (let site_new of sites_new) {
let sites_new = Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/) && !sites_default.includes(x));
for (let site_new of sites_new)
sites[site_new] = defaultSites[site_new].domain;
}
ext_api.storage.local.set({
sites: sites
});
}
sites_default = Object.keys(defaultSites).filter(x => !defaultSites[x].domain.match(/^(#options_|###$)/));
sites_default = Object.keys(defaultSites).filter(x => defaultSites[x].domain && !defaultSites[x].domain.match(/^(#options_|###$)/));
ext_api.storage.local.set({
sites_default: sites_default,
ext_version_old: ext_version
@ -371,7 +374,17 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
if (key === 'sites_updated') {
var sites_updated = storageChange.newValue ? storageChange.newValue : {};
updatedSites = sites_updated;
set_rules(optionSites, updatedSites, customSites);
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);
}
if (key === 'sites_excluded') {
var sites_excluded = storageChange.newValue ? storageChange.newValue : [];

View file

@ -5,8 +5,9 @@ Post-release
Fix Nikkei Asian Review (cookies)
Fix Quora+ (banner)
Fix Repubblica sites (re-enable Googlebot)
Add rules for new sites (opt-in to custom sites)
Add rules for new sites (post-release; opt-in to custom sites)
Check for update version on startup/options (now opt-out)
Update group rules (post-release)
* v2.4.3.0 (2021-11-07)
Add Harvard Business Review China

View file

@ -71,7 +71,6 @@
"*://*.americanbanker.com/*",
"*://*.apollo-magazine.com/*",
"*://*.arvopaperi.fi/*",
"*://*.asia.nikkei.com/*",
"*://*.asiatimes.com/*",
"*://*.atavist.com/*",
"*://*.atlantico.fr/*",
@ -349,6 +348,7 @@
"*://*.newsweek.com/*",
"*://*.newyorker.com/*",
"*://*.niagarafallsreview.ca/*",
"*://*.nikkei.com/*",
"*://*.nknews.org/*",
"*://*.noordhollandsdagblad.nl/*",
"*://*.nordeclair.fr/*",
@ -558,5 +558,5 @@
"*://*.wallkit.net/*",
"*://*.wsj.net/*"
],
"version": "2.4.3.4"
"version": "2.4.3.5"
}

View file

@ -71,16 +71,15 @@ function renderOptions() {
let sites_arr = site_types[site_type].sites
for (let key in sites_arr) {
let domain = sites_arr[key]['domain'];
if (!site_types[site_type].default_sites && (defaultSites.hasOwnProperty(key) || defaultSites_domains.includes(domain))) {
if (!domain || (!site_types[site_type].default_sites && (defaultSites.hasOwnProperty(key) || defaultSites_domains.includes(domain))))
continue;
}
labelEl = document.createElement('label');
let inputEl = document.createElement('input');
inputEl.type = 'checkbox';
inputEl.dataset.key = key;
inputEl.dataset.value = domain;
inputEl.checked = Object.keys(sites).some(title => compareKey(title, key)) && !sites_excluded.includes(domain);
if (domain !== '' && domain !== '###') {
if (domain !== '###') {
labelEl.appendChild(inputEl);
} else {
labelEl.appendChild(document.createElement('hr'));

136
sites.js
View file

@ -1,7 +1,7 @@
var defaultSites = {
"360Dx": {
domain: "360dx.com",
group_rule: "usa_genomeweb_domains"
group_rule: "###_gr_usa_genomeweb_domains"
},
"Aachener Zeitung": {
domain: "aachener-zeitung.de",
@ -174,7 +174,7 @@ var defaultSites = {
},
"Brisbane Times": {
domain: "brisbanetimes.com.au",
group_rule: "au_nine_domains"
group_rule: "###_gr_au_nine_domains"
},
"Business Insider": {
domain: "businessinsider.com",
@ -279,7 +279,7 @@ var defaultSites = {
},
"DeMorgen": {
domain: "demorgen.be",
group_rule: "nl_pg_domains"
group_rule: "###_gr_nl_pg_domains"
},
"Deutsche Wirtschafts Nachrichten": {
domain: "deutsche-wirtschafts-nachrichten.de",
@ -343,7 +343,7 @@ var defaultSites = {
},
"El Mundo": {
domain: "elmundo.es",
group_rule: "es_unidad_domains"
group_rule: "###_gr_es_unidad_domains"
},
"El País": {
domain: "elpais.com",
@ -387,7 +387,7 @@ var defaultSites = {
},
"Expansión": {
domain: "expansion.com",
group_rule: "es_unidad_domains"
group_rule: "###_gr_es_unidad_domains"
},
"Financial News (London)": {
domain: "fnlondon.com",
@ -475,11 +475,11 @@ var defaultSites = {
},
"GElocal.it": {
domain: "gelocal.it",
group_rule: "it_repubblica_domains"
group_rule: "###_gr_it_repubblica_domains"
},
"GenomeWeb": {
domain: "genomeweb.com",
group_rule: "usa_genomeweb_domains"
group_rule: "###_gr_usa_genomeweb_domains"
},
"Gestión": {
domain: "gestion.pe",
@ -641,7 +641,7 @@ var defaultSites = {
},
"Humo.be": {
domain: "humo.be",
group_rule: "nl_pg_domains"
group_rule: "###_gr_nl_pg_domains"
},
"Il Fatto Quotidiano": {
domain: "ilfattoquotidiano.it",
@ -665,7 +665,7 @@ var defaultSites = {
},
"Il Secolo XIX": {
domain: "ilsecoloxix.it",
group_rule: "it_repubblica_domains"
group_rule: "###_gr_it_repubblica_domains"
},
"Inc.com": {
domain: "inc.com",
@ -748,11 +748,11 @@ var defaultSites = {
},
"La Nuova Sardegna": {
domain: "lanuovasardegna.it",
group_rule: "it_repubblica_domains"
group_rule: "###_gr_it_repubblica_domains"
},
"La Repubblica": {
domain: "repubblica.it",
group_rule: "it_repubblica_domains"
group_rule: "###_gr_it_repubblica_domains"
},
"La Segunda": {
domain: "lasegunda.com",
@ -760,7 +760,7 @@ var defaultSites = {
},
"La Stampa": {
domain: "lastampa.it",
group_rule: "it_repubblica_domains"
group_rule: "###_gr_it_repubblica_domains"
},
"La Tercera": {
domain: "latercera.com",
@ -802,7 +802,7 @@ var defaultSites = {
},
"Le Scienze": {
domain: "lescienze.it",
group_rule: "it_repubblica_domains"
group_rule: "###_gr_it_repubblica_domains"
},
"Le Télégramme": {
domain: "letelegramme.fr",
@ -832,7 +832,7 @@ var defaultSites = {
},
"LimesOnline": {
domain: "limesonline.com",
group_rule: "it_repubblica_domains"
group_rule: "###_gr_it_repubblica_domains"
},
"Live Law": {
domain: "livelaw.in",
@ -873,7 +873,7 @@ var defaultSites = {
},
"Marca": {
domain: "marca.com",
group_rule: "es_unidad_domains"
group_rule: "###_gr_es_unidad_domains"
},
"Marianne.net": {
domain: "marianne.net",
@ -1077,7 +1077,7 @@ var defaultSites = {
},
"Parool": {
domain: "parool.nl",
group_rule: "nl_pg_domains"
group_rule: "###_gr_nl_pg_domains"
},
"Philosophy Now": {
domain: "philosophynow.org"
@ -1097,7 +1097,7 @@ var defaultSites = {
},
"Precision Oncology News": {
domain: "precisiononcologynews.com",
group_rule: "usa_genomeweb_domains"
group_rule: "###_gr_usa_genomeweb_domains"
},
"Prospect Magazine": {
domain: "prospectmagazine.co.uk",
@ -1266,7 +1266,7 @@ var defaultSites = {
},
"The Age": {
domain: "theage.com.au",
group_rule: "au_nine_domains"
group_rule: "###_gr_au_nine_domains"
},
"The American Interest": {
domain: "the-american-interest.com",
@ -1448,7 +1448,7 @@ var defaultSites = {
},
"The Sydney Morning Herald": {
domain: "smh.com.au",
group_rule: "au_nine_domains"
group_rule: "###_gr_au_nine_domains"
},
"The Telegraph": {
domain: "telegraph.co.uk",
@ -1545,7 +1545,7 @@ var defaultSites = {
},
"Trouw": {
domain: "trouw.nl",
group_rule: "nl_pg_domains"
group_rule: "###_gr_nl_pg_domains"
},
"USA Today": {
domain: "usatoday.com",
@ -1576,11 +1576,11 @@ var defaultSites = {
},
"Volkskrant": {
domain: "volkskrant.nl",
group_rule: "nl_pg_domains"
group_rule: "###_gr_nl_pg_domains"
},
"WAtoday": {
domain: "watoday.com.au",
group_rule: "au_nine_domains"
group_rule: "###_gr_au_nine_domains"
},
"Westfalen-Blatt": {
domain: "westfalen-blatt.de",
@ -1607,6 +1607,31 @@ var defaultSites = {
allow_cookies: 1,
useragent: "googlebot"
},
"###_gr_au_nine_domains": {
group_rule_domains: ["brisbanetimes.com.au", "smh.com.au", "theage.com.au", "watoday.com.au"],
block_regex: /cdn\.ampproject\.org\/v\d\/amp-((sticky-)?ad|subscriptions)-.+\.js/
},
"###_gr_es_unidad_domains": {
group_rule_domains: ["elmundo.es", "expansion.com", "marca.com"],
allow_cookies: 1,
block_regex: /cdn\.ampproject\.org\/v\d\/amp-(access|(sticky-)?ad|consent|subscriptions)-.+\.js/
},
"###_gr_it_repubblica_domains": {
group_rule_domains: ["gelocal.it", "ilsecoloxix.it", "lanuovasardegna.it", "lastampa.it", "limesonline.com", "repubblica.it"],
allow_cookies: 1,
block_regex: /(scripts\.repubblica\.it\/pw\/pw\.js|cdn\.ampproject\.org\/v\d\/amp-(access|ad|user-notification)-.+\.js)/,
useragent: "googlebot"
},
"###_gr_nl_pg_domains": {
group_rule_domains: ["parool.nl", "trouw.nl", "volkskrant.nl", "humo.be", "demorgen.be"],
remove_cookies_select_drop: ["TID_ID"],
block_regex: "\\.{domain}\\/temptation\\/resolve"
},
"###_gr_usa_genomeweb_domains": {
group_rule_domains: ["genomeweb.com", "360dx.com", "precisiononcologynews.com"],
allow_cookies: 1,
block_regex: /crain-platform-.+-prod\.s3\.amazonaws\.com\/s3fs-public\/js\/js_.+\.js/
},
"* Block Paywall-scripts (opt-in to custom sites to enable also for non-listed sites)": {
domain: "###"
},
@ -1678,42 +1703,14 @@ var defaultSites = {
}
}
var defaultSites_grouped_domains = Object.values(defaultSites).map(x => x.domain);
var defaultSites_grouped_domains = Object.values(defaultSites).filter(function (value) {
return value.hasOwnProperty('domain');
}).map(x => x.domain);
var defaultSites_groups_domains = [].concat.apply([], Object.values(defaultSites).filter(function (value) {
return value.hasOwnProperty('group');
}).map(x => x.group));
var defaultSites_domains = defaultSites_grouped_domains.concat(defaultSites_groups_domains);
// grouped domains (rules only)
var au_nine_domains = ['brisbanetimes.com.au', 'smh.com.au', 'theage.com.au', 'watoday.com.au'];
var es_unidad_domains = ['elmundo.es', 'expansion.com', 'marca.com'];
var it_repubblica_domains = ['gelocal.it', 'ilsecoloxix.it', 'lanuovasardegna.it', 'lastampa.it', 'limesonline.com', 'repubblica.it'].concat(['lescienze.it']);
var nl_pg_domains = ['parool.nl', 'trouw.nl', 'volkskrant.nl', 'humo.be', 'demorgen.be'];
var usa_genomeweb_domains = ['genomeweb.com', '360dx.com', 'precisiononcologynews.com'];
var group_rules = {
au_nine_domains: {
block_regex: /cdn\.ampproject\.org\/v\d\/amp-((sticky-)?ad|subscriptions)-.+\.js/
},
es_unidad_domains: {
allow_cookies: 1,
block_regex: /cdn\.ampproject\.org\/v\d\/amp-(access|(sticky-)?ad|consent|subscriptions)-.+\.js/
},
it_repubblica_domains: {
allow_cookies: 1,
block_regex: /(scripts\.repubblica\.it\/pw\/pw\.js|cdn\.ampproject\.org\/v\d\/amp-(access|ad|user-notification)-.+\.js)/,
useragent: "googlebot"
},
nl_pg_domains: {
remove_cookies_select_drop: ['TID_ID'],
block_regex: "\\.{domain}\\/temptation\\/resolve"
},
usa_genomeweb_domains: {
allow_cookies: 1,
block_regex: /crain-platform-.+-prod\.s3\.amazonaws\.com\/s3fs-public\/js\/js_.+\.js/
}
}
function addCookieRules(rule, custom) {
if (rule.hasOwnProperty('remove_cookies_select_drop') || rule.hasOwnProperty('remove_cookies_select_hold') || (custom && !rule.hasOwnProperty('allow_cookies'))) {
rule.allow_cookies = 1;
@ -1721,26 +1718,43 @@ function addCookieRules(rule, custom) {
}
}
function expandSiteRules(sites, custom = false) {
function expandSiteRules(sites, updated = false) {
for (let site in sites) {
let rule = sites[site];
let domain = rule.domain;
if (rule.hasOwnProperty('group_rule')) {
let rules = group_rules[rule.group_rule];
for (key in rules)
sites[site][key] = rules[key];
sites[site].domain = domain;
let rules = sites[rule.group_rule];
for (key in rules) {
if (key !== 'group_rule_domains')
sites[site][key] = rules[key];
}
//delete sites[site].group_rule;
}
if (rule.hasOwnProperty('group'))
if (updated) {
if (rule.hasOwnProperty('group_rule_domains')) {
let domains = rule.group_rule_domains;
for (let domain of domains) {
let defaultTitle = Object.keys(defaultSites).find(key => defaultSites[key].domain === domain);
if (defaultTitle) {
for (key in rule) {
if (key !== 'group_rule_domains')
defaultSites[defaultTitle][key] = rule[key];
}
}
}
}
}
if (rule.hasOwnProperty('group')) {
let domain = rule.domain;
grouped_sites[domain] = rule.group
}
}
}
var grouped_sites = {};
expandSiteRules(defaultSites);
// grouped domains (dompurify)
// grouped domains (background)
var it_repubblica_domains = defaultSites['###_gr_it_repubblica_domains']['group_rule_domains'].concat(['lescienze.it']);
var nl_mediahuis_region_domains = grouped_sites['###_nl_mediahuis_region'];
var no_nhst_media_domains = grouped_sites['###_no_nhst_media'];
var usa_theathletic_domains = grouped_sites['###_usa_theathletic'];