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
1 changed files with 9 additions and 5 deletions

View File

@ -2704,7 +2704,7 @@ function cookieRemover(
const safe = safeSelf();
const reName = safe.patternToRegex(needle);
const extraArgs = safe.getExtraArgs(Array.from(arguments), 1);
const throttle = (fn, ms = 1000) => {
const throttle = (fn, ms = 500) => {
if ( throttle.timer !== undefined ) { return; }
throttle.timer = setTimeout(( ) => {
throttle.timer = undefined;
@ -2746,13 +2746,17 @@ function cookieRemover(
}
});
};
if ( extraArgs.when === 'scroll' ) {
document.addEventListener('scroll', ( ) => {
removeCookie();
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);
}, { passive: true });
}
removeCookie();
window.addEventListener('beforeunload', removeCookie);
}
/******************************************************************************/