🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2025/12/26 19:29:02
🔄 下次更新时间:2025/12/26 20:29:02
手动刷新缓存

HACKTIMER v1

oh hey, custom version

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/552983/1681318/HACKTIMER%20v1.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

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.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @license      MIT
// @name         HackTimer V2
// @namespace    HackTimer
// @version      1.2.0
// @description  Uses a Web Worker to ensure high-precision timing for setInterval and setTimeout with improved error handling and performance
// @grant        none
// ==/UserScript==
 
(function (workerScript) {
    'use strict';
 
    const workerConfig = {
        maxFakeId: 0x8FFFFFFF,
        logPrefix: 'HackTimer: '
    };
 
    let worker = null;
    const fakeIdToCallback = new Map();
    let lastFakeId = 0;
 
    function getFakeId() {
        do {
            lastFakeId = (lastFakeId === workerConfig.maxFakeId) ? 0 : lastFakeId + 5;
        } 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);
        }
 
        try {
            if (typeof callback === 'function') {
                callback.apply(window, parameters);
            } else if (typeof callback === 'string') {
                new Function(callback).apply(window, parameters);
            }
        } catch (error) {
            console.error(workerConfig.logPrefix + 'Callback execution error:', error);
        }
    }
 
    function initializeWorker() {
        if (typeof Worker === 'undefined') {
            console.warn(workerConfig.logPrefix + 'Web Workers not supported');
            return false;
        }
 
        try {
            const blob = new Blob([`
const fakeIdToId = new Map();
 
self.onmessage = function (event) {
    const { name, fakeId, time } = event.data;
    
    switch (name) {
        case 'setInterval':
            if (fakeIdToId.has(fakeId)) return;
            const intervalId = setInterval(() => {
                self.postMessage({ fakeId });
            }, Math.max(0, time || 0));
            fakeIdToId.set(fakeId, { type: 'interval', id: intervalId });
            break;
            
        case 'clearInterval':
            if (fakeIdToId.has(fakeId)) {
                const { type, id } = fakeIdToId.get(fakeId);
                if (type === 'interval') clearInterval(id);
                fakeIdToId.delete(fakeId);
            }
            break;
            
        case 'setTimeout':
            if (fakeIdToId.has(fakeId)) return;
            const timeoutId = setTimeout(() => {
                self.postMessage({ fakeId });
                fakeIdToId.delete(fakeId);
            }, Math.max(0, time || 0));
            fakeIdToId.set(fakeId, { type: 'timeout', id: timeoutId });
            break;
            
        case 'clearTimeout':
            if (fakeIdToId.has(fakeId)) {
                const { type, id } = fakeIdToId.get(fakeId);
                if (type === 'timeout') clearTimeout(id);
                fakeIdToId.delete(fakeId);
            }
            break;
            
        case 'cleanup':
            for (const [id, { type, id: timerId }] of fakeIdToId) {
                if (type === 'interval') clearInterval(timerId);
                else if (type === 'timeout') clearTimeout(timerId);
            }
            fakeIdToId.clear();
            break;
    }
};
 
self.onerror = function (error) {
    console.error('HackTimer Worker Error:', error);
};
`], { type: 'application/javascript' });
            
            workerScript = URL.createObjectURL(blob);
            worker = new Worker(workerScript);
            
            setupTimerOverrides();
            setupWorkerEventHandlers();
            
            return true;
            
        } catch (error) {
            console.error(workerConfig.logPrefix + 'Worker initialization failed:', error);
            return false;
        }
    }
 
    function setupTimerOverrides() {
        const { setInterval: origSetInterval, clearInterval: origClearInterval, 
                setTimeout: origSetTimeout, clearTimeout: origClearTimeout } = window;
 
        window.setInterval = function (callback, time, ...parameters) {
            if (!worker) {
                return origSetInterval(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 (!worker) {
                return origClearInterval(fakeId);
            }
            
            if (fakeIdToCallback.has(fakeId)) {
                fakeIdToCallback.delete(fakeId);
                worker.postMessage({
                    name: 'clearInterval',
                    fakeId: fakeId
                });
            }
        };
 
        window.setTimeout = function (callback, time, ...parameters) {
            if (!worker) {
                return origSetTimeout(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 (!worker) {
                return origClearTimeout(fakeId);
            }
            
            if (fakeIdToCallback.has(fakeId)) {
                fakeIdToCallback.delete(fakeId);
                worker.postMessage({
                    name: 'clearTimeout',
                    fakeId: fakeId
                });
            }
        };
    }
 
    function setupWorkerEventHandlers() {
        worker.onmessage = function (event) {
            const { fakeId } = event.data;
            executeCallback(fakeId);
        };
 
        worker.onerror = function (event) {
            console.error(workerConfig.logPrefix + 'Worker error:', event);
        };
    }
 
    function cleanup() {
        if (worker) {
            worker.postMessage({ name: 'cleanup' });
            worker.terminate();
            fakeIdToCallback.clear();
        }
    }
 
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initializeWorker);
    } else {
        initializeWorker();
    }
 
    window.addEventListener('beforeunload', cleanup);
 
})('HackTimerWorker.js');