Wormax.IO Zoom

Another fix

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wormax.IO Zoom
// @namespace    http://tampermonkey.net/
// @version      4.3
// @description  Another fix
// @author       AdamStorme
// @match        *://*.wormax.io/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    const script = document.createElement('script');
    script.textContent = '(' + function () {
        let zoomTarget = 1.0;
        let controller = null;
        let lastCamera = null;

        function findCameraController() {
            const stack = [window];
            const visited = new WeakSet();

            while (stack.length) {
                const obj = stack.pop();
                if (!obj || typeof obj !== 'object' || visited.has(obj)) continue;
                visited.add(obj);

                for (const key in obj) {
                    try {
                        const val = obj[key];
                        if (
                            val &&
                            typeof val === 'object' &&
                            typeof val.updateZoom === 'boolean' &&
                            typeof val.follow === 'boolean' &&
                            val.camera &&
                            typeof val.camera.zoom === 'number'
                        ) {
                            return val;
                        }
                        if (val && typeof val === 'object') {
                            stack.push(val);
                        }
                    } catch {}
                }
            }
            return null;
        }

        function applyZoom() {
            if (controller?.camera) {
                controller.camera.zoom = zoomTarget;
                controller.camera.update?.();
            }
        }

        function setupInput() {
            window.addEventListener('wheel', (e) => {
                const step = e.altKey ? 0.1 : e.shiftKey ? 1.0 : 0.2;
                zoomTarget += e.deltaY > 0 ? step : -step;
                zoomTarget = Math.max(0.1, Math.min(5.0, zoomTarget));
                applyZoom();
                e.preventDefault();
            }, { passive: false });

            window.addEventListener('keydown', (e) => {
                if (e.key.toLowerCase() === 'r') {
                    zoomTarget = 1.0;
                    applyZoom();
                    console.log('[ZoomMod] Zoom reset');
                }
            });
        }

        function monitorCameraChanges() {
            setInterval(() => {
                const found = findCameraController();
                if (!found) return;

                // If camera controller or camera object changed (e.g. after respawn)
                if (found !== controller || found.camera !== lastCamera) {
                    controller = found;
                    lastCamera = found.camera;
                    controller.updateZoom = false;
                    console.log('[ZoomMod] Rehooked after camera change');
                    applyZoom();
                }
            }, 300); // Frequent check, but not too aggressive
        }

        function init() {
            setupInput();
            monitorCameraChanges();
        }

        init();
    } + ')();';
    document.body.appendChild(script);
})();