Auto GK equip

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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');

})();