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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

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

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

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