// ==UserScript== // @name 通用时间加速器(修复浮窗显示) // @namespace http://tampermonkey.net/ // @version 1.8 // @description 修复浮窗消失问题,确保UI正确显示 // @author ZMM // @match *://*/* // @grant none // @run-at document-start // ==/UserScript== (function () { 'use strict'; /* ========== 配置持久化 ========== */ const CFG_KEY = '__time_cheat_cfg__'; const defaultCfg = { enabled: false, multiplier: 2 // 默认2倍速 }; let cfg = Object.assign({}, defaultCfg); try { cfg = Object.assign(cfg, JSON.parse(localStorage.getItem(CFG_KEY) || '{}')); } catch (e) { localStorage.removeItem(CFG_KEY); } function saveCfg() { localStorage.setItem(CFG_KEY, JSON.stringify(cfg)); } /* ========== 核心:绝对稳定的时间加速引擎 ========== */ // 1. 保存原始函数(关键:Date.now 必须恢复原始行为) const OrigPerfNow = performance.now.bind(performance); const OrigDateNow = Date.now; // 2. 初始化时间引擎变量 let lastRealPerfTime = OrigPerfNow(); let fakePerfTime = lastRealPerfTime; let timeEngineEnabled = false; // 3. 劫持 performance.now(仅用于游戏逻辑加速) function safePerfNow() { const realNow = OrigPerfNow(); const delta = realNow - lastRealPerfTime; lastRealPerfTime = realNow; // 防止时间跳跃过大(如切后台再切回来) if (delta > 0 && delta < 10000) { // 允许10秒内的跳跃,避免异常重置 if (timeEngineEnabled) { const multiplier = Number(cfg.multiplier) || 1; fakePerfTime += delta * multiplier; } else { fakePerfTime += delta; // 即使没开启,也要让 fakePerfTime 跟上真实时间,避免停滞 } } else { // 跳跃过大,直接对齐真实时间,避免负数 fakePerfTime = realNow; } return fakePerfTime; } // 4. 劫持 Date.now(关键修复:恢复原始行为,不再依赖 performance.now) Date.now = OrigDateNow; // 直接使用原始 Date.now,返回系统当前时间 // 5. 启用/禁用时间引擎 function enableTimeEngine() { timeEngineEnabled = true; performance.now = safePerfNow; // 启用加速 } function disableTimeEngine() { timeEngineEnabled = false; performance.now = OrigPerfNow; // 恢复原始 performance.now } /* ========== 注入 UI:可移动浮窗(彻底修复) ========== */ function injectUI() { try { // 1. 注入CSS样式(确保样式正确加载) const css = document.createElement('style'); css.textContent = ` #time-cheat-btn{ position:fixed; z-index:2147483647; width:42px; height:42px; border-radius:50%; border:2px solid #4CAF50; background:linear-gradient(135deg,#2E7D32 0%,#4CAF50 100%); color:#fff; font:bold 18px/42px sans-serif; text-align:center; cursor:pointer; user-select:none; box-shadow:0 2px 12px rgba(0,0,0,.6); transition:transform .15s,box-shadow .15s; right:16px; top:16px; touch-action:none; } #time-cheat-btn:hover{ transform:scale(1.12); box-shadow:0 0 18px rgba(76,175,80,.5); } #time-cheat-panel{ position:fixed; z-index:2147483646; right:70px; top:16px; width:280px; max-height:90vh; overflow-y:auto; background:rgba(30,30,30,.95); border:1.5px solid #4CAF50; border-radius:10px; box-shadow:0 4px 30px rgba(0,0,0,.7); font:13px/1.5 'Segoe UI',sans-serif; color:#e0e0e0; transition:opacity .2s,transform .2s; transform-origin:top right; } #time-cheat-panel.tc-hidden{ opacity:0; transform:scale(.92); pointer-events:none; } .tc-hd{ display:flex; align-items:center; justify-content:space-between; padding:10px 14px; background:rgba(76,175,80,.12); border-bottom:1px solid rgba(76,175,80,.25); cursor:move