Skip to content

Commit

Permalink
Allow for support of more event types
Browse files Browse the repository at this point in the history
Related commit:
ef311dd
  • Loading branch information
gorhill committed Nov 12, 2023
1 parent 11fe8ee commit 3db46c1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/******************************************************************************/
Expand Down

0 comments on commit 3db46c1

Please sign in to comment.