1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

Allow for support of more event types

Related commit:
ef311ddbec
This commit is contained in:
Raymond Hill 2023-11-12 11:44:24 -05:00
parent 11fe8ee3b5
commit 3db46c1728
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -2704,7 +2704,7 @@ function cookieRemover(
const safe = safeSelf(); const safe = safeSelf();
const reName = safe.patternToRegex(needle); const reName = safe.patternToRegex(needle);
const extraArgs = safe.getExtraArgs(Array.from(arguments), 1); const extraArgs = safe.getExtraArgs(Array.from(arguments), 1);
const throttle = (fn, ms = 1000) => { const throttle = (fn, ms = 500) => {
if ( throttle.timer !== undefined ) { return; } if ( throttle.timer !== undefined ) { return; }
throttle.timer = setTimeout(( ) => { throttle.timer = setTimeout(( ) => {
throttle.timer = undefined; throttle.timer = undefined;
@ -2746,13 +2746,17 @@ function cookieRemover(
} }
}); });
}; };
if ( extraArgs.when === 'scroll' ) { removeCookie();
document.addEventListener('scroll', ( ) => { window.addEventListener('beforeunload', removeCookie);
if ( typeof extraArgs.when !== 'string' ) { return; }
const supportedEventTypes = [ 'scroll', 'keydown' ];
const eventTypes = extraArgs.when.split(/\s/);
for ( const type of eventTypes ) {
if ( supportedEventTypes.includes(type) === false ) { continue; }
document.addEventListener(type, ( ) => {
throttle(removeCookie); throttle(removeCookie);
}, { passive: true }); }, { passive: true });
} }
removeCookie();
window.addEventListener('beforeunload', removeCookie);
} }
/******************************************************************************/ /******************************************************************************/