Minefun Safe Easy-Scaffold

Hỗ trợ đặt block dễ dàng bằng giả lập thao tác chuột an toàn, không can thiệp code game

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Minefun Safe Easy-Scaffold
// @namespace    http://tampermonkey.net/
// @version      3.0
// @description  Hỗ trợ đặt block dễ dàng bằng giả lập thao tác chuột an toàn, không can thiệp code game
// @match        https://minefun.io/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // CẤU HÌNH ĐƠN GIẢN
    const CONFIG = {
        toggleKey: 'KeyB',       // Bấm B để Bật/Tắt chế độ hỗ trợ đặt block
        placeInterval: 50,       // Khoảng cách giữa các lần đặt block (ms) - 50ms là vừa mượt vừa an toàn
        autoSelectSlot: true,    // Tự đổi sang ô Hotbar số 1 khi bật
        slotNumber: '1'          // Ô chứa block trên hotbar
    };

    let isEnabled = false;
    let placeTimer = null;

    // Giả lập thao tác cuộn hoặc bấm phím chọn Hotbar
    function selectSlot() {
        if (!CONFIG.autoSelectSlot) return;
        
        const eventDown = new KeyboardEvent('keydown', {
            key: CONFIG.slotNumber,
            code: `Digit${CONFIG.slotNumber}`,
            bubbles: true
        });
        const eventUp = new KeyboardEvent('keyup', {
            key: CONFIG.slotNumber,
            code: `Digit${CONFIG.slotNumber}`,
            bubbles: true
        });

        window.dispatchEvent(eventDown);
        window.dispatchEvent(eventUp);
    }

    // Thao tác click chuột phải mượt mà trên Canvas game
    function doRightClick() {
        const canvas = document.querySelector('canvas') || document.body;
        const rect = canvas.getBoundingClientRect();
        const x = rect.left + rect.width / 2;
        const y = rect.top + rect.height / 2;

        const mouseDown = new MouseEvent('mousedown', {
            button: 2,
            buttons: 2,
            clientX: x,
            clientY: y,
            bubbles: true
        });

        const mouseUp = new MouseEvent('mouseup', {
            button: 2,
            buttons: 0,
            clientX: x,
            clientY: y,
            bubbles: true
        });

        canvas.dispatchEvent(mouseDown);
        setTimeout(() => canvas.dispatchEvent(mouseUp), 10);
    }

    // Quản lý trạng thái Bật / Tắt
    function toggleScaffold() {
        isEnabled = !isEnabled;

        if (isEnabled) {
            selectSlot();
            placeTimer = setInterval(doRightClick, CONFIG.placeInterval);
            showNotification('Hỗ trợ đặt block: ĐÃ BẬT (Bấm B để tắt)');
        } else {
            if (placeTimer) clearInterval(placeTimer);
            showNotification('Hỗ trợ đặt block: ĐÃ TẮT');
        }
    }

    // Lắng nghe phím bật/tắt
    window.addEventListener('keydown', (e) => {
        // Chỉ nhận khi không gõ vào ô chat
        if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') return;

        if (e.code === CONFIG.toggleKey) {
            toggleScaffold();
        }
    });

    // Tắt menu chuột phải mặc định của trình duyệt để không bị vướng
    window.addEventListener('contextmenu', (e) => {
        if (isEnabled) e.preventDefault();
    });

    // Thông báo nhỏ góc màn hình
    function showNotification(text) {
        let el = document.getElementById('safe-scaffold-notif');
        if (!el) {
            el = document.createElement('div');
            el.id = 'safe-scaffold-notif';
            el.style.position = 'fixed';
            el.style.bottom = '20px';
            el.style.right = '20px';
            el.style.padding = '8px 15px';
            el.style.background = 'rgba(0,0,0,0.7)';
            el.style.color = '#FFF';
            el.style.borderRadius = '5px';
            el.style.fontFamily = 'sans-serif';
            el.style.fontSize = '13px';
            el.style.zIndex = '999999';
            el.style.transition = 'all 0.3s';
            document.body.appendChild(el);
        }
        el.innerText = text;
        el.style.opacity = '1';
        setTimeout(() => { el.style.opacity = '0.5'; }, 2000);
    }
})();