☰

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)

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴、Greasemonkey 油猴子 或 Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴 或 暴力猴 才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴 或 Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴 或 Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

})();