File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -2704,7 +2704,7 @@ function cookieRemover(
2704
2704
const safe = safeSelf ( ) ;
2705
2705
const reName = safe . patternToRegex ( needle ) ;
2706
2706
const extraArgs = safe . getExtraArgs ( Array . from ( arguments ) , 1 ) ;
2707
- const throttle = ( fn , ms = 1000 ) => {
2707
+ const throttle = ( fn , ms = 500 ) => {
2708
2708
if ( throttle . timer !== undefined ) { return ; }
2709
2709
throttle . timer = setTimeout ( ( ) => {
2710
2710
throttle . timer = undefined ;
@@ -2746,13 +2746,17 @@ function cookieRemover(
2746
2746
}
2747
2747
} ) ;
2748
2748
} ;
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 , ( ) => {
2751
2757
throttle ( removeCookie ) ;
2752
2758
} , { passive : true } ) ;
2753
2759
}
2754
- removeCookie ( ) ;
2755
- window . addEventListener ( 'beforeunload' , removeCookie ) ;
2756
2760
}
2757
2761
2758
2762
/******************************************************************************/
You can’t perform that action at this time.
0 commit comments