Predator Stack

Customizable predator Stack Keys. With a beautiful Menu.

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

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

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name         Predator Stack
// @license      MIT
// @namespace    http://tampermonkey.net/
// @version      2.6
// @description  Customizable predator Stack Keys. With a beautiful Menu.
// @author       Voyager
// @match        *://diep.io/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    let stackKey5 = GM_getValue('stackKey5', 'b'); // Reload 5
    let stackKey6 = GM_getValue('stackKey6', 'g'); // Reload 6
    let stackKey7 = GM_getValue('stackKey7', 'v'); // Reload 7
    let toggleKey = GM_getValue('toggleKey', 'i'); // Menu toggle

    let menuX = GM_getValue('menuX', '20px');
    let menuY = GM_getValue('menuY', '20px');

    let yaInstalado = GM_getValue('yaInstalado', false);
    let menuVisible = !yaInstalado;
    let activeBindingInput = null;

    if (!yaInstalado) {
        GM_setValue('yaInstalado', true);
    }

    const style = document.createElement('style');
    style.textContent = `
        #predator-menu {
            position: fixed;
            top: ${menuY};
            left: ${menuX};
            background: rgba(17, 17, 17, 0.95);
            border: 2px solid #00b2e1;
            border-radius: 8px;
            padding: 15px;
            color: white;
            font-family: 'Ubuntu', sans-serif;
            z-index: 999999;
            box-shadow: 0 4px 20px rgba(0,0,0,0.7);
            width: 230px;
            display: ${menuVisible ? 'block' : 'none'};
            user-select: none;
        }
        #predator-menu-header {
            margin: -15px -15px 10px -15px;
            padding: 10px;
            background: rgba(0, 178, 225, 0.15);
            border-bottom: 1px solid #00b2e1;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            cursor: move;
        }
        #predator-menu-header h3 {
            margin: 0;
            font-size: 14px;
            text-align: center;
            color: #00b2e1;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        .menu-welcome {
            font-size: 11px;
            color: #aaa;
            text-align: center;
            margin-bottom: 12px;
            line-height: 14px;
        }
        .menu-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
            font-size: 12px;
        }
        .menu-row.separador {
            border-top: 1px solid #333;
            padding-top: 10px;
            margin-top: 5px;
        }
        .menu-btn {
            width: 55px;
            background: #222;
            border: 1px solid #555;
            color: #fff;
            text-align: center;
            padding: 4px;
            border-radius: 4px;
            text-transform: uppercase;
            font-weight: bold;
            cursor: pointer;
            font-size: 11px;
            transition: background 0.2s, border-color 0.2s;
        }
        .menu-btn:hover {
            border-color: #00b2e1;
            background: #2a2a2a;
        }
        .menu-btn.listening {
            border-color: #ffb86c !important;
            color: #ffb86c;
            background: #33251a;
        }
    `;
    document.head.appendChild(style);

    const menuContainer = document.createElement('div');
    menuContainer.id = "predator-menu";
    menuContainer.innerHTML = `
        <div id="predator-menu-header">
            <h3>Predator Stack</h3>
        </div>
        <div class="menu-welcome">Click any box and press a key to bind it</div>

        <div class="menu-row">
            <span>Stack 1 (Reload 5):</span>
            <div id="btn-key5" class="menu-btn">${stackKey5.toUpperCase()}</div>
        </div>
        <div class="menu-row">
            <span>Stack 2 (Reload 6):</span>
            <div id="btn-key6" class="menu-btn">${stackKey6.toUpperCase()}</div>
        </div>
        <div class="menu-row">
            <span>Stack 3 (Reload 7):</span>
            <div id="btn-key7" class="menu-btn">${stackKey7.toUpperCase()}</div>
        </div>
        <div class="menu-row separador">
            <span style="color: #ffb86c;">Show/Hide Menu:</span>
            <div id="btn-toggle" class="menu-btn" style="border-color: #ffb86c; color: #ffb86c;">${toggleKey.toUpperCase()}</div>
        </div>
    `;
    document.body.appendChild(menuContainer);

    const btnKey5 = document.getElementById('btn-key5');
    const btnKey6 = document.getElementById('btn-key6');
    const btnKey7 = document.getElementById('btn-key7');
    const btnToggle = document.getElementById('btn-toggle');
    const menuDiv = document.getElementById('predator-menu');
    const menuHeader = document.getElementById('predator-menu-header');

    function getKeyValueByButton(element) {
        if (element === btnKey5) return stackKey5;
        if (element === btnKey6) return stackKey6;
        if (element === btnKey7) return stackKey7;
        if (element === btnToggle) return toggleKey;
        return '';
    }

    const setupRebind = (element) => {
        element.addEventListener('click', () => {
            if (activeBindingInput === element) {
                element.classList.remove('listening');
                element.textContent = getKeyValueByButton(element).toUpperCase();
                activeBindingInput = null;
                return;
            }
            if (activeBindingInput) {
                activeBindingInput.classList.remove('listening');
                activeBindingInput.textContent = getKeyValueByButton(activeBindingInput).toUpperCase();
            }
            activeBindingInput = element;
            element.classList.add('listening');
            element.textContent = '...';
        });
    };

    setupRebind(btnKey5);
    setupRebind(btnKey6);
    setupRebind(btnKey7);
    setupRebind(btnToggle);

    window.addEventListener('keydown', (e) => {
        const pressedKey = e.key.toLowerCase();

        if (activeBindingInput) {
            e.preventDefault();
            e.stopPropagation();

            if (pressedKey === 'escape') {
                activeBindingInput.classList.remove('listening');
                btnKey5.textContent = stackKey5.toUpperCase();
                btnKey6.textContent = stackKey6.toUpperCase();
                btnKey7.textContent = stackKey7.toUpperCase();
                btnToggle.textContent = toggleKey.toUpperCase();
                activeBindingInput = null;
                return;
            }

            if (activeBindingInput === btnKey5) { stackKey5 = pressedKey; GM_setValue('stackKey5', pressedKey); btnKey5.textContent = pressedKey.toUpperCase(); }
            if (activeBindingInput === btnKey6) { stackKey6 = pressedKey; GM_setValue('stackKey6', pressedKey); btnKey6.textContent = pressedKey.toUpperCase(); }
            if (activeBindingInput === btnKey7) { stackKey7 = pressedKey; GM_setValue('stackKey7', pressedKey); btnKey7.textContent = pressedKey.toUpperCase(); }
            if (activeBindingInput === btnToggle) {
                toggleKey = pressedKey;
                GM_setValue('toggleKey', pressedKey);
                btnToggle.textContent = pressedKey.toUpperCase();
            }

            activeBindingInput.classList.remove('listening');
            activeBindingInput = null;
            actualizarScriptInyectado();
            return;
        }

        if (pressedKey === toggleKey) {
            menuVisible = !menuVisible;
            menuDiv.style.display = menuVisible ? 'block' : 'none';
        }
    }, true);

    let isDragging = false;
    let offsetX, offsetY;

    menuHeader.addEventListener('mousedown', (e) => {
        if (activeBindingInput) return;
        isDragging = true;
        offsetX = e.clientX - menuDiv.offsetLeft;
        offsetY = e.clientY - menuDiv.offsetTop;
    });

    document.addEventListener('mousemove', (e) => {
        if (!isDragging) return;
        let x = e.clientX - offsetX;
        let y = e.clientY - offsetY;
        menuDiv.style.left = `${x}px`;
        menuDiv.style.top = `${y}px`;
    });

    document.addEventListener('mouseup', () => {
        if (isDragging) {
            isDragging = false;
            GM_setValue('menuX', menuDiv.style.left);
            GM_setValue('menuY', menuDiv.style.top);
        }
    });

    let injectedScript = null;

    function actualizarScriptInyectado() {
        if (injectedScript) injectedScript.remove();

        injectedScript = document.createElement('script');
        injectedScript.textContent = `
            (function() {
                const key5 = "${stackKey5}";
                const key6 = "${stackKey6}";
                const key7 = "${stackKey7}";
                const menuToggle = "${toggleKey}";

                function simulateKey(code, keyChar, keyCode, type) {
                    const event = new KeyboardEvent(type, {
                        key: keyChar,
                        code: code,
                        keyCode: keyCode,
                        which: keyCode,
                        bubbles: true,
                        cancelable: true,
                        composed: true
                    });

                    window.dispatchEvent(event);
                    document.dispatchEvent(event);
                    const canvas = document.querySelector('canvas');
                    if (canvas) canvas.dispatchEvent(event);
                }

                function shoot(duration) {
                    simulateKey("Space", " ", 32, "keydown");
                    setTimeout(() => {
                        simulateKey("Space", " ", 32, "keyup");
                    }, duration);
                }

                function executeStack(t1, t2, t3) {
                    shoot(t1);
                    setTimeout(() => shoot(300), t2);
                    setTimeout(() => {
                        simulateKey("KeyE", "e", 69, "keydown");
                        setTimeout(() => simulateKey("KeyE", "e", 69, "keyup"), 50);
                    }, t3);
                }

                if (window.predatorHandler) {
                    window.removeEventListener('keydown', window.predatorHandler, true);
                }

                window.predatorHandler = function(e) {
                    if (e.repeat || e.key.toLowerCase() === menuToggle) return;

                    if (document.activeElement && (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA')) return;

                    const key = e.key.toLowerCase();

                    if (key === key5) executeStack(50, 900, 1800);  // Reload 5
                    if (key === key6) executeStack(50, 825, 1700);  // Reload 6
                    if (key === key7) executeStack(50, 750, 1500);  // Reload 7
                };

                window.addEventListener('keydown', window.predatorHandler, true);
            })();
        `;
        (document.head || document.documentElement).appendChild(injectedScript);
    }

    actualizarScriptInyectado();

})();