Gartic.io chat panel

Panel that sends messages to chat using wsObj (Some codes in this script were adapted from other projects. It is an AI product, for those who want to take the code and publish a developed version.)

// ==UserScript==
// @name         Gartic.io chat panel
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description:tr  wsObj kullanarak chate mesaj gönderen panel (Bu betikte bazı kod bölümleri başka projelerden uyarlanmıştır. Yapay zeka ürünüdür, kodu alıp dahada geliştirilmiş halini atmak isteyenler içindir.) 
// @description  Panel that sends messages to chat using wsObj (Some codes in this script were adapted from other projects. It is an AI product, for those who want to take the code and publish a developed version.)
// @author       《₁₈₇》
// @match        *://gartic.io/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let originalWebSocket = window.WebSocket;
    let setTrue = 0;

    window.wsObj = {
        id: null,
        roomCode: null,
        lengthID: null,
        send: function(msg) {
            if (this.ws) this.ws.send(msg);
        }
    };

    window.WebSocket = function(...args) {
        let ws = new originalWebSocket(...args);
        ws.addEventListener('open', () => {
            window.wsObj.ws = ws;
            window.eventAdd();
        });
        return ws;
    };
    window.WebSocket.prototype = originalWebSocket.prototype;

    window.eventAdd = () => {
        if (!setTrue) {
            setTrue = 1;
            window.wsObj.ws.addEventListener("message", (msg) => {
                try {
                    let data = JSON.parse(msg.data.slice(2));
                    if (data[0] == 5) {
                        window.wsObj.lengthID = data[1];
                        window.wsObj.id = data[2];
                        window.wsObj.roomCode = data[3];
                    }
                } catch (err) {}
            });
        }
    };

    let panel = document.createElement("div");
    panel.style.position = "fixed";
    panel.style.top = "10px";
    panel.style.left = "10px";
    panel.style.background = "rgba(0,0,255,0.8)";
    panel.style.color = "white";
    panel.style.padding = "10px";
    panel.style.borderRadius = "10px";
    panel.style.zIndex = 99999;

    let input = document.createElement("input");
    input.type = "text";
    input.placeholder = "Mesaj yaz...";
    input.style.padding = "5px";
    input.style.borderRadius = "5px";
    input.style.border = "none";
    input.style.outline = "none";
    input.style.width = "150px";
    input.style.marginRight = "5px";

    let sendBtn = document.createElement("button");
    sendBtn.textContent = "Gönder";
    sendBtn.style.background = "red";
    sendBtn.style.color = "white";
    sendBtn.style.border = "none";
    sendBtn.style.padding = "5px 10px";
    sendBtn.style.borderRadius = "5px";
    sendBtn.style.cursor = "pointer";

    function sendMessage() {
        if (!window.wsObj.ws || !window.wsObj.id || input.value.trim() === "") return;
        try {
            let msg = `42[11,${window.wsObj.id},"${input.value}"]`;
            window.wsObj.send(msg);
            input.value = "";
        } catch (err) {}
    }

    sendBtn.onclick = sendMessage;
    input.addEventListener("keydown", function(e) {
        if (e.key === "Enter") sendMessage();
    });

    panel.appendChild(input);
    panel.appendChild(sendBtn);
    document.body.appendChild(panel);
})();