Add comments

This commit is contained in:
ZXMushroom63 2024-06-02 14:36:08 +08:00
parent 348003e4d6
commit 521bce612a
1 changed files with 12 additions and 4 deletions

View File

@ -1,17 +1,24 @@
//Blink hack mod that prototype pollutes WebSocket to implement itself. //Blink hack mod that prototype pollutes WebSocket to implement itself.
//Blinking state
var blinking = false; var blinking = false;
//The backlog of packets that need to be sent on disable
var backlog = []; var backlog = [];
//Store the original, actual WebSocket send method
const originalSend = WebSocket.prototype.send; const originalSend = WebSocket.prototype.send;
//Override WebSocket.send, so when eagler tries to send messages, it runs our code instead
Object.defineProperty(WebSocket.prototype, 'send', { Object.defineProperty(WebSocket.prototype, 'send', {
configurable: true, configurable: true,
enumerable: false, enumerable: false,
writable: false, writable: false,
value: function(data) { value: function(data) {
//If blinking, push data to backlog along with it's websocket instance.
if (blinking) { if (blinking) {
backlog.push({data: data, thisArg: this}); backlog.push({data: data, thisArg: this});
} else { } else { //Else send the data as normal
originalSend.call(this, data); originalSend.call(this, data);
} }
} }
@ -19,10 +26,11 @@ Object.defineProperty(WebSocket.prototype, 'send', {
ModAPI.addEventListener("key", (ev)=>{ ModAPI.addEventListener("key", (ev)=>{
if (ev.key === 48) { if (ev.key === 48) { //KEY_B
ev.preventDefault = true; ev.preventDefault = true;
blinking = !blinking; blinking = !blinking; //Toggle blinking boolean
if (blinking === false) {
if (blinking === false) { //If blink just turned off, send data.
for (let i = 0; i < backlog.length; i++) { for (let i = 0; i < backlog.length; i++) {
const backlogItem = backlog[i]; const backlogItem = backlog[i];
originalSend.call(backlogItem.thisArg, backlogItem.data); originalSend.call(backlogItem.thisArg, backlogItem.data);