MineFun.io Floating Panel + Mouse Tracker

Panel bay có on/off, drag, resize, hiển thị tọa độ chuột trong MineFun.io

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MineFun.io Floating Panel + Mouse Tracker
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  Panel bay có on/off, drag, resize, hiển thị tọa độ chuột trong MineFun.io
// @author       You
// @match        https://minefun.io/*
// @match        https://*.minefun.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // ================= CẤU HÌNH =================
    const HOTKEY_TOGGLE = 'h';     // phím bật/tắt panel
    const DEFAULT_WIDTH = 220;
    const DEFAULT_HEIGHT = 140;
    const OPACITY = 0.85;
    // =============================================

    let panel = null;
    let isVisible = true;
    let isDragging = false;
    let currentX, currentY, initialX, initialY;

    function createPanel() {
        if (panel) return;

        panel = document.createElement('div');
        panel.id = 'minefun-floating-panel';
        Object.assign(panel.style, {
            position: 'fixed',
            left: '20px',
            top: '20px',
            width: DEFAULT_WIDTH + 'px',
            minWidth: '160px',
            height: DEFAULT_HEIGHT + 'px',
            background: 'rgba(30, 30, 40, ' + OPACITY + ')',
            color: '#e0e0ff',
            border: '1px solid #6a5acd',
            borderRadius: '10px',
            padding: '10px',
            fontFamily: 'Arial, sans-serif',
            fontSize: '13px',
            zIndex: '999999',
            userSelect: 'none',
            cursor: 'default',
            boxShadow: '0 4px 15px rgba(0,0,0,0.6)',
            overflow: 'hidden',
            transition: 'all 0.2s ease'
        });

        // Title bar (dùng để kéo)
        const titleBar = document.createElement('div');
        titleBar.textContent = 'MineFun Overlay';
        Object.assign(titleBar.style, {
            background: 'linear-gradient(#4a3c8c, #6a5acd)',
            padding: '6px 10px',
            margin: '-10px -10px 10px -10px',
            borderRadius: '10px 10px 0 0',
            fontWeight: 'bold',
            cursor: 'move',
            display: 'flex',
            justifyContent: 'space-between',
            alignItems: 'center'
        });

        // Nút đóng / thu nhỏ
        const btnClose = document.createElement('span');
        btnClose.textContent = '×';
        btnClose.style.cursor = 'pointer';
        btnClose.style.fontSize = '18px';
        btnClose.style.marginLeft = '10px';
        btnClose.onclick = () => { isVisible = false; panel.style.display = 'none'; };

        titleBar.appendChild(btnClose);
        panel.appendChild(titleBar);

        // Nội dung chính
        const content = document.createElement('div');
        content.id = 'panel-content';
        content.innerHTML = `
            <div><strong>Status:</strong> <span id="status">ON</span></div>
            <div><strong>Mouse X:</strong> <span id="mouseX">---</span></div>
            <div><strong>Mouse Y:</strong> <span id="mouseY">---</span></div>
            <div style="margin-top:8px;">
                <button id="btnZoomOut">-</button>
                <button id="btnZoomIn">+</button>
                <span id="zoomLevel">100%</span>
            </div>
        `;
        panel.appendChild(content);

        document.body.appendChild(panel);

        // Xử lý kéo thả
        titleBar.addEventListener('mousedown', startDragging);

        // Nút phóng to / thu nhỏ
        document.getElementById('btnZoomOut').onclick = () => zoomPanel(-20);
        document.getElementById('btnZoomIn').onclick = () => zoomPanel(20);
    }

    function startDragging(e) {
        if (e.target.tagName === 'BUTTON' || e.target.tagName === 'SPAN') return;

        initialX = e.clientX - currentX;
        initialY = e.clientY - currentY;

        isDragging = true;
        document.addEventListener('mousemove', drag);
        document.addEventListener('mouseup', stopDragging);
    }

    function drag(e) {
        if (isDragging) {
            e.preventDefault();
            currentX = e.clientX - initialX;
            currentY = e.clientY - initialY;

            panel.style.left = currentX + 'px';
            panel.style.top = currentY + 'px';
        }
    }

    function stopDragging() {
        isDragging = false;
        document.removeEventListener('mousemove', drag);
        document.removeEventListener('mouseup', stopDragging);
    }

    function zoomPanel(delta) {
        let w = parseInt(panel.style.width) || DEFAULT_WIDTH;
        w = Math.max(160, w + delta);
        panel.style.width = w + 'px';

        const percent = Math.round((w / DEFAULT_WIDTH) * 100);
        document.getElementById('zoomLevel').textContent = percent + '%';
    }

    // Theo dõi chuột trong game
    function updateMousePosition(e) {
        if (!panel || !isVisible) return;

        // Lấy canvas chính của game (thường là canvas lớn nhất)
        const canvas = document.querySelector('canvas');
        if (!canvas) return;

        const rect = canvas.getBoundingClientRect();
        const mouseX = Math.round(e.clientX - rect.left);
        const mouseY = Math.round(e.clientY - rect.top);

        document.getElementById('mouseX').textContent = mouseX;
        document.getElementById('mouseY').textContent = mouseY;
    }

    // Bật/tắt bằng phím
    document.addEventListener('keydown', e => {
        if (e.key.toLowerCase() === HOTKEY_TOGGLE) {
            e.preventDefault();
            isVisible = !isVisible;
            if (isVisible) {
                if (!panel) createPanel();
                panel.style.display = 'block';
                document.getElementById('status').textContent = 'ON';
            } else if (panel) {
                panel.style.display = 'none';
            }
        }
    });

    // Theo dõi chuột liên tục
    window.addEventListener('mousemove', updateMousePosition);

    // Tự động tạo panel khi load
    setTimeout(() => {
        createPanel();
        currentX = 20;
        currentY = 20;
    }, 3000); // chờ game load ~3 giây

    console.log("[MineFun Panel] Đã load. Nhấn " + HOTKEY_TOGGLE.toUpperCase() + " để bật/tắt");
})();