HackTimer V1

Uses a Web Worker to ensure high-precision timing for setInterval and setTimeout.

Verze ze dne 18. 10. 2025. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greatest.deepsurf.us/scripts/552983/1679691/HackTimer%20V1.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @license      MIT
// @name         HackTimer V1
// @namespace    HackTimer
// @version      1.0.2.3
// @description  Uses a Web Worker to ensure high-precision timing for setInterval and setTimeout.
// @grant        none
// ==/UserScript==

(function (workerScript) {
    if (!/MSIE 10/i.test(navigator.userAgent)) {
        try {
            var blob = new Blob([`
var fakeIdToId = {};
onmessage = function (event) {
    var data = event.data,
        name = data.name,
        fakeId = data.fakeId,
        time;
    if (data.hasOwnProperty('time')) {
        time = data.time;
    }
    switch (name) {
        case 'setInterval':
            fakeIdToId[fakeId] = setInterval(function () {
                postMessage({fakeId: fakeId});
            }, time);
            break;
        case 'clearInterval':
            if (fakeIdToId.hasOwnProperty(fakeId)) {
                clearInterval(fakeIdToId[fakeId]);
                delete fakeIdToId[fakeId];
            }
            break;
        case 'setTimeout':
            fakeIdToId[fakeId] = setTimeout(function () {
                postMessage({fakeId: fakeId});
                if (fakeIdToId.hasOwnProperty(fakeId)) {
                    delete fakeIdToId[fakeId];
                }
            }, time);
            break;
        case 'clearTimeout':
            if (fakeIdToId.hasOwnProperty(fakeId)) {
                clearTimeout(fakeIdToId[fakeId]);
                delete fakeIdToId[fakeId];
            }
            break;
    }
}
`], { type: 'application/javascript' });
            workerScript = window.URL.createObjectURL(blob);
        } catch (error) {
            console.warn('HackTimer: Blob not supported, using external script');
        }
    }

    var worker,
        fakeIdToCallback = new Map(),
        lastFakeId = 0,
        maxFakeId = 0x7FFFFFFF,
        logPrefix = 'HackTimer: ';

    if (typeof Worker !== 'undefined') {
        function getFakeId() {
            do {
                lastFakeId = (lastFakeId === maxFakeId) ? 0 : lastFakeId + 1;
            } while (fakeIdToCallback.has(lastFakeId));
            return lastFakeId;
        }

        function executeCallback(fakeId) {
            const request = fakeIdToCallback.get(fakeId);
            if (!request) return;

            const { callback, parameters, isTimeout } = request;
            
            if (isTimeout) {
                fakeIdToCallback.delete(fakeId);
            }

            let callbackFunc = callback;
            if (typeof callback === 'string') {
                try {
                    callbackFunc = new Function(callback);
                } catch (error) {
                    console.error(logPrefix + 'Error parsing callback:', error);
                    return;
                }
            }

            if (typeof callbackFunc === 'function') {
                try {
                    callbackFunc.apply(window, parameters);
                } catch (error) {
                    console.error(logPrefix + 'Error executing callback:', error);
                }
            }
        }

        try {
            worker = new Worker(workerScript);
            
            const originalSetInterval = window.setInterval;
            const originalClearInterval = window.clearInterval;
            const originalSetTimeout = window.setTimeout;
            const originalClearTimeout = window.clearTimeout;

            window.setInterval = function (callback, time, ...parameters) {
                const fakeId = getFakeId();
                fakeIdToCallback.set(fakeId, {
                    callback: callback,
                    parameters: parameters,
                    isTimeout: false
                });
                worker.postMessage({
                    name: 'setInterval',
                    fakeId: fakeId,
                    time: Math.max(0, time || 0)
                });
                return fakeId;
            };

            window.clearInterval = function (fakeId) {
                if (fakeIdToCallback.has(fakeId)) {
                    fakeIdToCallback.delete(fakeId);
                    worker.postMessage({
                        name: 'clearInterval',
                        fakeId: fakeId
                    });
                }
            };

            window.setTimeout = function (callback, time, ...parameters) {
                const fakeId = getFakeId();
                fakeIdToCallback.set(fakeId, {
                    callback: callback,
                    parameters: parameters,
                    isTimeout: true
                });
                worker.postMessage({
                    name: 'setTimeout',
                    fakeId: fakeId,
                    time: Math.max(0, time || 0)
                });
                return fakeId;
            };

            window.clearTimeout = function (fakeId) {
                if (fakeIdToCallback.has(fakeId)) {
                    fakeIdToCallback.delete(fakeId);
                    worker.postMessage({
                        name: 'clearTimeout',
                        fakeId: fakeId
                    });
                }
            };

            worker.onmessage = function (event) {
                const { fakeId } = event.data;
                executeCallback(fakeId);
            };

            worker.onerror = function (event) {
                console.error(logPrefix + 'Worker error:', event);
            };

        } catch (error) {
            console.error(logPrefix + 'Initialisation failed:', error);
        }
    } else {
        console.warn(logPrefix + 'Web Workers not supported');
    }
})('HackTimerWorker.js');