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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
    }
})();