Drawaria Draggable Menu

Menu funcional con caché de imagen para un menú de Drawaria.

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Drawaria Draggable Menu
// @namespace    http://tampermonkey.net/
// @version      1.01
// @description  Menu funcional con caché de imagen para un menú de Drawaria.
// @author       YouTubeDrawaria
// @match        https://drawaria.online/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=drawaria.online
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let lastUsedUrl = "https://drawaria.online/avatar/cache/81b01610-02d0-11f1-afef-4fc74305da51.1770323084729.jpg";
    let imageInterval = null;

    // --- LÓGICA DE CAPTURA DE SOCKET (CORREGIDA) ---
    // En lugar de un array que crece, nos aseguramos de que window.sockets[0] sea siempre el socket actual
    if (!window.sockets) { window.sockets = []; }
    const originalSend = WebSocket.prototype.send;
    WebSocket.prototype.send = function(...args) {
        // Cada vez que el juego envía algo, actualizamos la referencia al socket activo
        window.sockets[0] = this;
        return originalSend.apply(this, args);
    };

    // --- FUNCIÓN DE ENVÍO ESTILO PANTHER ---
    function sendSocketRaw(message) {
        if (window.sockets[0] && window.sockets[0].readyState === WebSocket.OPEN) {
            window.sockets[0].send(message);
        } else {
            console.error('WebSocket no disponible o cerrado.');
        }
    }

    // --- ACCIÓN DE PASTE (LÓGICA DINÁMICA) ---
    function handlePasteAction() {
        const userUrl = prompt("Pega la URL de la imagen:", lastUsedUrl);
        if (userUrl && userUrl.trim() !== "") {
            lastUsedUrl = userUrl.trim();
            // Formato exacto que Panther recomendó: 42["clientnotify", -1, 10002, ["URL"]]
            const msg = `42["clientnotify",-1,10002,["${lastUsedUrl}"]]`;
            sendSocketRaw(msg);
            console.log("Imagen enviada con éxito.");
        }
    }

    // --- ACCIÓN DE TOGGLE (POR SI NECESITAS QUE PERSISTA) ---
    function toggleImagePersistence() {
        if (imageInterval) {
            clearInterval(imageInterval);
            imageInterval = null;
            alert("Auto-Paste detenido.");
        } else {
            const userUrl = prompt("URL para mantener activa:", lastUsedUrl);
            if (userUrl) {
                lastUsedUrl = userUrl;
                imageInterval = setInterval(() => {
                    const msg = `42["clientnotify",-1,10002,["${lastUsedUrl}"]]`;
                    sendSocketRaw(msg);
                }, 2000); // Se envía cada 2 segundos para no saturar pero mantenerla visible
                alert("Auto-Paste iniciado (cada 2 seg).");
            }
        }
    }

    // --- ESTILOS Y UI (Mantenidos según tu preferencia) ---
    function addStyles() {
        const style = document.createElement('style');
        style.innerHTML = `
            .action-menu {
                position: absolute;
                top: 220px;
                left: 20px;
                display: flex;
                flex-direction: column;
                background: linear-gradient(135deg, #8e2de2, #4a00e0);
                border-radius: 10px;
                padding: 15px;
                z-index: 10000;
                box-shadow: 0 4px 15px rgba(0,0,0,0.4);
            }
            .action-button {
                margin: 5px;
                padding: 12px;
                cursor: pointer;
                background: linear-gradient(135deg, #ffd700, #ffb90f);
                color: #000;
                border: 2px solid;
                border-top-color: #b8860b;
                border-right-color: #b8860b;
                border-bottom-color: #ffffff;
                border-left-color: #ffffff;
                border-radius: 5px;
                font-weight: bold;
                min-width: 170px;
                transition: transform 0.1s;
            }
            .action-button:active { transform: scale(0.95); }
            .draggable { cursor: move; }
        `;
        document.head.appendChild(style);
    }

    function createMenu() {
        const menu = document.createElement('div');
        menu.className = 'action-menu draggable';

        const btnPaste = document.createElement('button');
        btnPaste.className = 'action-button';
        btnPaste.textContent = 'Paste Image (URL)';
        btnPaste.onclick = handlePasteAction;

        const btnToggle = document.createElement('button');
        btnToggle.className = 'action-button';
        btnToggle.textContent = 'Toggle Persistence';
        btnToggle.onclick = toggleImagePersistence;

        const btnRules = document.createElement('button');
        btnRules.className = 'action-button';
        btnRules.textContent = 'Send Rules';
        btnRules.onclick = () => sendSocketRaw('42["clientnotify",-1,100,[2]]');

        menu.appendChild(btnPaste);
        menu.appendChild(btnToggle);
        menu.appendChild(btnRules);

        document.body.appendChild(menu);
        makeDraggable(menu);
    }

    function makeDraggable(el) {
        let ox, oy, dragging = false;
        el.onmousedown = (e) => {
            if(e.target === el) {
                dragging = true;
                ox = e.clientX - el.offsetLeft;
                oy = e.clientY - el.offsetTop;
                el.style.userSelect = 'none';
            }
        };
        document.onmousemove = (e) => {
            if(dragging) {
                el.style.left = (e.clientX - ox) + 'px';
                el.style.top = (e.clientY - oy) + 'px';
            }
        };
        document.onmouseup = () => dragging = false;
    }

    addStyles();
    setTimeout(createMenu, 1500);
})();