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와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 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);
    }
})();