// ==UserScript== // @name A Dark Room 一键加满资源(立即生效) // @namespace http://tampermonkey.net/ // @version 1.6 // @description 点击加满资源并立即刷新界面(小于999999才修改) // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; function injectButton() { if (document.getElementById("add-resource-btn")) return; let state; try { state = JSON.parse(localStorage.getItem("gameState")); } catch(e){} let resourceContainers = [ window.game && window.game.resources, window.room && window.room.resources, window.resources ]; // 检查是否存在可修改资源 let hasResources = (state && state.stores && "wood" in state.stores) || resourceContainers.some(c => c && "wood" in c); if (!hasResources) return; // 创建按钮 const btn = document.createElement("button"); btn.id = "add-resource-btn"; btn.innerText = "💰 一键加满资源"; btn.style.position = "fixed"; btn.style.top = "10px"; btn.style.right = "10px"; btn.style.zIndex = 9999; btn.style.padding = "8px 12px"; btn.style.background = "#28a745"; btn.style.color = "white"; btn.style.border = "none"; btn.style.borderRadius = "6px"; btn.style.cursor = "pointer"; btn.style.fontSize = "14px"; btn.style.boxShadow = "0 2px 6px rgba(0,0,0,0.3)"; btn.onclick = function() { // 修改 LocalStorage if(state && state.stores){ Object.keys(state.stores).forEach(k => { if(state.stores[k] < 999999){ state.stores[k] = 999999; } } ); localStorage.setItem("gameState", JSON.stringify(state)); } // 修改 window.resources resourceContainers.forEach(c => { if(c){ Object.keys(c).forEach(k=>{ if(c[k] && typeof c[k] === 'object' && 'value' in c[k]){ if(c[k].value < 999999){ c[k].value = 999999; } } }); } }); //alert("💎 所有资源已加满,页面将刷新!"); // 刷新页面让资源立即生效 location.reload(); }; document.body.appendChild(btn); } // 定时轮询,直到资源存在才注入 const interval = setInterval(() => { injectButton(); }, 500); })();