Universal HTML5 Speed Hack with GUI

change the speed of the site. works on every site (performance.now, Date.now, setTimeout, requestAnimationFrame)

当前为 2025-07-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Universal HTML5 Speed Hack with GUI
// @namespace    https://chat.openai.com/
// @version      1.1
// @description  change the speed of the site. works on every site (performance.now, Date.now, setTimeout, requestAnimationFrame)
// @author       kubabreak; i did use chatgpt for this though
// @match        *://*/*
// @grant        none
// @run-at       document-end
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    let speed = 1.0;

    function injectSpeedHack(win) {
        try {
            const script = win.document.createElement('script');
            script.textContent = `(() => {
                const realPerfNow = performance.now.bind(performance);
                const realDateNow = Date.now;
                const realSetTimeout = window.setTimeout;
                const realRAF = window.requestAnimationFrame;
                const start = realPerfNow();
                window.__speedHack = ${speed};

                performance.now = () => start + (realPerfNow() - start) * window.__speedHack;
                Date.now = () => realDateNow() * window.__speedHack;
                window.setTimeout = (fn, delay, ...args) => realSetTimeout(fn, delay / window.__speedHack, ...args);
                window.requestAnimationFrame = (cb) => realRAF(t => cb(t * window.__speedHack));

                console.log('[SpeedHack] Active at ' + window.__speedHack + 'x');
            })();`;
            win.document.documentElement.appendChild(script);
        } catch (e) {
            console.warn('[SpeedHack] Injection failed:', e);
        }
    }

    function updateSpeed(newSpeed) {
        speed = newSpeed;
        const win = window;
        win.__speedHack = speed;
        injectSpeedHack(win);
        for (const frame of document.querySelectorAll("iframe")) {
            try {
                frame.contentWindow.__speedHack = speed;
                injectSpeedHack(frame.contentWindow);
            } catch (e) {
                // Ignore cross-origin
            }
        }
    }

    function addSpeedControlUI() {
        const ui = document.createElement("div");
        ui.style.position = "fixed";
        ui.style.top = "10px";
        ui.style.right = "10px";
        ui.style.padding = "10px";
        ui.style.background = "rgba(0,0,0,0.7)";
        ui.style.color = "white";
        ui.style.zIndex = 999999;
        ui.style.borderRadius = "8px";
        ui.style.fontSize = "14px";
        ui.style.fontFamily = "sans-serif";
        ui.innerHTML = `
            <label style="display:block;">Speed: <span id="speedVal">${speed.toFixed(2)}x</span></label>
            <input type="range" id="speedSlider" min="0.1" max="5" value="${speed}" step="0.1" style="width:150px;">
        `;
        document.body.appendChild(ui);

        const slider = ui.querySelector("#speedSlider");
        const valText = ui.querySelector("#speedVal");

        slider.addEventListener("input", () => {
            const val = parseFloat(slider.value);
            valText.textContent = val.toFixed(2) + "x";
            updateSpeed(val);
        });
    }

    // Initialize on current window and all same-origin iframes
    function initialize() {
        injectSpeedHack(window);
        for (const frame of document.querySelectorAll("iframe")) {
            try {
                injectSpeedHack(frame.contentWindow);
            } catch (e) {
                // Cross-origin iframe – ignore
            }
        }
        addSpeedControlUI();
    }

    // Wait a bit for page to stabilize
    setTimeout(initialize, 500);
})();