craft quick (smart right click)

Trong UI: Giữ Chuột Phải vào nút Chế tạo để chế đồ nhanh, Chuột Trái lấy đồ bình thường. Trong Game: Bắn tự động và nhắm bình thường.

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         craft quick (smart right click)
// @namespace    http://tampermonkey.net/
// @version      6.0
// @description  Trong UI: Giữ Chuột Phải vào nút Chế tạo để chế đồ nhanh, Chuột Trái lấy đồ bình thường. Trong Game: Bắn tự động và nhắm bình thường.
// @author       Gemini
// @match        *://minefun.io/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let mouseX = 0;
    let mouseY = 0;
    let clickInterval = null;
    
    // Tốc độ click: 40ms = 25 click/giây
    const CLICK_SPEED = 40;

    // Liên tục cập nhật tọa độ chuột khi đang ở trong Menu
    window.addEventListener('mousemove', (e) => {
        if(e.isTrusted) {
            mouseX = e.clientX;
            mouseY = e.clientY;
        }
    });

    // KHI BẤM CHUỘT XUỐNG
    window.addEventListener('mousedown', (e) => {
        // NẾU ĐANG TRONG TRẬN (Chuột bị ẩn): Bỏ qua hoàn toàn, nhường quyền cho game để bắn/nhắm.
        if (document.pointerLockElement) {
            return;
        }

        // CHỈ KÍCH HOẠT KHI GIỮ CHUỘT PHẢI (button === 2) TRONG MENU
        if (e.button === 2 && e.isTrusted && !clickInterval) {
            const element = document.elementFromPoint(mouseX, mouseY);
            
            // Nếu click nhầm ra ngoài nền 3D thì bỏ qua
            if (element && element.tagName.toLowerCase() === 'canvas') {
                return;
            }
            
            // Bắt đầu chế độ Auto-Click (Nhấp chuột trái liên tục vào vị trí đang chỉ)
            clickInterval = setInterval(() => {
                const currentElement = document.elementFromPoint(mouseX, mouseY);
                
                if (currentElement && currentElement.tagName.toLowerCase() !== 'canvas') {
                    // Giả lập phím bấm Chuột Trái (button: 0) để chế đồ
                    const mouseDown = new MouseEvent('mousedown', { bubbles: true, cancelable: true, view: window, button: 0 });
                    const mouseUp = new MouseEvent('mouseup', { bubbles: true, cancelable: true, view: window, button: 0 });
                    const clickEvent = new MouseEvent('click', { bubbles: true, cancelable: true, view: window, button: 0 });
                    
                    currentElement.dispatchEvent(mouseDown);
                    currentElement.dispatchEvent(mouseUp);
                    currentElement.dispatchEvent(clickEvent);
                }
            }, CLICK_SPEED);
        }
    });

    // KHI NHẢ CHUỘT PHẢI RA
    window.addEventListener('mouseup', (e) => {
        if (e.button === 2 && e.isTrusted && clickInterval) {
            clearInterval(clickInterval);
            clickInterval = null;
        }
    });

    // Chặn menu chuột phải của trình duyệt khi ở trong túi đồ để không bị hiện menu rác che màn hình
    window.addEventListener('contextmenu', (e) => {
        if (!document.pointerLockElement) {
            e.preventDefault();
        }
    });

    // Tự động dừng nếu bạn tab ra ngoài màn hình
    window.addEventListener('blur', () => {
        if (clickInterval) {
            clearInterval(clickInterval);
            clickInterval = null;
        }
    });
})();