From 348003e4d634922d7a9ec2d6108795bec776ac85 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Sun, 2 Jun 2024 14:33:19 +0800 Subject: [PATCH] Add ws blink mod that actually works --- ExampleMods/blink_ws.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ExampleMods/blink_ws.js diff --git a/ExampleMods/blink_ws.js b/ExampleMods/blink_ws.js new file mode 100644 index 0000000..1632ade --- /dev/null +++ b/ExampleMods/blink_ws.js @@ -0,0 +1,33 @@ +//Blink hack mod that prototype pollutes WebSocket to implement itself. + +var blinking = false; +var backlog = []; +const originalSend = WebSocket.prototype.send; + +Object.defineProperty(WebSocket.prototype, 'send', { + configurable: true, + enumerable: false, + writable: false, + value: function(data) { + if (blinking) { + backlog.push({data: data, thisArg: this}); + } else { + originalSend.call(this, data); + } + } +}); + + +ModAPI.addEventListener("key", (ev)=>{ + if (ev.key === 48) { + ev.preventDefault = true; + blinking = !blinking; + if (blinking === false) { + for (let i = 0; i < backlog.length; i++) { + const backlogItem = backlog[i]; + originalSend.call(backlogItem.thisArg, backlogItem.data); + } + backlog = []; + } + } +}); \ No newline at end of file