diff options
| author | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-13 23:28:46 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-13 23:28:46 +0530 |
| commit | dfba7ff6fff7bde33b40a343a2318b35c429b40f (patch) | |
| tree | 52a813c1705a952312c20c328b00fa845a3453f9 /src/scripts | |
| parent | 68777ec421d41be0da27013afd4165ae7d658d26 (diff) | |
| download | banglar-bhumi-utils-dfba7ff6fff7bde33b40a343a2318b35c429b40f.tar.gz banglar-bhumi-utils-dfba7ff6fff7bde33b40a343a2318b35c429b40f.zip | |
refactor: fixed all of the eslint warnings and errors
Diffstat (limited to 'src/scripts')
| -rw-r--r-- | src/scripts/common/stop-blocking.ts | 53 |
1 files changed, 38 insertions, 15 deletions
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<JQueryBindFn> + ): 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<JQueryKeydownFn> + ): 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; }); |
