1
0
mirror of https://github.com/gorhill/uBlock.git synced 2025-01-31 20:21:35 +01:00

[mv3] Minor code review

This commit is contained in:
Raymond Hill 2024-12-14 09:01:23 -05:00
parent c2a4b72fee
commit c279cded17
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -23,11 +23,8 @@ import {
browser,
dnr,
i18n,
runtime,
} from './ext.js';
import {
localRead, localRemove, localWrite,
runtime,
sessionRead, sessionRemove, sessionWrite,
} from './ext.js';
@ -578,13 +575,17 @@ async function defaultRulesetsFromLanguage() {
`\\b(${Array.from(langSet).join('|')})\\b`
);
const manifest = runtime.getManifest();
const rulesets = manifest.declarative_net_request.rule_resources;
const rulesetDetails = await getRulesetDetails();
const out = [];
for ( const [ id, details ] of rulesetDetails ) {
if ( details.enabled ) {
for ( const ruleset of rulesets ) {
const { id, enabled } = ruleset;
if ( enabled ) {
out.push(id);
continue;
}
const details = rulesetDetails.get(id);
if ( typeof details.lang !== 'string' ) { continue; }
if ( reTargetLang.test(details.lang) === false ) { continue; }
out.push(id);
@ -598,12 +599,15 @@ async function patchDefaultRulesets() {
const [
oldDefaultIds = [],
newDefaultIds,
newIds,
] = await Promise.all([
localRead('defaultRulesetIds'),
defaultRulesetsFromLanguage(),
getRulesetDetails(),
]);
const manifest = runtime.getManifest();
const validIds = new Set(
manifest.declarative_net_request.rule_resources.map(r => r.id)
);
const toAdd = [];
const toRemove = [];
for ( const id of newDefaultIds ) {
@ -615,7 +619,7 @@ async function patchDefaultRulesets() {
toRemove.push(id);
}
for ( const id of rulesetConfig.enabledRulesets ) {
if ( newIds.has(id) ) { continue; }
if ( validIds.has(id) ) { continue; }
toRemove.push(id);
}
localWrite('defaultRulesetIds', newDefaultIds);