mirror of https://github.com/gorhill/uBlock.git
[mv3] Fine tune various portions of code
This commit is contained in:
parent
f282b43550
commit
1ad7410077
|
@ -59,6 +59,7 @@ iframe {
|
||||||
border: 0;
|
border: 0;
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
min-height: 800px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
#unsavedWarning {
|
#unsavedWarning {
|
||||||
|
|
|
@ -65,11 +65,12 @@ const rulesetConfig = {
|
||||||
version: '',
|
version: '',
|
||||||
enabledRulesets: [ 'default' ],
|
enabledRulesets: [ 'default' ],
|
||||||
autoReload: 1,
|
autoReload: 1,
|
||||||
firstRun: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const UBOL_ORIGIN = runtime.getURL('').replace(/\/$/, '');
|
const UBOL_ORIGIN = runtime.getURL('').replace(/\/$/, '');
|
||||||
|
|
||||||
|
let firstRun = false;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function getCurrentVersion() {
|
function getCurrentVersion() {
|
||||||
|
@ -82,26 +83,26 @@ async function loadRulesetConfig() {
|
||||||
rulesetConfig.version = data.version;
|
rulesetConfig.version = data.version;
|
||||||
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
||||||
rulesetConfig.autoReload = data.autoReload;
|
rulesetConfig.autoReload = data.autoReload;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
data = await localRead('rulesetConfig');
|
data = await localRead('rulesetConfig');
|
||||||
if ( data ) {
|
if ( data ) {
|
||||||
rulesetConfig.version = data.version;
|
rulesetConfig.version = data.version;
|
||||||
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
||||||
rulesetConfig.autoReload = data.autoReload;
|
rulesetConfig.autoReload = data.autoReload;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
data = await loadRulesetConfig.convertLegacyStorage();
|
data = await loadRulesetConfig.convertLegacyStorage();
|
||||||
if ( data ) {
|
if ( data ) {
|
||||||
rulesetConfig.version = data.version;
|
rulesetConfig.version = data.version;
|
||||||
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
rulesetConfig.enabledRulesets = data.enabledRulesets;
|
||||||
rulesetConfig.autoReload = data.autoReload;
|
rulesetConfig.autoReload = data.autoReload;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
rulesetConfig.enabledRulesets = await defaultRulesetsFromLanguage();
|
rulesetConfig.enabledRulesets = await defaultRulesetsFromLanguage();
|
||||||
rulesetConfig.firstRun = true;
|
|
||||||
sessionWrite('rulesetConfig', rulesetConfig);
|
sessionWrite('rulesetConfig', rulesetConfig);
|
||||||
localWrite('rulesetConfig', rulesetConfig);
|
localWrite('rulesetConfig', rulesetConfig);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: To remove after next stable release is widespread (2023-06-04)
|
// TODO: To remove after next stable release is widespread (2023-06-04)
|
||||||
|
@ -221,9 +222,9 @@ function onMessage(request, sender, callback) {
|
||||||
enabledRulesets,
|
enabledRulesets,
|
||||||
rulesetDetails: Array.from(rulesetDetails.values()),
|
rulesetDetails: Array.from(rulesetDetails.values()),
|
||||||
autoReload: rulesetConfig.autoReload === 1,
|
autoReload: rulesetConfig.autoReload === 1,
|
||||||
firstRun: rulesetConfig.firstRun,
|
firstRun,
|
||||||
});
|
});
|
||||||
rulesetConfig.firstRun = false;
|
firstRun = false;
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +298,7 @@ function onMessage(request, sender, callback) {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
await loadRulesetConfig();
|
firstRun = await loadRulesetConfig();
|
||||||
await enableRulesets(rulesetConfig.enabledRulesets);
|
await enableRulesets(rulesetConfig.enabledRulesets);
|
||||||
|
|
||||||
// We need to update the regex rules only when ruleset version changes.
|
// We need to update the regex rules only when ruleset version changes.
|
||||||
|
@ -330,10 +331,6 @@ async function start() {
|
||||||
if ( dnr.setExtensionActionOptions ) {
|
if ( dnr.setExtensionActionOptions ) {
|
||||||
dnr.setExtensionActionOptions({ displayActionCountAsBadgeText: true });
|
dnr.setExtensionActionOptions({ displayActionCountAsBadgeText: true });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
(async ( ) => {
|
|
||||||
await start();
|
|
||||||
|
|
||||||
runtime.onMessage.addListener(onMessage);
|
runtime.onMessage.addListener(onMessage);
|
||||||
|
|
||||||
|
@ -341,7 +338,9 @@ async function start() {
|
||||||
( ) => { onPermissionsRemoved(); }
|
( ) => { onPermissionsRemoved(); }
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( rulesetConfig.firstRun ) {
|
if ( firstRun ) {
|
||||||
runtime.openOptionsPage();
|
runtime.openOptionsPage();
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
start();
|
||||||
|
|
|
@ -100,6 +100,9 @@ async function getActualFilteringModeDetails() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( details ) {
|
||||||
|
sessionWrite('filteringModeDetails', details);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const out = {
|
const out = {
|
||||||
none: new Set(details.none),
|
none: new Set(details.none),
|
||||||
|
|
|
@ -46,19 +46,17 @@ const CURRENT_CONFIG_BASE_RULE_ID = 9000000;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
let rulesetDetailsPromise;
|
|
||||||
|
|
||||||
function getRulesetDetails() {
|
function getRulesetDetails() {
|
||||||
if ( rulesetDetailsPromise !== undefined ) {
|
if ( getRulesetDetails.rulesetDetailsPromise !== undefined ) {
|
||||||
return rulesetDetailsPromise;
|
return getRulesetDetails.rulesetDetailsPromise;
|
||||||
}
|
}
|
||||||
rulesetDetailsPromise = fetchJSON('/rulesets/ruleset-details').then(entries => {
|
getRulesetDetails.rulesetDetailsPromise = fetchJSON('/rulesets/ruleset-details').then(entries => {
|
||||||
const map = new Map(
|
const rulesMap = new Map(
|
||||||
entries.map(entry => [ entry.id, entry ])
|
entries.map(entry => [ entry.id, entry ])
|
||||||
);
|
);
|
||||||
return map;
|
return rulesMap;
|
||||||
});
|
});
|
||||||
return rulesetDetailsPromise;
|
return getRulesetDetails.rulesetDetailsPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -68,12 +66,10 @@ function getDynamicRules() {
|
||||||
return getDynamicRules.dynamicRuleMapPromise;
|
return getDynamicRules.dynamicRuleMapPromise;
|
||||||
}
|
}
|
||||||
getDynamicRules.dynamicRuleMapPromise = dnr.getDynamicRules().then(rules => {
|
getDynamicRules.dynamicRuleMapPromise = dnr.getDynamicRules().then(rules => {
|
||||||
const map = new Map(
|
const rulesMap = new Map(rules.map(rule => [ rule.id, rule ]));
|
||||||
rules.map(rule => [ rule.id, rule ])
|
ubolLog(`Dynamic rule count: ${rulesMap.size}`);
|
||||||
);
|
ubolLog(`Available dynamic rule count: ${dnr.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES - rulesMap.size}`);
|
||||||
ubolLog(`Dynamic rule count: ${map.size}`);
|
return rulesMap;
|
||||||
ubolLog(`Available dynamic rule count: ${dnr.MAX_NUMBER_OF_DYNAMIC_AND_SESSION_RULES - map.size}`);
|
|
||||||
return map;
|
|
||||||
});
|
});
|
||||||
return getDynamicRules.dynamicRuleMapPromise;
|
return getDynamicRules.dynamicRuleMapPromise;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,7 +126,7 @@ const hostnamesFromMatches = origins => {
|
||||||
const ubolLog = (...args) => {
|
const ubolLog = (...args) => {
|
||||||
// Do not pollute dev console in stable release.
|
// Do not pollute dev console in stable release.
|
||||||
if ( browser.runtime.id === 'ddkjiahejlhfcafbddmgiahcphecmpfh' ) { return; }
|
if ( browser.runtime.id === 'ddkjiahejlhfcafbddmgiahcphecmpfh' ) { return; }
|
||||||
console.info(...args);
|
console.info('[uBOL]', ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
Loading…
Reference in New Issue