aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/common/stop-blocking.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripts/common/stop-blocking.ts')
-rw-r--r--src/scripts/common/stop-blocking.ts52
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;
+});