Auto GK equip

Envía rápidamente !gk al presionar K en HaxBall

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Auto GK equip
// @namespace    haxball-gk
// @version      3.1
// @author       MIZUELMASCAPITOFORRO/NICK HAXBALL
// @description  Envía rápidamente !gk al presionar K en HaxBall
// @match        https://www.haxball.com/*
// @grant        none
// @license      MIZUELMASCAPITOFORRO
// ==/UserScript==

(function () {
    'use strict';

    const TECLA = 'k';
    const COMANDO = '!gk';

    document.addEventListener('keydown', function (e) {

        // Solo reaccionar a K
        if (e.key.toLowerCase() !== TECLA || e.repeat) {
            return;
        }

        // Si ya estás escribiendo en un campo, no hacer nada
        const active = document.activeElement;

        if (
            active &&
            (
                active.tagName === 'INPUT' ||
                active.tagName === 'TEXTAREA' ||
                active.isContentEditable
            )
        ) {
            return;
        }

        e.preventDefault();

        // Abrir el chat
        document.dispatchEvent(new KeyboardEvent('keydown', {
            key: 'Enter',
            code: 'Enter',
            keyCode: 13,
            which: 13,
            bubbles: true
        }));

        setTimeout(() => {

            // Buscar específicamente elementos que puedan ser el chat
            const inputs = Array.from(document.querySelectorAll(
                'input, textarea, [contenteditable="true"]'
            ));

            const input = inputs.find(el => {
                const rect = el.getBoundingClientRect();
                return rect.width > 0 &&
                       rect.height > 0 &&
                       getComputedStyle(el).visibility !== 'hidden';
            });

            if (!input) {
                console.log('[Auto GK] No se encontró el chat.');
                return;
            }

            input.focus();

            // Escribir el comando
            if (input.isContentEditable) {
                input.textContent = COMANDO;
            } else {
                input.value = COMANDO;
            }

            input.dispatchEvent(new Event('input', {
                bubbles: true
            }));

            // Enviar
            setTimeout(() => {

                input.dispatchEvent(new KeyboardEvent('keydown', {
                    key: 'Enter',
                    code: 'Enter',
                    keyCode: 13,
                    which: 13,
                    bubbles: true
                }));

                input.dispatchEvent(new KeyboardEvent('keyup', {
                    key: 'Enter',
                    code: 'Enter',
                    keyCode: 13,
                    which: 13,
                    bubbles: true
                }));

            }, 5);

        }, 20);

    });

    console.log('[Auto GK] Activado - K = !gk');

})();