Wormax.IO Zoom (Fixed client-side issues)

Enables smooth zoom with mouse wheel Wormax.IO.

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wormax.IO Zoom (Fixed client-side issues)
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Enables smooth zoom with mouse wheel Wormax.IO.
// @author       AdamStorme
// @match        *://*.wormax.io/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    let zoomTarget = 1.0;
    let cameraController = 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' &&
                        val.camera &&
                        typeof val.camera.zoom === 'number' &&
                        'updateZoom' in val &&
                        'follow' in val
                    ) {
                        return val;
                    }
                    if (val && typeof val === 'object') {
                        stack.push(val);
                    }
                } catch (e) {}
            }
        }
        return null;
    }

    function startZoomControlLoop() {
        const cam = cameraController.camera;
        cameraController.updateZoom = false;
        console.log('[ZoomMod] Zoom control enabled');

        const zoomStep = () => {
            const diff = zoomTarget - cam.zoom;
            cam.zoom += diff * 0.05;
            requestAnimationFrame(zoomStep);
        };
        requestAnimationFrame(zoomStep);
    }

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

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

    function waitForGameInit() {
        const interval = setInterval(() => {
            const ctrl = findCameraController();
            if (ctrl && ctrl.camera && typeof ctrl.camera.zoom === 'number') {
                clearInterval(interval);
                cameraController = ctrl;
                setupUserInput();
                startZoomControlLoop();
            }
        }, 1000);
    }

    waitForGameInit();
})();