mirror of https://github.com/gorhill/uBlock.git
Add advanced setting `requestStatsDisabled`
To disable collating global blocked/allowed counts. Boolean, default to `false`. Setting to `true` will prevent uBO from loading/saving global blocked/allowed counts, and in such case the "Blocked since install" count instead reflects the count since uBO launched. Setting back to `false` will cause the counts to resume from last time they were saved. Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3100
This commit is contained in:
parent
e0971fe0ac
commit
e02ea69c86
|
@ -83,6 +83,7 @@ const hiddenSettingsDefault = {
|
||||||
popupPanelLockedSections: 0,
|
popupPanelLockedSections: 0,
|
||||||
popupPanelHeightMode: 0,
|
popupPanelHeightMode: 0,
|
||||||
requestJournalProcessPeriod: 1000,
|
requestJournalProcessPeriod: 1000,
|
||||||
|
requestStatsDisabled: false,
|
||||||
selfieAfter: 2,
|
selfieAfter: 2,
|
||||||
strictBlockingBypassDuration: 120,
|
strictBlockingBypassDuration: 120,
|
||||||
toolbarWarningTimeout: 60,
|
toolbarWarningTimeout: 60,
|
||||||
|
|
|
@ -97,52 +97,80 @@ import {
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
{
|
{
|
||||||
µb.loadLocalSettings = ( ) => Promise.all([
|
const requestStats = µb.requestStats;
|
||||||
vAPI.sessionStorage.get('requestStats'),
|
let requestStatsDisabled = false;
|
||||||
vAPI.storage.get('requestStats'),
|
|
||||||
vAPI.storage.get([ 'blockedRequestCount', 'allowedRequestCount' ]),
|
µb.loadLocalSettings = async ( ) => {
|
||||||
]).then(([ a, b, c ]) => {
|
requestStatsDisabled = µb.hiddenSettings.requestStatsDisabled;
|
||||||
if ( a instanceof Object && a.requestStats ) { return a.requestStats; }
|
if ( requestStatsDisabled ) { return; }
|
||||||
if ( b instanceof Object && b.requestStats ) { return b.requestStats; }
|
return Promise.all([
|
||||||
if ( c instanceof Object && Object.keys(c).length === 2 ) {
|
vAPI.sessionStorage.get('requestStats'),
|
||||||
return {
|
vAPI.storage.get('requestStats'),
|
||||||
blockedCount: c.blockedRequestCount,
|
vAPI.storage.get([ 'blockedRequestCount', 'allowedRequestCount' ]),
|
||||||
allowedCount: c.allowedRequestCount,
|
]).then(([ a, b, c ]) => {
|
||||||
};
|
if ( a instanceof Object && a.requestStats ) { return a.requestStats; }
|
||||||
}
|
if ( b instanceof Object && b.requestStats ) { return b.requestStats; }
|
||||||
return { blockedCount: 0, allowedCount: 0 };
|
if ( c instanceof Object && Object.keys(c).length === 2 ) {
|
||||||
}).then(({ blockedCount, allowedCount }) => {
|
return {
|
||||||
µb.requestStats.blockedCount += blockedCount;
|
blockedCount: c.blockedRequestCount,
|
||||||
µb.requestStats.allowedCount += allowedCount;
|
allowedCount: c.allowedRequestCount,
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
return { blockedCount: 0, allowedCount: 0 };
|
||||||
|
}).then(({ blockedCount, allowedCount }) => {
|
||||||
|
requestStats.blockedCount += blockedCount;
|
||||||
|
requestStats.allowedCount += allowedCount;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const SAVE_DELAY_IN_MINUTES = 3.6;
|
const SAVE_DELAY_IN_MINUTES = 3.6;
|
||||||
const QUICK_SAVE_DELAY_IN_SECONDS = 23;
|
const QUICK_SAVE_DELAY_IN_SECONDS = 23;
|
||||||
|
|
||||||
|
const stopTimers = ( ) => {
|
||||||
|
vAPI.alarms.clear('saveLocalSettings');
|
||||||
|
quickSaveTimer.off();
|
||||||
|
saveTimer.off();
|
||||||
|
};
|
||||||
|
|
||||||
const saveTimer = vAPI.defer.create(( ) => {
|
const saveTimer = vAPI.defer.create(( ) => {
|
||||||
µb.saveLocalSettings();
|
µb.saveLocalSettings();
|
||||||
});
|
});
|
||||||
|
|
||||||
const quickSaveTimer = vAPI.defer.create(( ) => {
|
const quickSaveTimer = vAPI.defer.create(( ) => {
|
||||||
|
if ( vAPI.sessionStorage.unavailable !== true ) {
|
||||||
|
vAPI.sessionStorage.set({ requestStats: requestStats });
|
||||||
|
}
|
||||||
|
if ( requestStatsDisabled ) { return; }
|
||||||
saveTimer.on({ min: SAVE_DELAY_IN_MINUTES });
|
saveTimer.on({ min: SAVE_DELAY_IN_MINUTES });
|
||||||
if ( vAPI.sessionStorage.unavailable ) { return; }
|
|
||||||
vAPI.sessionStorage.set({ requestStats: µb.requestStats });
|
|
||||||
vAPI.alarms.createIfNotPresent('saveLocalSettings', {
|
vAPI.alarms.createIfNotPresent('saveLocalSettings', {
|
||||||
delayInMinutes: SAVE_DELAY_IN_MINUTES + 0.5
|
delayInMinutes: SAVE_DELAY_IN_MINUTES + 0.5
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
µb.incrementRequestStats = (blocked, allowed) => {
|
µb.incrementRequestStats = (blocked, allowed) => {
|
||||||
µb.requestStats.blockedCount += blocked;
|
requestStats.blockedCount += blocked;
|
||||||
µb.requestStats.allowedCount += allowed;
|
requestStats.allowedCount += allowed;
|
||||||
quickSaveTimer.on({ sec: QUICK_SAVE_DELAY_IN_SECONDS });
|
quickSaveTimer.on({ sec: QUICK_SAVE_DELAY_IN_SECONDS });
|
||||||
};
|
};
|
||||||
|
|
||||||
µb.saveLocalSettings = ( ) => {
|
µb.saveLocalSettings = ( ) => {
|
||||||
vAPI.alarms.clear('saveLocalSettings');
|
stopTimers();
|
||||||
quickSaveTimer.off(); saveTimer.off();
|
if ( requestStatsDisabled ) { return; }
|
||||||
return vAPI.storage.set({ requestStats: µb.requestStats });
|
return vAPI.storage.set({ requestStats: µb.requestStats });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onBroadcast(msg => {
|
||||||
|
if ( msg.what !== 'hiddenSettingsChanged' ) { return; }
|
||||||
|
const newState = µb.hiddenSettings.requestStatsDisabled;
|
||||||
|
if ( requestStatsDisabled === newState ) { return; }
|
||||||
|
requestStatsDisabled = newState;
|
||||||
|
if ( newState ) {
|
||||||
|
stopTimers();
|
||||||
|
µb.requestStats.blockedCount = µb.requestStats.allowedCount = 0;
|
||||||
|
} else {
|
||||||
|
µb.loadLocalSettings();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
Loading…
Reference in New Issue