(function () {
'use strict';
if (window.__snowmanAutoLight) return;
window.__snowmanAutoLight = true;
const sleep = ms => new Promise(r => setTimeout(r, ms));
function getCurrentFloor() {
const floors = document.querySelectorAll('[class^="floor"]');
for (const el of floors) {
if (el.querySelector('.obj_character')) {
const name = el.className;
const num = Number(name.slice(5));
if (!isNaN(num)) return num;
}
}
return null;
}
function getDoors(floor) {
const el = document.querySelector('.floor' + floor);
if (!el) return [];
return Array.from(el.querySelectorAll('button.door'));
}
const nextDoorIndex = {};
let lastClicked = null;
let stopFlag = false;
function clickNextDoor(floor) {
const doors = getDoors(floor);
if (!doors.length) return;
if (nextDoorIndex[floor] == null) {
nextDoorIndex[floor] = 0;
}
const idx = nextDoorIndex[floor];
const btn = doors[idx];
if (!btn || btn.disabled) return;
lastClicked = { floor, idx };
btn.click();
}
(function hookXHR() {
if (window.__snowmanXHRHooked) return;
window.__snowmanXHRHooked = true;
const OriginalXHR = window.XMLHttpRequest;
function WrappedXHR() {
const xhr = new OriginalXHR();
let url = null;
const open = xhr.open;
xhr.open = function (m, u) {
url = u;
return open.apply(xhr, arguments);
};
const send = xhr.send;
xhr.send = function () {
xhr.addEventListener('load', () => {
try {
if (!url || url.indexOf('SetDoor') === -1) return;
if (!lastClicked) return;
const res = JSON.parse(xhr.responseText);
const { floor } = lastClicked;
if (res.isCorrect) {
nextDoorIndex[floor + 1] = 0;
} else {
nextDoorIndex[floor]++;
}
} catch {}
});
return send.apply(xhr, arguments);
};
return xhr;
}
WrappedXHR.prototype = OriginalXHR.prototype;
window.XMLHttpRequest = WrappedXHR;
})();
async function loop() {
while (!stopFlag) {
const floor = getCurrentFloor();
if (floor != null) {
clickNextDoor(floor);
}
await sleep(150);
}
}
window.addEventListener('keydown', e => {
if (e.key === 'Escape') stopFlag = true;
});
loop();
})();