Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b15e42891d | |||
| 214a422504 |
@@ -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;
|
||||||
|
const checkEnd = () => {
|
||||||
|
if (Date.now() >= endTime) {
|
||||||
autoFishCooldownTimer = null;
|
autoFishCooldownTimer = null;
|
||||||
hideAutoFishStopButton();
|
hideAutoFishStopButton();
|
||||||
|
|
||||||
if (autoFishing) {
|
if (autoFishing) {
|
||||||
void startFishing();
|
void startFishing();
|
||||||
}
|
}
|
||||||
}, cooldown * 1000);
|
return;
|
||||||
|
}
|
||||||
|
autoFishCooldownTimer = window.setTimeout(checkEnd, 200);
|
||||||
|
};
|
||||||
|
autoFishCooldownTimer = window.setTimeout(checkEnd, Math.min(cooldown * 1000, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -457,6 +457,9 @@ export function enqueueChatMessage(msg) {
|
|||||||
state.chatMessageFlushTimer = scheduleFlush(flushQueuedChatMessages);
|
state.chatMessageFlushTimer = scheduleFlush(flushQueuedChatMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 后台恢复时公屏最大渲染条数,避免暴刷 */
|
||||||
|
const MAX_BURST_RENDER = 50;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分批渲染待处理消息,给动画、输入和滚动留出主线程时间。
|
* 分批渲染待处理消息,给动画、输入和滚动留出主线程时间。
|
||||||
*/
|
*/
|
||||||
@@ -466,6 +469,23 @@ export function flushQueuedChatMessages() {
|
|||||||
|
|
||||||
state.chatMessageFlushTimer = null;
|
state.chatMessageFlushTimer = null;
|
||||||
|
|
||||||
|
// 大批量消息堆积(后台标签页恢复)时,丢弃早于 MAX_BURST_RENDER 的消息,
|
||||||
|
// 插入一条省略提示,避免用户一回来就看到满屏消息狂刷。
|
||||||
|
if (state.pendingChatMessages.length > MAX_BURST_RENDER + 20) {
|
||||||
|
const skipped = state.pendingChatMessages.length - MAX_BURST_RENDER;
|
||||||
|
state.pendingChatMessages.splice(0, skipped);
|
||||||
|
|
||||||
|
const container = state.container;
|
||||||
|
if (container) {
|
||||||
|
const notice = document.createElement("div");
|
||||||
|
notice.className = "msg-line msg-burst-notice";
|
||||||
|
notice.style.cssText =
|
||||||
|
"text-align:center;padding:6px 0;margin:4px 0;font-size:12px;color:#94a3b8;border-top:1px dashed #d1d5db;border-bottom:1px dashed #d1d5db;";
|
||||||
|
notice.textContent = `⏫ 省略了 ${skipped} 条未读消息`;
|
||||||
|
container.appendChild(notice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const batch = state.pendingChatMessages.splice(0, CHAT_MESSAGE_FLUSH_BATCH_SIZE);
|
const batch = state.pendingChatMessages.splice(0, CHAT_MESSAGE_FLUSH_BATCH_SIZE);
|
||||||
const renderBatch = createChatMessageRenderBatch();
|
const renderBatch = createChatMessageRenderBatch();
|
||||||
batch.forEach((msg) => appendMessage(msg, renderBatch));
|
batch.forEach((msg) => appendMessage(msg, renderBatch));
|
||||||
|
|||||||
Reference in New Issue
Block a user