☰

Minefun.io Ore & Cave Helper (Wireframe + Toggle)

Toggle wireframe + cố gắng làm nổi bật quặng/hang (không phải Xray thật)

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu betiği yüklemek için bir betik yöneticisi eklentisi yüklemeniz gerekecektir.

(Zaten bir betik yöneticim var, hadi yükleyelim!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Minefun.io Ore & Cave Helper (Wireframe + Toggle)
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Toggle wireframe + cố gắng làm nổi bật quặng/hang (không phải Xray thật)
// @author       You
// @match        https://minefun.io/*
// @match        https://*.minefun.io/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    let enabled = false;
    let originalMaterials = new Map();

    // Tạo nút toggle
    function createToggleButton() {
        const btn = document.createElement('button');
        btn.innerText = 'X-Ray: OFF';
        btn.style.position = 'fixed';
        btn.style.top = '10px';
        btn.style.right = '10px';
        btn.style.zIndex = '9999';
        btn.style.padding = '8px 12px';
        btn.style.background = '#333';
        btn.style.color = 'white';
        btn.style.border = '2px solid #0f0';
        btn.style.cursor = 'pointer';
        btn.style.fontSize = '14px';
        document.body.appendChild(btn);

        btn.addEventListener('click', () => {
            enabled = !enabled;
            btn.innerText = `X-Ray: ${enabled ? 'ON' : 'OFF'}`;
            btn.style.borderColor = enabled ? '#f00' : '#0f0';
            toggleXRay();
        });
    }

    function toggleXRay() {
        if (!window.THREE || !renderer) {
            console.log("[Minefun Helper] Chưa tìm thấy THREE.js hoặc renderer");
            return;
        }

        const scene = renderer.scene; // có thể khác tùy phiên bản game

        if (!scene) return;

        if (enabled) {
            // Bật wireframe + thử highlight quặng
            scene.traverse((obj) => {
                if (obj.isMesh && obj.material) {
                    if (!originalMaterials.has(obj)) {
                        originalMaterials.set(obj, obj.material.clone());
                    }

                    // Wireframe cho mọi thứ
                    obj.material.wireframe = true;
                    obj.material.wireframeLinewidth = 2.5;

                    // Thử đoán quặng bằng màu (rất không chính xác)
                    const color = obj.material.color?.getHexString?.();
                    if (color) {
                        if (color.includes('e5d') || color.includes('ff0') || color.includes('ffd700')) { // vàng, kim cương...
                            obj.material.emissive?.set(0xffff00);
                            obj.material.emissiveIntensity = 1.2;
                        }
                        if (color.includes('00f') || color.includes('4169e1')) { // lapis, nước...
                            obj.material.transparent = true;
                            obj.material.opacity = 0.3;
                        }
                    }
                }
            });
            console.log("[XRay] Bật – wireframe + highlight thử nghiệm");
        } else {
            // Tắt → khôi phục
            originalMaterials.forEach((mat, mesh) => {
                if (mesh.material) {
                    mesh.material.dispose?.();
                    mesh.material = mat;
                }
            });
            originalMaterials.clear();
            console.log("[XRay] Tắt");
        }

        // Buộc render lại (nếu game không tự update)
        if (renderer && renderer.render) renderer.render(scene, camera);
    }

    // Chờ game load THREE.js
    const waitInterval = setInterval(() => {
        if (window.THREE && document.querySelector('canvas')) {
            clearInterval(waitInterval);
            createToggleButton();
            console.log("[Minefun Helper] Đã sẵn sàng toggle wireframe");
        }
    }, 800);

    // Phím tắt (ấn phím X để bật/tắt)
    window.addEventListener('keydown', e => {
        if (e.key.toLowerCase() === 'x') {
            enabled = !enabled;
            toggleXRay();
            const btn = document.querySelector('button[innerText*="X-Ray"]');
            if (btn) {
                btn.innerText = `X-Ray: ${enabled ? 'ON' : 'OFF'}`;
                btn.style.borderColor = enabled ? '#f00' : '#0f0';
            }
        }
    });

})();