Skip to content

Commit 3db46c1

Browse files
committed
Allow for support of more event types
Related commit: ef311dd
1 parent 11fe8ee commit 3db46c1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

assets/resources/scriptlets.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,7 @@ function cookieRemover(
27042704
const safe = safeSelf();
27052705
const reName = safe.patternToRegex(needle);
27062706
const extraArgs = safe.getExtraArgs(Array.from(arguments), 1);
2707-
const throttle = (fn, ms = 1000) => {
2707+
const throttle = (fn, ms = 500) => {
27082708
if ( throttle.timer !== undefined ) { return; }
27092709
throttle.timer = setTimeout(( ) => {
27102710
throttle.timer = undefined;
@@ -2746,13 +2746,17 @@ function cookieRemover(
27462746
}
27472747
});
27482748
};
2749-
if ( extraArgs.when === 'scroll' ) {
2750-
document.addEventListener('scroll', ( ) => {
2749+
removeCookie();
2750+
window.addEventListener('beforeunload', removeCookie);
2751+
if ( typeof extraArgs.when !== 'string' ) { return; }
2752+
const supportedEventTypes = [ 'scroll', 'keydown' ];
2753+
const eventTypes = extraArgs.when.split(/\s/);
2754+
for ( const type of eventTypes ) {
2755+
if ( supportedEventTypes.includes(type) === false ) { continue; }
2756+
document.addEventListener(type, ( ) => {
27512757
throttle(removeCookie);
27522758
}, { passive: true });
27532759
}
2754-
removeCookie();
2755-
window.addEventListener('beforeunload', removeCookie);
27562760
}
27572761

27582762
/******************************************************************************/

0 commit comments

Comments
 (0)