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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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