Minefun Ultimate FPS Boost & Tracker

Hiển thị FPS, nút bật tắt Boost siêu mượt, ép xung WebGL cho Minefun.io

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Minefun Ultimate FPS Boost & Tracker
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Hiển thị FPS, nút bật tắt Boost siêu mượt, ép xung WebGL cho Minefun.io
// @author       You
// @match        *://minefun.io/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // --- 1. ÉP XUNG WEBGL TỪ LÕI (Chạy ngay khi load trang) ---
    const originalGetContext = HTMLCanvasElement.prototype.getContext;
    HTMLCanvasElement.prototype.getContext = function(type, options) {
        if (type === 'webgl' || type === 'webgl2') {
            options = options || {};
            options.antialias = false; // Tắt khử răng cưa (Giảm lag cực mạnh)
            options.preserveDrawingBuffer = false;
            options.powerPreference = "high-performance"; // Ép card đồ họa chạy tối đa
            options.desynchronized = true; // Giảm độ trễ chuyển động
            options.alpha = false; 
        }
        return originalContext = originalGetContext.call(this, type, options);
    };

    let isBoosted = false;
    let currentFps = 0;
    const originalPixelRatio = window.devicePixelRatio;

    // --- 2. TẠO GIAO DIỆN NÚT BẬT/TẮT VÀ HIỂN THỊ FPS ---
    window.addEventListener('DOMContentLoaded', () => {
        const uiContainer = document.createElement('div');
        uiContainer.style.position = 'fixed';
        uiContainer.style.top = '10px';
        uiContainer.style.left = '10px';
        uiContainer.style.zIndex = '999999';
        uiContainer.style.display = 'flex';
        uiContainer.style.gap = '10px';
        uiContainer.style.alignItems = 'center';
        uiContainer.style.fontFamily = 'Arial, sans-serif';

        // Bảng FPS
        const fpsDisplay = document.createElement('div');
        fpsDisplay.style.background = 'rgba(0, 0, 0, 0.7)';
        fpsDisplay.style.color = '#00FF00'; // Màu xanh lá mượt mà
        fpsDisplay.style.padding = '5px 10px';
        fpsDisplay.style.borderRadius = '5px';
        fpsDisplay.style.fontWeight = 'bold';
        fpsDisplay.style.fontSize = '16px';
        fpsDisplay.innerText = 'FPS: 0';

        // Nút Boost
        const boostBtn = document.createElement('button');
        boostBtn.innerText = 'BẬT BOOST (OFF)';
        boostBtn.style.background = '#ff4757';
        boostBtn.style.color = 'white';
        boostBtn.style.border = 'none';
        boostBtn.style.padding = '5px 10px';
        boostBtn.style.borderRadius = '5px';
        boostBtn.style.cursor = 'pointer';
        boostBtn.style.fontWeight = 'bold';

        boostBtn.addEventListener('click', toggleBoost);

        uiContainer.appendChild(fpsDisplay);
        uiContainer.appendChild(boostBtn);
        document.body.appendChild(uiContainer);

        // --- 3. LOGIC TÍNH TOÁN FPS ---
        let lastTime = performance.now();
        let frames = 0;

        function updateFPS() {
            let now = performance.now();
            frames++;
            if (now >= lastTime + 1000) {
                currentFps = Math.round((frames * 1000) / (now - lastTime));
                fpsDisplay.innerText = `FPS: ${currentFps}`;
                
                // Đổi màu FPS theo độ mượt
                if (currentFps >= 60) fpsDisplay.style.color = '#00FF00'; // Xanh lá = Ngon
                else if (currentFps >= 30) fpsDisplay.style.color = '#ffa502'; // Cam = Tạm
                else fpsDisplay.style.color = '#ff4757'; // Đỏ = Lag

                frames = 0;
                lastTime = now;
            }
            requestAnimationFrame(updateFPS);
        }
        requestAnimationFrame(updateFPS);

        // --- 4. LOGIC BOOST MƯỢT MÀ ---
        function toggleBoost() {
            isBoosted = !isBoosted;
            if (isBoosted) {
                boostBtn.innerText = '🔥 BOOST ĐANG BẬT';
                boostBtn.style.background = '#2ed573';
                
                // Giảm độ phân giải nội bộ của game để tăng FPS đột biến
                Object.defineProperty(window, 'devicePixelRatio', {
                    get: function() { return 0.5; } // Hạ tỷ lệ điểm ảnh xuống một nửa
                });

                // Ép Canvas render mượt hơn
                document.querySelectorAll('canvas').forEach(canvas => {
                    canvas.style.imageRendering = 'pixelated';
                });
            } else {
                boostBtn.innerText = 'BẬT BOOST (OFF)';
                boostBtn.style.background = '#ff4757';
                
                // Trả về bình thường
                Object.defineProperty(window, 'devicePixelRatio', {
                    get: function() { return originalPixelRatio; }
                });

                document.querySelectorAll('canvas').forEach(canvas => {
                    canvas.style.imageRendering = 'auto';
                });
            }
            
            // Cập nhật lại kích thước cửa sổ để game nhận diện setting mới
            window.dispatchEvent(new Event('resize'));
        }
    });
})();