From dfba7ff6fff7bde33b40a343a2318b35c429b40f Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Mon, 13 Jul 2026 23:28:46 +0530 Subject: refactor: fixed all of the eslint warnings and errors --- src/scripts/common/stop-blocking.ts | 53 ++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'src/scripts') diff --git a/src/scripts/common/stop-blocking.ts b/src/scripts/common/stop-blocking.ts index bdebfe9..8588834 100644 --- a/src/scripts/common/stop-blocking.ts +++ b/src/scripts/common/stop-blocking.ts @@ -4,26 +4,49 @@ * is disabled. Reverts the prototypes after patching to avoid * interfering with other code. */ + +type JQueryBindFn = ( + eventName: string, + handler: (event: JQuery.Event) => unknown +) => JQuery; + +type JQueryKeydownFn = ( + handler: (event: JQuery.Event) => unknown +) => JQuery; + +type JQueryPrototypeShape = { + bind: JQueryBindFn; + keydown: JQueryKeydownFn +}; + +const jQueryPrototype = $.prototype as unknown as JQueryPrototypeShape; + document.addEventListener("DOMContentLoaded", () => { - const proxiedBind = $.prototype.bind; + const proxiedBind = jQueryPrototype.bind; /** Proxies jQuery `.bind()` to no-op the `"cut copy paste"` event. */ - $.prototype.bind = function() { - if (arguments[0].trim() === "cut copy paste") { - arguments[1] = (_: any) => {}; - } - - return proxiedBind.apply(this, Array.from(arguments) as any); + jQueryPrototype.bind = function( + this: JQuery, + ...args: Parameters + ): JQuery { + const [eventName, handler] = args; + const noop = (): undefined => undefined; + return proxiedBind.call( + this, + eventName, + eventName.trim() === "cut copy paste" ? noop : handler + ); }; - const proxiedKeydown = $.prototype.keydown; + const proxiedKeydown = jQueryPrototype.keydown; /** Proxies jQuery `.keydown()` so all key presses are allowed. */ - $.prototype.keydown = function() { - arguments[0] = (_: any) => true; - - return proxiedKeydown.apply(this, Array.from(arguments) as any); + jQueryPrototype.keydown = function( + this: JQuery, + ..._args: Parameters + ): JQuery { + return proxiedKeydown.call(this, () => true); }; - $.prototype.bind = proxiedBind; - $.prototype.keydown = proxiedKeydown; - document.oncontextmenu = () => true; + jQueryPrototype.bind = proxiedBind; + jQueryPrototype.keydown = proxiedKeydown; + document.oncontextmenu = (): boolean => true; }); -- cgit v1.2.3