Wormax.IO Zoom

Another fix

目前為 2025-07-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();