Wormax.IO Smooth Zoom Enhancer (Fixed After Death)

Enables smooth zoom with mouse wheel, zoom reset, and persistent zoom after deaths in Wormax.IO.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wormax.IO Smooth Zoom Enhancer (Fixed After Death)
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Enables smooth zoom with mouse wheel, zoom reset, and persistent zoom after deaths in Wormax.IO.
// @author       you
// @match        *://*.wormax.io/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    let __cameraController = null;
    let __forcedZoom = 0.6;
    let __currentZoom = 1;
    let __smoothingLoop = null;
    let __zoomPatched = false;

    function scanForCameraController(root = window, visited = new WeakSet(), depth = 0, path = "window") {
        if (!root || typeof root !== "object" || visited.has(root) || depth > 10) return;
        visited.add(root);

        for (const key in root) {
            try {
                const val = root[key];
                const fullPath = `${path}['${key}']`;

                if (val && typeof val === "object") {
                    if (
                        typeof val.updateZoom === "boolean" &&
                        "follow" in val &&
                        val.camera && typeof val.camera.zoom === "number"
                    ) {
                        console.log("🎯 CameraController found at path:", fullPath);
                        __cameraController = val;
                        window.__cameraController = val;
                        return val;
                    }
                    const found = scanForCameraController(val, visited, depth + 1, fullPath);
                    if (found) return found;
                }
            } catch (e) {}
        }
        return null;
    }

    function patchZoomProperty() {
        if (!__cameraController || !__cameraController.camera) return;

        try {
            Object.defineProperty(__cameraController.camera, "zoom", {
                get() {
                    return __currentZoom;
                },
                set(v) {
                    __forcedZoom = Math.max(0.1, Math.min(5.0, v));
                },
                configurable: true
            });
            __zoomPatched = true;
            console.log("🔁 Zoom property patched");
        } catch (e) {
            console.warn("⚠️ Could not redefine zoom (may already be patched)");
        }
    }

    function startSmoothZoomLoop() {
        if (__smoothingLoop) clearInterval(__smoothingLoop);

        __smoothingLoop = setInterval(() => {
            if (!__cameraController || !__cameraController.camera) return;

            // Re-patch if zoom reverted (after death)
            if (!__zoomPatched || typeof __cameraController.camera.zoom !== "number") {
                patchZoomProperty();
            }

            const diff = __forcedZoom - __currentZoom;
            __currentZoom += diff * 0.02;
            if (Math.abs(diff) < 0.0001) {
                __currentZoom = __forcedZoom;
            }
            __cameraController.camera.update?.();
        }, 30);
    }

    function setupInputHandlers() {
        window.addEventListener("wheel", (e) => {
            const step = e.shiftKey ? 1.0 : e.altKey ? 0.1 : 0.5;
            const delta = e.deltaY > 0 ? step : -step;

            __forcedZoom += delta;
            __forcedZoom = Math.max(0.1, Math.min(5.0, __forcedZoom));
        }, { passive: false });

        document.addEventListener("keydown", (e) => {
            if (e.key.toLowerCase() === "r") {
                __forcedZoom = 1.0;
                console.log("🔄 Zoom reset to 1.0");
            }
        });
    }

    function observeGameLoop() {
        const observer = new MutationObserver(() => {
            const found = scanForCameraController();
            if (found) {
                __cameraController.updateZoom = false;
                patchZoomProperty();
                startSmoothZoomLoop();
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    // Init
    setupInputHandlers();
    observeGameLoop();
})();