HTML5 Universal Speed Hack PLUS (Userscript Edition)

Tăng tốc độ thời gian trong game HTML5 và video

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         HTML5 Universal Speed Hack PLUS (Userscript Edition)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Tăng tốc độ thời gian trong game HTML5 và video
// @author       Dựa trên code của TheByteyear & HUSH+
// @match        *://*/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addStyle
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    
    // --- Cấu hình mặc định ---
    const defaultConfig = {
        speed: GM_getValue("hush-speed", 1.0),
        cbSetIntervalChecked: GM_getValue("hush-si", true),
        cbSetTimeoutChecked: GM_getValue("hush-st", true),
        cbPerformanceNowChecked: GM_getValue("hush-pn", true),
        cbDateNowChecked: GM_getValue("hush-dn", true),
        cbRequestAnimationFrameChecked: GM_getValue("hush-raf", false)
    };

    // --- Phần 1: Core Logic (Từ contentScript.js) ---
    function pageScript() {
        // COPY TOÀN BỘ NỘI DUNG HÀM pageScript TỪ contentScript.js VÀO ĐÂY
        let speedConfig = {
            speed: 1.0,
            cbSetIntervalChecked: true,
            cbSetTimeoutChecked: true,
            cbPerformanceNowChecked: true,
            cbDateNowChecked: true,
            cbRequestAnimationFrameChecked: false,
        };
        // ... (Phần còn lại của hàm pageScript)
        
        window.addEventListener("message", (e) => {
            if (e.data.command === "setSpeedConfig") {
                speedConfig = e.data.config;
                reloadTimers();
            }
        });
        
        // Gửi yêu cầu cấu hình ban đầu lên parent (nơi sẽ chạy code điều khiển)
        window.postMessage({ command: "getSpeedConfig" });

        // ... (Các hàm override)
    }

    // Hàm này để chèn pageScript vào trang web
    function injectScript() {
        const script = document.createElement("script");
        script.setAttribute("type", "text/javascript");
        script.textContent = `!${pageScript.toString()}()\n//# sourceURL=pageScript.js`;
        document.documentElement.appendChild(script);
    }
    
    // --- Kết thúc Phần 1 ---

    // Chạy injectScript ngay lập tức
    injectScript();

    // --- Phần 2: Xây dựng UI Điều khiển và Kết nối ---
    
    // Lấy cấu hình đã lưu
    let speedConfig = {
        speed: GM_getValue("hush-speed", 1.0),
        cbSetIntervalChecked: GM_getValue("hush-si", true),
        cbSetTimeoutChecked: GM_getValue("hush-st", true),
        cbPerformanceNowChecked: GM_getValue("hush-pn", true),
        cbDateNowChecked: GM_getValue("hush-dn", true),
        cbRequestAnimationFrameChecked: GM_getValue("hush-raf", false)
    };

    // Lắng nghe yêu cầu cấu hình từ pageScript
    window.addEventListener("message", (e) => {
        if (e.data.command === "getSpeedConfig") {
            window.postMessage({
                command: "setSpeedConfig",
                config: speedConfig,
            }, "*");
        }
    });

    // Gửi cấu hình mới đến pageScript và lưu lại
    function updateConfig(newConfig) {
        // Cập nhật object hiện tại
        for (let key in newConfig) {
            if (newConfig.hasOwnProperty(key)) {
                speedConfig[key] = newConfig[key];
            }
        }
        // Gửi xuống pageScript
        window.postMessage({
            command: "setSpeedConfig",
            config: speedConfig,
        }, "*");
        // Lưu vào storage của Tampermonkey
        GM_setValue("hush-speed", speedConfig.speed);
        GM_setValue("hush-si", speedConfig.cbSetIntervalChecked);
        GM_setValue("hush-st", speedConfig.cbSetTimeoutChecked);
        GM_setValue("hush-pn", speedConfig.cbPerformanceNowChecked);
        GM_setValue("hush-dn", speedConfig.cbDateNowChecked);
        GM_setValue("hush-raf", speedConfig.cbRequestAnimationFrameChecked);
    }

    // --- Phần 3: Tạo giao diện HTML cho thanh điều khiển nổi ---
    
    // Thêm CSS cho thanh điều khiển
    GM_addStyle(`
        #hush-control-panel {
            position: fixed;
            top: 10px;
            right: 10px;
            z-index: 999999;
            background: rgba(30, 30, 30, 0.9);
            color: white;
            padding: 15px;
            border-radius: 8px;
            font-family: Arial, sans-serif;
            font-size: 14px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.3);
            border: 1px solid #555;
            width: 260px;
            backdrop-filter: blur(5px);
            cursor: move; /* Gợi ý có thể kéo */
            user-select: none;
        }
        #hush-control-panel .header {
            font-weight: bold;
            margin-bottom: 10px;
            text-align: center;
            color: #ffa500;
            cursor: move;
        }
        #hush-control-panel .slider-container {
            margin-bottom: 15px;
        }
        #hush-control-panel .slider-label {
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
        }
        #hush-control-panel input[type=range] {
            width: 100%;
            cursor: pointer;
        }
        #hush-control-panel .speed-value {
            font-weight: bold;
            color: #ffa500;
        }
        #hush-control-panel .checkbox-group {
            display: flex;
            flex-direction: column;
            gap: 8px;
            margin-top: 10px;
        }
        #hush-control-panel .checkbox-group label {
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
        }
        #hush-control-panel .minimap-marks {
            display: flex;
            justify-content: space-between;
            margin-top: 4px;
            color: #aaa;
            font-size: 10px;
            padding: 0 5px;
        }
    `);

    // Tạo element div cho panel
    const panel = document.createElement('div');
    panel.id = 'hush-control-panel';
    panel.innerHTML = `
        <div class="header" id="hush-drag-handle">⚡ HUSH+ Control</div>
        <div class="slider-container">
            <div class="slider-label">
                <span>Speed</span>
                <span class="speed-value" id="hush-speed-display">${speedConfig.speed.toFixed(2)}x</span>
            </div>
            <input type="range" id="hush-speed-slider" min="0.05" max="25" step="0.05" value="${speedConfig.speed}">
            <div class="minimap-marks">
                <span>0x</span><span>5x</span><span>10x</span><span>15x</span><span>20x</span><span>25x</span>
            </div>
        </div>
        <div class="checkbox-group">
            <label><input type="checkbox" id="cb-si" ${speedConfig.cbSetIntervalChecked ? 'checked' : ''}> <span>Override setInterval</span></label>
            <label><input type="checkbox" id="cb-st" ${speedConfig.cbSetTimeoutChecked ? 'checked' : ''}> <span>Override setTimeout</span></label>
            <label><input type="checkbox" id="cb-pn" ${speedConfig.cbPerformanceNowChecked ? 'checked' : ''}> <span>Override performance.now</span></label>
            <label><input type="checkbox" id="cb-dn" ${speedConfig.cbDateNowChecked ? 'checked' : ''}> <span>Override Date.now</span></label>
            <label><input type="checkbox" id="cb-raf" ${speedConfig.cbRequestAnimationFrameChecked ? 'checked' : ''}> <span>Override requestAnimationFrame</span></label>
        </div>
    `;

    // Thêm panel vào body
    document.body.appendChild(panel);

    // --- Phần 4: Kết nối sự kiện UI ---

    const speedSlider = document.getElementById('hush-speed-slider');
    const speedDisplay = document.getElementById('hush-speed-display');
    const cbSi = document.getElementById('cb-si');
    const cbSt = document.getElementById('cb-st');
    const cbPn = document.getElementById('cb-pn');
    const cbDn = document.getElementById('cb-dn');
    const cbRaf = document.getElementById('cb-raf');

    function sendUpdateFromUI() {
        const newConfig = {
            speed: parseFloat(speedSlider.value),
            cbSetIntervalChecked: cbSi.checked,
            cbSetTimeoutChecked: cbSt.checked,
            cbPerformanceNowChecked: cbPn.checked,
            cbDateNowChecked: cbDn.checked,
            cbRequestAnimationFrameChecked: cbRaf.checked,
        };
        speedDisplay.textContent = newConfig.speed.toFixed(2) + 'x';
        updateConfig(newConfig);
    }

    speedSlider.addEventListener('input', sendUpdateFromUI);
    cbSi.addEventListener('change', sendUpdateFromUI);
    cbSt.addEventListener('change', sendUpdateFromUI);
    cbPn.addEventListener('change', sendUpdateFromUI);
    cbDn.addEventListener('change', sendUpdateFromUI);
    cbRaf.addEventListener('change', sendUpdateFromUI);

    // --- (Tùy chọn) Thêm tính năng kéo thả cho panel ---
    let isDragging = false;
    let offsetX, offsetY;
    const dragHandle = document.getElementById('hush-drag-handle');

    dragHandle.addEventListener('mousedown', (e) => {
        isDragging = true;
        offsetX = e.clientX - panel.offsetLeft;
        offsetY = e.clientY - panel.offsetTop;
        panel.style.cursor = 'grabbing';
    });

    document.addEventListener('mousemove', (e) => {
        if (isDragging) {
            panel.style.left = (e.clientX - offsetX) + 'px';
            panel.style.top = (e.clientY - offsetY) + 'px';
            panel.style.right = 'auto'; // Bỏ fixed right
        }
    });

    document.addEventListener('mouseup', () => {
        isDragging = false;
        panel.style.cursor = 'move';
    });

})();