Main Menu - Auto Clicker Controller

Menu chính điều khiển auto clicker + ẩn menu bằng lệnh chat

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

Vous devrez installer une extension telle que Tampermonkey pour installer ce 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         Main Menu - Auto Clicker Controller
// @namespace    http://tampermonkey.net/
// @version      3.0
// @license      MIT
// @description  Menu chính điều khiển auto clicker + ẩn menu bằng lệnh chat
// @author       Admin
// @icon         https://i.postimg.cc/3wJFzXWv/resized-image.jpg
// @match        *://*/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_xmlhttpRequest
// @grant        GM_openInTab
// @grant        GM_deleteValue
// @grant        GM_listValues
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';
    
    if (document.querySelector('.main-menu-fab')) return;
    
    let isDragging = false;
    let dragStarted = false;
    let dragOffsetX = 0, dragOffsetY = 0;
    let loaderScriptInjected = false;
    
    // Trang thai hien/ẩn cua cac menu con
    let isAutoClickerVisible = true;
    let isSpeedHackVisible = true;
    
    // Trang thai toggle
    let toggleStates = {
        autoClicker: GM_getValue('toggle_autoClicker', false),
        speedHack: GM_getValue('toggle_speedHack', false),
        coming2: GM_getValue('toggle_coming2', false),
        coming3: GM_getValue('toggle_coming3', false)
    };
    
    // ========== CSS ==========
    GM_addStyle(`
        .main-menu-fab {
            position: fixed;
            bottom: 80px;
            right: 20px;
            width: 55px;
            height: 55px;
            border-radius: 50%;
            background: #00adb5;
            box-shadow: 0 4px 15px rgba(0,0,0,0.3);
            z-index: 999999;
            cursor: grab;
            overflow: hidden;
            border: 2px solid white;
            transition: transform 0.1s;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .main-menu-fab img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            object-fit: cover;
            pointer-events: none;
        }
        .main-menu-fab:active {
            cursor: grabbing;
            transform: scale(0.95);
        }
        .main-menu-panel {
            position: fixed;
            bottom: 150px;
            right: 20px;
            width: 280px;
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            border-radius: 16px;
            border: 1px solid #667eea;
            color: white;
            font-family: 'Segoe UI', Arial, sans-serif;
            font-size: 14px;
            z-index: 999998;
            box-shadow: 0 8px 25px rgba(0,0,0,0.5);
            display: none;
            backdrop-filter: blur(5px);
        }
        .main-menu-panel.show { display: block; }
        .main-menu-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 15px;
            background: rgba(102,126,234,0.2);
            border-bottom: 1px solid #667eea;
            border-radius: 16px 16px 0 0;
            cursor: grab;
        }
        .main-menu-header:active { cursor: grabbing; }
        .main-menu-title { font-weight: bold; color: #667eea; font-size: 14px; }
        .main-menu-close {
            background: #ff4757;
            border: none;
            color: white;
            width: 26px;
            height: 26px;
            border-radius: 50%;
            cursor: pointer;
            font-size: 14px;
        }
        .main-menu-content { padding: 12px; }
        .menu-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px;
            margin: 8px 0;
            background: #0f0f1a;
            border-radius: 10px;
        }
        .menu-item-left { display: flex; flex-direction: column; gap: 4px; }
        .menu-item-title { font-weight: bold; font-size: 14px; }
        .menu-item-desc { font-size: 11px; color: #aaa; }
        .menu-item-desc.hidden { color: #ff4757; }
        .toggle-switch {
            position: relative;
            width: 50px;
            height: 24px;
            background-color: #2d2d44;
            border-radius: 12px;
            cursor: pointer;
            transition: all 0.3s;
        }
        .toggle-switch.active { background-color: #00adb5; }
        .toggle-slider {
            position: absolute;
            top: 2px;
            left: 2px;
            width: 20px;
            height: 20px;
            background-color: white;
            border-radius: 50%;
            transition: all 0.3s;
        }
        .toggle-switch.active .toggle-slider { left: 28px; }
        .hidden-menu {
            display: none !important;
        }
        @media (max-width: 768px) {
            .main-menu-panel { width: 260px; right: 10px; bottom: 130px; }
            .main-menu-fab { bottom: 70px; right: 10px; width: 50px; height: 50px; }
        }
    `);
    
    // ========== XU LY LENH CHAT ==========
    function checkChatCommands() {
        // Tim khung chat trong game
        const chatInputs = document.querySelectorAll('input[type="text"], textarea, [contenteditable="true"]');
        
        chatInputs.forEach(input => {
            if (input._chatListenerAdded) return;
            input._chatListenerAdded = true;
            
            input.addEventListener('keypress', (e) => {
                if (e.key === 'Enter') {
                    setTimeout(() => {
                        const message = input.value || input.innerText || input.textContent;
                        if (message && message.startsWith('/')) {
                            processCommand(message);
                            // Xoa tin nhan sau khi xu ly
                            if (input.value) input.value = '';
                            if (input.innerText) input.innerText = '';
                            if (input.textContent) input.textContent = '';
                        }
                    }, 100);
                }
            });
        });
    }
    
    function processCommand(command) {
        const cmd = command.toLowerCase().trim();
        
        if (cmd === '/unauto') {
            // An menu auto clicker
            isAutoClickerVisible = false;
            const autoMenu = document.querySelector('.autoClick-fab, .autoClick-panel, .autoClick-menu');
            if (autoMenu) autoMenu.classList.add('hidden-menu');
            // An tat ca element cua auto clicker
            document.querySelectorAll('.autoClick-fab, .autoClick-panel, .autoClick-menu, .coord-preview').forEach(el => {
                el.classList.add('hidden-menu');
            });
            showNotification('🔒 Auto Clicker da duoc an!', '#ff4757');
            console.log('Auto Clicker da bi an');
        } 
        else if (cmd === '/unspeed') {
            // An menu speedhack
            isSpeedHackVisible = false;
            // Tim menu speedhack (neu co)
            const speedElements = document.querySelectorAll('[class*="speed"], [id*="speed"]');
            speedElements.forEach(el => {
                if (el.style.display !== 'none') {
                    el.classList.add('hidden-menu');
                }
            });
            showNotification('⚡ SpeedHack da duoc an!', '#ff4757');
            console.log('SpeedHack da bi an');
        }
        else if (cmd === '/showauto') {
            // Hien lai menu auto clicker
            isAutoClickerVisible = true;
            document.querySelectorAll('.autoClick-fab, .autoClick-panel, .autoClick-menu, .coord-preview').forEach(el => {
                el.classList.remove('hidden-menu');
            });
            showNotification('🔓 Auto Clicker da duoc hien lai!', '#00adb5');
        }
        else if (cmd === '/showspeed') {
            // Hien lai menu speedhack
            isSpeedHackVisible = true;
            const speedElements = document.querySelectorAll('[class*="speed"], [id*="speed"]');
            speedElements.forEach(el => {
                el.classList.remove('hidden-menu');
            });
            showNotification('⚡ SpeedHack da duoc hien lai!', '#00adb5');
        }
        else {
            // Cac lenh khac khong tac dung
            console.log('Lenh khong hop le:', cmd);
        }
    }
    
    function showNotification(message, color) {
        const noti = document.createElement('div');
        noti.textContent = message;
        noti.style.cssText = `position:fixed; bottom:20px; left:50%; transform:translateX(-50%); background:${color}; color:white; padding:8px 16px; border-radius:8px; z-index:10000000; font-size:12px; animation:fadeOut 2s ease forwards;`;
        document.body.appendChild(noti);
        setTimeout(() => noti.remove(), 2000);
    }
    
    // ========== TAO MENU ==========
    const fab = document.createElement('div');
    fab.className = 'main-menu-fab';
    
    const avatarImg = document.createElement('img');
    avatarImg.src = 'https://i.postimg.cc/3wJFzXWv/resized-image.jpg';
    avatarImg.alt = 'Menu';
    fab.appendChild(avatarImg);
    document.body.appendChild(fab);
    
    const panel = document.createElement('div');
    panel.className = 'main-menu-panel';
    panel.innerHTML = `
        <div class="main-menu-header" id="mainMenuHeader">
            <span class="main-menu-title">Control Panel</span>
            <button class="main-menu-close" id="closeMenuBtn">✖</button>
        </div>
        <div class="main-menu-content">
            <div class="menu-item">
                <div class="menu-item-left">
                    <span class="menu-item-title">🎯 Auto Clicker</span>
                    <span class="menu-item-desc" id="autoClickerDesc">Auto click theo toa do</span>
                </div>
                <div class="toggle-switch" id="toggleAutoClicker">
                    <div class="toggle-slider"></div>
                </div>
            </div>
            <div class="menu-item">
                <div class="menu-item-left">
                    <span class="menu-item-title">⚡ SpeedHack</span>
                    <span class="menu-item-desc" id="speedHackDesc">Tang toc game (Coming soon)</span>
                </div>
                <div class="toggle-switch" id="toggleSpeedHack">
                    <div class="toggle-slider"></div>
                </div>
            </div>
            <div class="menu-item">
                <div class="menu-item-left">
                    <span class="menu-item-title">📦 Tinh nang 2</span>
                    <span class="menu-item-desc">Coming soon</span>
                </div>
                <div class="toggle-switch" id="toggleComing2">
                    <div class="toggle-slider"></div>
                </div>
            </div>
            <div class="menu-item">
                <div class="menu-item-left">
                    <span class="menu-item-title">📦 Tinh nang 3</span>
                    <span class="menu-item-desc">Coming soon</span>
                </div>
                <div class="toggle-switch" id="toggleComing3">
                    <div class="toggle-slider"></div>
                </div>
            </div>
        </div>
    `;
    document.body.appendChild(panel);
    
    // ========== CAP NHAT UI ==========
    function updateToggleUI() {
        const toggleAuto = document.getElementById('toggleAutoClicker');
        const toggleSpeed = document.getElementById('toggleSpeedHack');
        const toggle2 = document.getElementById('toggleComing2');
        const toggle3 = document.getElementById('toggleComing3');
        
        if (toggleAuto) {
            if (toggleStates.autoClicker) toggleAuto.classList.add('active');
            else toggleAuto.classList.remove('active');
        }
        if (toggleSpeed) {
            if (toggleStates.speedHack) toggleSpeed.classList.add('active');
            else toggleSpeed.classList.remove('active');
        }
        if (toggle2) {
            if (toggleStates.coming2) toggle2.classList.add('active');
            else toggle2.classList.remove('active');
        }
        if (toggle3) {
            if (toggleStates.coming3) toggle3.classList.add('active');
            else toggle3.classList.remove('active');
        }
        
        // Cap nhat mo ta neu dang bi an
        const autoDesc = document.getElementById('autoClickerDesc');
        const speedDesc = document.getElementById('speedHackDesc');
        
        if (autoDesc) {
            if (!isAutoClickerVisible) {
                autoDesc.innerHTML = 'Auto click theo toa do <span style="color:#ff4757;">(ĐÃ ẨN - Gõ /showauto)</span>';
                autoDesc.style.color = '#ffa502';
            } else {
                autoDesc.innerHTML = 'Auto click theo toa do';
                autoDesc.style.color = '#aaa';
            }
        }
        
        if (speedDesc) {
            if (!isSpeedHackVisible) {
                speedDesc.innerHTML = 'Tang toc game <span style="color:#ff4757;">(ĐÃ ẨN - Gõ /showspeed)</span>';
                speedDesc.style.color = '#ffa502';
            } else {
                speedDesc.innerHTML = 'Tang toc game (Coming soon)';
                speedDesc.style.color = '#aaa';
            }
        }
    }
    
    // ========== LOAD SCRIPT GITHUB ==========
    function loadAutoClickerScript() {
        if (loaderScriptInjected) {
            console.log('Auto Clicker da duoc tai');
            return;
        }
        
        console.log('Dang tai Auto Clicker script tu GitHub...');
        
        const script = document.createElement('script');
        script.textContent = `
            (function() {
                const sourceUrl = "https://raw.githubusercontent.com/Minhbeo8/autoclickGUI/refs/heads/main/autoclick.js";
                if (window._autoClickerLoaded) return;
                window._autoClickerLoaded = true;
                
                function loadScript(url, callback) {
                    var xhr = new XMLHttpRequest();
                    xhr.open('GET', url + '?t=' + Date.now(), true);
                    xhr.onload = function() {
                        if (xhr.status === 200 && xhr.responseText) {
                            try {
                                new Function(xhr.responseText)();
                                if (callback) callback();
                            } catch(e) { console.error('Loi execute:', e); }
                        } else {
                            console.error('Khong the tai script:', xhr.status);
                        }
                    };
                    xhr.onerror = function() { console.error('Loi ket noi'); };
                    xhr.send();
                }
                
                loadScript(sourceUrl);
                console.log('Auto Clicker Loader da duoc khoi tao');
            })();
        `;
        document.head.appendChild(script);
        loaderScriptInjected = true;
        
        showNotification('Auto Clicker da duoc kich hoat!', '#00adb5');
        
        // Quet lai de tim menu va ap dung trang thai an neu can
        setTimeout(() => {
            if (!isAutoClickerVisible) {
                document.querySelectorAll('.autoClick-fab, .autoClick-panel, .autoClick-menu, .coord-preview').forEach(el => {
                    el.classList.add('hidden-menu');
                });
            }
        }, 2000);
    }
    
    // ========== UNLOAD SCRIPT ==========
    function unloadAutoClickerScript() {
        console.log('Dang tat Auto Clicker...');
        
        const elementsToRemove = [
            '.autoClick-fab',
            '.autoClick-panel',
            '.coord-preview'
        ];
        
        elementsToRemove.forEach(sel => {
            document.querySelectorAll(sel).forEach(el => el.remove());
        });
        
        document.querySelectorAll('style').forEach(style => {
            if (style.textContent.includes('autoClick-fab') || 
                style.textContent.includes('autoClick-panel') ||
                style.textContent.includes('coord-preview')) {
                if (!style.textContent.includes('main-menu')) {
                    style.remove();
                }
            }
        });
        
        delete window._autoClickerLoaded;
        delete window.autoClickerInitialized;
        
        loaderScriptInjected = false;
        showNotification('Auto Clicker da duoc tat!', '#ff4757');
    }
    
    // ========== XU LY TOGGLE ==========
    function handleToggle(item, isOn) {
        switch(item) {
            case 'autoClicker':
                if (isOn) {
                    loadAutoClickerScript();
                } else {
                    unloadAutoClickerScript();
                }
                break;
            case 'speedHack':
                if (isOn) {
                    alert('Tinh nang SpeedHack dang duoc phat trien!');
                    setTimeout(() => {
                        toggleStates.speedHack = false;
                        GM_setValue('toggle_speedHack', false);
                        updateToggleUI();
                    }, 100);
                }
                break;
            case 'coming2':
            case 'coming3':
                if (isOn) {
                    alert('Tinh nang dang duoc phat trien! Coming soon.');
                    setTimeout(() => {
                        if (item === 'coming2') toggleStates.coming2 = false;
                        if (item === 'coming3') toggleStates.coming3 = false;
                        GM_setValue(`toggle_${item}`, false);
                        updateToggleUI();
                    }, 100);
                }
                break;
        }
    }
    
    // ========== KEO THA FAB ==========
    fab.addEventListener('mousedown', (e) => {
        if (e.target === fab || fab.contains(e.target)) {
            isDragging = true;
            dragStarted = false;
            dragOffsetX = e.clientX - fab.offsetLeft;
            dragOffsetY = e.clientY - fab.offsetTop;
            fab.style.cursor = 'grabbing';
            fab.style.transition = 'none';
            e.preventDefault();
            e.stopPropagation();
        }
    });
    
    fab.addEventListener('touchstart', (e) => {
        const touch = e.touches[0];
        isDragging = true;
        dragStarted = false;
        dragOffsetX = touch.clientX - fab.offsetLeft;
        dragOffsetY = touch.clientY - fab.offsetTop;
        fab.style.cursor = 'grabbing';
        fab.style.transition = 'none';
        e.preventDefault();
        e.stopPropagation();
    });
    
    window.addEventListener('mousemove', (e) => {
        if (isDragging) {
            dragStarted = true;
            let left = e.clientX - dragOffsetX;
            let top = e.clientY - dragOffsetY;
            left = Math.max(0, Math.min(window.innerWidth - fab.offsetWidth, left));
            top = Math.max(0, Math.min(window.innerHeight - fab.offsetHeight, top));
            fab.style.left = left + 'px';
            fab.style.top = top + 'px';
            fab.style.right = 'auto';
            fab.style.bottom = 'auto';
        }
    });
    
    window.addEventListener('touchmove', (e) => {
        if (isDragging) {
            dragStarted = true;
            const touch = e.touches[0];
            let left = touch.clientX - dragOffsetX;
            let top = touch.clientY - dragOffsetY;
            left = Math.max(0, Math.min(window.innerWidth - fab.offsetWidth, left));
            top = Math.max(0, Math.min(window.innerHeight - fab.offsetHeight, top));
            fab.style.left = left + 'px';
            fab.style.top = top + 'px';
            fab.style.right = 'auto';
            fab.style.bottom = 'auto';
            e.preventDefault();
        }
    });
    
    window.addEventListener('mouseup', () => {
        if (isDragging) {
            isDragging = false;
            fab.style.cursor = 'grab';
            fab.style.transition = '';
            setTimeout(() => {
                if (!dragStarted) {
                    panel.classList.toggle('show');
                }
                dragStarted = false;
            }, 10);
        }
    });
    
    window.addEventListener('touchend', () => {
        if (isDragging) {
            isDragging = false;
            fab.style.cursor = 'grab';
            fab.style.transition = '';
            setTimeout(() => {
                if (!dragStarted) {
                    panel.classList.toggle('show');
                }
                dragStarted = false;
            }, 10);
        }
    });
    
    // ========== KEO THA PANEL ==========
    let panelDragging = false;
    let panelOffsetX, panelOffsetY;
    const panelHeader = document.getElementById('mainMenuHeader');
    
    panelHeader.addEventListener('mousedown', (e) => {
        if (e.target === panelHeader || e.target.classList.contains('main-menu-title')) {
            panelDragging = true;
            panelOffsetX = e.clientX - panel.offsetLeft;
            panelOffsetY = e.clientY - panel.offsetTop;
            panel.style.cursor = 'grabbing';
            e.preventDefault();
        }
    });
    
    panelHeader.addEventListener('touchstart', (e) => {
        const touch = e.touches[0];
        panelDragging = true;
        panelOffsetX = touch.clientX - panel.offsetLeft;
        panelOffsetY = touch.clientY - panel.offsetTop;
        e.preventDefault();
    });
    
    window.addEventListener('mousemove', (e) => {
        if (panelDragging) {
            let left = e.clientX - panelOffsetX;
            let top = e.clientY - panelOffsetY;
            left = Math.min(window.innerWidth - panel.offsetWidth, Math.max(0, left));
            top = Math.min(window.innerHeight - panel.offsetHeight, Math.max(0, top));
            panel.style.left = left + 'px';
            panel.style.top = top + 'px';
            panel.style.right = 'auto';
            panel.style.bottom = 'auto';
        }
    });
    
    window.addEventListener('touchmove', (e) => {
        if (panelDragging) {
            const touch = e.touches[0];
            let left = touch.clientX - panelOffsetX;
            let top = touch.clientY - panelOffsetY;
            left = Math.min(window.innerWidth - panel.offsetWidth, Math.max(0, left));
            top = Math.min(window.innerHeight - panel.offsetHeight, Math.max(0, top));
            panel.style.left = left + 'px';
            panel.style.top = top + 'px';
            panel.style.right = 'auto';
            panel.style.bottom = 'auto';
            e.preventDefault();
        }
    });
    
    window.addEventListener('mouseup', () => { panelDragging = false; panel.style.cursor = 'default'; });
    window.addEventListener('touchend', () => { panelDragging = false; });
    
    // ========== DONG PANEL ==========
    document.getElementById('closeMenuBtn').addEventListener('click', () => {
        panel.classList.remove('show');
    });
    
    // ========== TOGGLE EVENTS ==========
    document.getElementById('toggleAutoClicker').addEventListener('click', (e) => {
        e.stopPropagation();
        toggleStates.autoClicker = !toggleStates.autoClicker;
        GM_setValue('toggle_autoClicker', toggleStates.autoClicker);
        updateToggleUI();
        handleToggle('autoClicker', toggleStates.autoClicker);
    });
    
    document.getElementById('toggleSpeedHack').addEventListener('click', (e) => {
        e.stopPropagation();
        toggleStates.speedHack = !toggleStates.speedHack;
        GM_setValue('toggle_speedHack', toggleStates.speedHack);
        updateToggleUI();
        handleToggle('speedHack', toggleStates.speedHack);
    });
    
    document.getElementById('toggleComing2').addEventListener('click', (e) => {
        e.stopPropagation();
        toggleStates.coming2 = !toggleStates.coming2;
        GM_setValue('toggle_coming2', toggleStates.coming2);
        updateToggleUI();
        handleToggle('coming2', toggleStates.coming2);
    });
    
    document.getElementById('toggleComing3').addEventListener('click', (e) => {
        e.stopPropagation();
        toggleStates.coming3 = !toggleStates.coming3;
        GM_setValue('toggle_coming3', toggleStates.coming3);
        updateToggleUI();
        handleToggle('coming3', toggleStates.coming3);
    });
    
    // ========== THEM LISTENER CHO CHAT ==========
    setInterval(checkChatCommands, 2000);
    
    // ========== KHOI TAO ==========
    updateToggleUI();
    
    if (toggleStates.autoClicker) {
        setTimeout(() => loadAutoClickerScript(), 1000);
    }
    
    console.log('Main menu da san sang!');
    console.log('Lenh hop le:');
    console.log('  /unauto  - An menu Auto Clicker');
    console.log('  /unspeed - An menu SpeedHack');
    console.log('  /showauto - Hien lai menu Auto Clicker');
    console.log('  /showspeed - Hien lai menu SpeedHack');
})();