mirror of https://github.com/gorhill/uBlock.git
Coalesce tab reloads in burst "relax blocking mode" ops
Quickly firing "Relax blocking mode" commands will cause the tab to reload only once.
This commit is contained in:
parent
ad0315a4cd
commit
4792e0e291
|
@ -38,7 +38,10 @@
|
|||
|
||||
if ( µBlock.canUseShortcuts === false ) { return; }
|
||||
|
||||
const relaxBlockingMode = function(tab) {
|
||||
const relaxBlockingMode = (( ) => {
|
||||
const reloadTimers = new Map();
|
||||
|
||||
return function(tab) {
|
||||
if ( tab instanceof Object === false || tab.id <= 0 ) { return; }
|
||||
|
||||
const µb = µBlock;
|
||||
|
@ -105,10 +108,25 @@ const relaxBlockingMode = function(tab) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( newProfileBits & 0b00000001 ) {
|
||||
vAPI.tabs.reload(tab.id);
|
||||
// Reload the target tab?
|
||||
if ( (newProfileBits & 0b00000001) === 0 ) { return; }
|
||||
|
||||
// Reload: use a timer to coalesce bursts of reload commands.
|
||||
let timer = reloadTimers.get(tab.id);
|
||||
if ( timer !== undefined ) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
timer = vAPI.setTimeout(
|
||||
tabId => {
|
||||
reloadTimers.delete(tabId);
|
||||
vAPI.tabs.reload(tabId);
|
||||
},
|
||||
547,
|
||||
tab.id
|
||||
);
|
||||
reloadTimers.set(tab.id, timer);
|
||||
};
|
||||
})();
|
||||
|
||||
vAPI.commands.onCommand.addListener(command => {
|
||||
const µb = µBlock;
|
||||
|
|
Loading…
Reference in New Issue