From 214a4225047def0eb72072359563e319522189ef Mon Sep 17 00:00:00 2001 From: pllx Date: Tue, 28 Apr 2026 11:52:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=92=93=E9=B1=BC=E5=86=B7=E5=8D=B4=E5=80=92=E8=AE=A1=E6=97=B6?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=9F=BA=E4=BA=8E=E6=97=B6=E9=97=B4=E6=88=B3?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=90=8E=E5=8F=B0=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E8=8A=82=E6=B5=81=E5=AF=BC=E8=87=B4=E7=9A=84=E6=98=BE=E7=A4=BA?= =?UTF-8?q?/=E8=A7=A6=E5=8F=91=E5=BB=B6=E8=BF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/chat-room/fishing.js | 33 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/resources/js/chat-room/fishing.js b/resources/js/chat-room/fishing.js index 174e97c..282f763 100644 --- a/resources/js/chat-room/fishing.js +++ b/resources/js/chat-room/fishing.js @@ -200,34 +200,41 @@ function setFishingButton(text, disabled) { } /** - * 启动自动钓鱼冷却倒计时。 + * 启动自动钓鱼冷却倒计时(基于时间戳,不受浏览器后台节流影响)。 * - * @param {number} cooldown + * @param {number} cooldown 冷却秒数 * @returns {void} */ function startAutoFishingCooldown(cooldown) { - let remaining = cooldown; - setFishingButton(`⏳ 冷却 ${remaining}s`, true); + const endTime = Date.now() + cooldown * 1000; + setFishingButton(`⏳ 冷却 ${cooldown}s`, true); showAutoFishStopButton(cooldown); + // 基于时间戳更新倒计时 UI — 后台节流后回来也能准确显示 autoFishCooldownCountdown = window.setInterval(() => { - remaining -= 1; + const remaining = Math.max(0, Math.ceil((endTime - Date.now()) / 1000)); setFishingButton(`⏳ 冷却 ${remaining}s`, true); if (remaining <= 0) { window.clearInterval(autoFishCooldownCountdown); autoFishCooldownCountdown = null; } - }, 1000); + }, 200); - autoFishCooldownTimer = window.setTimeout(() => { - autoFishCooldownTimer = null; - hideAutoFishStopButton(); - - if (autoFishing) { - void startFishing(); + // 基于时间戳检测冷却结束 — 后台节流后立即触发 + autoFishCooldownTimer = null; + const checkEnd = () => { + if (Date.now() >= endTime) { + autoFishCooldownTimer = null; + hideAutoFishStopButton(); + if (autoFishing) { + void startFishing(); + } + return; } - }, cooldown * 1000); + autoFishCooldownTimer = window.setTimeout(checkEnd, 200); + }; + autoFishCooldownTimer = window.setTimeout(checkEnd, Math.min(cooldown * 1000, 200)); } /**