Another fix
目前為
// ==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);
})();