Gartic chat - FIXED

tr: gartic chat alanını geri getirir / büyük chat | en: brings back gartic chat area / bigger chat

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Gartic chat - FIXED
// @description:tr gartic chat alanını geri getirir / büyük chat
// @description:en brings back gartic chat area / big chat
// @author       Enes Yıldız
// @icon         https://i.ibb.co/s9Qv6JNW/107653-thumb.jpg
// @match        https://gartic.io/*
// @run-at       document-start
// @grant        unsafeWindow
// @grant        GM_addStyle
// @version     0.2
// @namespace https://greatest.deepsurf.us/users/1424758
// @description tr: gartic chat alanını geri getirir / büyük chat | en: brings back gartic chat area / bigger chat
// ==/UserScript==

(function() {
    'use strict';
    const window = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
    window.kullanicilar = {}; window.mesajlar = []; window.ben = null; window.socket = null; window.id = null;

    GM_addStyle(`.aktif #canvas, .aktif #answer, .aktif .bar { display: none !important; } .aktif .ctt { display: flex !important; } .aktif #interaction { flex: 1 !important; margin: 0 !important; } .sohbet { padding: 5px 10px; } #chat .history .scrollElements > div.msg:not(.you):not(.system):not(.alert) { display: none !important; } .buton { background: #ffcc00; color: #001b4d; border-radius: 4px; padding: 2px 8px; font-size: 11px; cursor: pointer; margin-left: 10px; font-family: 'NunitoBlack'; text-transform: uppercase; display: inline-block; border: 1px solid #000; } .mesaj.you span { color: #4B0082 !important; } .mesaj.you strong { color: #FF0000 !important; }`);

    function print(user, text, my) {
        const hedef = document.querySelector('#chat .history .scrollElements'); if (!hedef) return;
        const satir = document.createElement('div'); satir.className = `msg mesaj ${my ? 'you' : ''}`;
        const image = user.foto ? `<div class="avatar" style="background-image: url('${user.foto}')"></div>` : `<div class="avatar"><div class="av avt${user.avatar}"></div></div>`;
        satir.innerHTML = `${image}<div><strong>${user.nick} </strong><span>${text}</span></div>`;
        hedef.appendChild(satir); satir.scrollIntoView({ block: "end" }); }

    const bridge = window.WebSocket;
    window.WebSocket = function(...args) {
        const socket = new bridge(...args); window.socket = socket;
        socket.addEventListener('message', (event) => {
            if (!event.data.startsWith('42[')) return;
            const paket = JSON.parse(event.data.slice(2));
            const sync = (user) => window.kullanicilar[user.id] = { nick: user.nick, avatar: user.avatar, foto: user.foto };

            if (paket[0] == 5) { window.ben = paket[1]; window.id = paket[2]; paket[5].forEach(sync); }
            if (paket[0] == 23) sync(paket[1]);
            
            if (paket[0] == 11) {
                const user = window.kullanicilar[paket[1]] || { nick: paket[1], avatar: 0, foto: null };
                window.mesajlar.push(`${user.nick} ${paket[2]}`); 
                print(user, paket[2], paket[1].toString() === window.ben?.toString()); } });
        return socket; };
    window.WebSocket.prototype = bridge.prototype;

    setInterval(() => {
        const chat = document.querySelector('#chat');
        if (chat && !document.querySelector('.sohbet')) {
            const sohbet = document.createElement('form'); sohbet.className = 'sohbet';
            sohbet.innerHTML = `<div class="textGame"><input type="text" class="mousetrap" placeholder="text"><span></span></div>`;
            sohbet.onsubmit = (event) => { event.preventDefault(); const input = sohbet.querySelector('input');
                if (input.value.trim() && window.socket && window.id) {
                    window.socket.send(`42["11","${window.id}","${input.value}"]`); input.value = ''; } };
            chat.appendChild(sohbet); }
        const head = document.querySelector('#chat h5');
        if (head && !document.querySelector('.buton')) {
            const buton = document.createElement('div'); buton.className = 'buton';
            buton.innerText = document.body.classList.contains('aktif') ? 'DOWN' : 'UP';
            buton.onclick = () => buton.innerText = document.body.classList.toggle('aktif') ? 'DOWN' : 'UP';
            head.appendChild(buton); } }, 1000);
})();