Allow for support of more event types · gorhill/uBlock@3db46c1 (original) (raw)

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 /******************************************************************************/