Greasy Fork

Greasy Fork is available in English.

Gartic chat - FIXED

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 http://greasyfork.icu/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);
})();