Auto GK equip

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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');

})();