修复:自动钓鱼冷却倒计时改为基于时间戳,解决后台标签节流导致的显示/触发延迟
This commit is contained in:
@@ -200,34 +200,41 @@ function setFishingButton(text, disabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动自动钓鱼冷却倒计时。
|
* 启动自动钓鱼冷却倒计时(基于时间戳,不受浏览器后台节流影响)。
|
||||||
*
|
*
|
||||||
* @param {number} cooldown
|
* @param {number} cooldown 冷却秒数
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function startAutoFishingCooldown(cooldown) {
|
function startAutoFishingCooldown(cooldown) {
|
||||||
let remaining = cooldown;
|
const endTime = Date.now() + cooldown * 1000;
|
||||||
setFishingButton(`⏳ 冷却 ${remaining}s`, true);
|
setFishingButton(`⏳ 冷却 ${cooldown}s`, true);
|
||||||
showAutoFishStopButton(cooldown);
|
showAutoFishStopButton(cooldown);
|
||||||
|
|
||||||
|
// 基于时间戳更新倒计时 UI — 后台节流后回来也能准确显示
|
||||||
autoFishCooldownCountdown = window.setInterval(() => {
|
autoFishCooldownCountdown = window.setInterval(() => {
|
||||||
remaining -= 1;
|
const remaining = Math.max(0, Math.ceil((endTime - Date.now()) / 1000));
|
||||||
setFishingButton(`⏳ 冷却 ${remaining}s`, true);
|
setFishingButton(`⏳ 冷却 ${remaining}s`, true);
|
||||||
|
|
||||||
if (remaining <= 0) {
|
if (remaining <= 0) {
|
||||||
window.clearInterval(autoFishCooldownCountdown);
|
window.clearInterval(autoFishCooldownCountdown);
|
||||||
autoFishCooldownCountdown = null;
|
autoFishCooldownCountdown = null;
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 200);
|
||||||
|
|
||||||
autoFishCooldownTimer = window.setTimeout(() => {
|
// 基于时间戳检测冷却结束 — 后台节流后立即触发
|
||||||
autoFishCooldownTimer = null;
|
autoFishCooldownTimer = null;
|
||||||
hideAutoFishStopButton();
|
const checkEnd = () => {
|
||||||
|
if (Date.now() >= endTime) {
|
||||||
if (autoFishing) {
|
autoFishCooldownTimer = null;
|
||||||
void startFishing();
|
hideAutoFishStopButton();
|
||||||
|
if (autoFishing) {
|
||||||
|
void startFishing();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}, cooldown * 1000);
|
autoFishCooldownTimer = window.setTimeout(checkEnd, 200);
|
||||||
|
};
|
||||||
|
autoFishCooldownTimer = window.setTimeout(checkEnd, Math.min(cooldown * 1000, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user