diff options
| author | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-13 23:32:26 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-13 23:32:26 +0530 |
| commit | ce401d03e75bcbfd1cdfa963954e0807219fb80d (patch) | |
| tree | 52a813c1705a952312c20c328b00fa845a3453f9 /src/scripts/common/stop-blocking.ts | |
| parent | 98e7019c61ea0ffe344ef7ce809d38d62254a9fc (diff) | |
| parent | dfba7ff6fff7bde33b40a343a2318b35c429b40f (diff) | |
| download | banglar-bhumi-utils-ce401d03e75bcbfd1cdfa963954e0807219fb80d.tar.gz banglar-bhumi-utils-ce401d03e75bcbfd1cdfa963954e0807219fb80d.zip | |
Merge pull request #6 from arpitchakladar/adding-documentation-comments
Adding documentation comments
Diffstat (limited to 'src/scripts/common/stop-blocking.ts')
| -rw-r--r-- | src/scripts/common/stop-blocking.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/scripts/common/stop-blocking.ts b/src/scripts/common/stop-blocking.ts new file mode 100644 index 0000000..8588834 --- /dev/null +++ b/src/scripts/common/stop-blocking.ts @@ -0,0 +1,52 @@ +/** + * Proxies jQuery's `.bind()` (for the `"cut copy paste"` event) and + * `.keydown()` so that the website's copy/paste/right-click blocking + * 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 = jQueryPrototype.bind; + /** Proxies jQuery `.bind()` to no-op the `"cut copy paste"` event. */ + 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 = jQueryPrototype.keydown; + /** Proxies jQuery `.keydown()` so all key presses are allowed. */ + jQueryPrototype.keydown = function( + this: JQuery, + ..._args: Parameters<JQueryKeydownFn> + ): JQuery { + return proxiedKeydown.call(this, () => true); + }; + + jQueryPrototype.bind = proxiedBind; + jQueryPrototype.keydown = proxiedKeydown; + document.oncontextmenu = (): boolean => true; +}); |
