修复自动钓鱼状态与播报屏蔽范围
This commit is contained in:
@@ -50,19 +50,12 @@ function appendFishingMessage(html) {
|
||||
return;
|
||||
}
|
||||
|
||||
const blockedSet = window.chatState?.blockedSystemSenders;
|
||||
const isBlocked = blockedSet instanceof Set && blockedSet.has("钓鱼播报");
|
||||
const line = document.createElement("div");
|
||||
line.className = "msg-line";
|
||||
line.dataset.blockKey = "钓鱼播报";
|
||||
if (isBlocked) {
|
||||
line.dataset.blockHidden = "1";
|
||||
line.style.display = "none";
|
||||
}
|
||||
line.innerHTML = html;
|
||||
container.appendChild(line);
|
||||
|
||||
if (!isBlocked && shouldAutoScroll()) {
|
||||
if (shouldAutoScroll()) {
|
||||
container.scrollTop = container.scrollHeight;
|
||||
}
|
||||
}
|
||||
@@ -233,6 +226,8 @@ function hasActiveFishingSession() {
|
||||
* @returns {void}
|
||||
*/
|
||||
function startAutoFishingCooldown(cooldown) {
|
||||
clearAutoFishingTimers();
|
||||
|
||||
const endTime = Date.now() + cooldown * 1000;
|
||||
setFishingButton(`⏳ 冷却 ${cooldown}s`, true);
|
||||
showAutoFishStopButton(cooldown);
|
||||
@@ -254,10 +249,13 @@ function startAutoFishingCooldown(cooldown) {
|
||||
const checkEnd = () => {
|
||||
if (Date.now() >= endTime) {
|
||||
autoFishCooldownTimer = null;
|
||||
hideAutoFishStopButton();
|
||||
if (autoFishing) {
|
||||
updateAutoFishStopButtonCountdown(0, "正在继续自动钓鱼");
|
||||
void startFishing();
|
||||
return;
|
||||
}
|
||||
|
||||
hideAutoFishStopButton();
|
||||
return;
|
||||
}
|
||||
autoFishCooldownTimer = window.setTimeout(checkEnd, 200);
|
||||
@@ -272,7 +270,9 @@ function startAutoFishingCooldown(cooldown) {
|
||||
* @returns {void}
|
||||
*/
|
||||
function showAutoFishStopButton(cooldown) {
|
||||
if (document.getElementById("auto-fish-stop-btn")) {
|
||||
const currentButton = document.getElementById("auto-fish-stop-btn");
|
||||
if (currentButton) {
|
||||
updateAutoFishStopButtonCountdown(cooldown);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -304,16 +304,17 @@ function showAutoFishStopButton(cooldown) {
|
||||
* 同步更新停止自动钓鱼浮层上的冷却秒数,避免与主按钮倒计时不一致。
|
||||
*
|
||||
* @param {number} cooldown
|
||||
* @param {string|null} text
|
||||
* @returns {void}
|
||||
*/
|
||||
function updateAutoFishStopButtonCountdown(cooldown) {
|
||||
function updateAutoFishStopButtonCountdown(cooldown, text = null) {
|
||||
const hint = document.querySelector("#auto-fish-stop-btn .drag-hint");
|
||||
|
||||
if (!(hint instanceof HTMLElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
hint.textContent = `冷却 ${Number(cooldown) || 0}s · 可拖动`;
|
||||
hint.textContent = text || `冷却 ${Number(cooldown) || 0}s · 可拖动`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,6 +426,12 @@ export async function startFishing() {
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok || data.status !== "success") {
|
||||
if (autoFishing && response.status === 429) {
|
||||
// 服务端冷却 TTL 可能与前端倒计时有毫秒级误差,自动模式下按服务端剩余时间续等。
|
||||
startAutoFishingCooldown(Math.max(1, Number(data.cooldown) || 1));
|
||||
return;
|
||||
}
|
||||
|
||||
window.chatDialog?.alert?.(data.message || "钓鱼失败", "操作失败", "#cc4444");
|
||||
setFishingButton("🎣 钓鱼", false);
|
||||
return;
|
||||
@@ -439,11 +446,20 @@ export async function startFishing() {
|
||||
const bobber = createBobber(data.bobber_x, data.bobber_y);
|
||||
document.body.appendChild(bobber);
|
||||
|
||||
if (data.auto_fishing) {
|
||||
showAutoFishStopButton(0);
|
||||
updateAutoFishStopButtonCountdown(0, "等待鱼儿上钩 · 可拖动");
|
||||
}
|
||||
|
||||
fishingTimer = window.setTimeout(() => {
|
||||
// 等待计时器触发后必须立即释放句柄,否则自动钓鱼冷却结束会误判仍有会话进行中。
|
||||
fishingTimer = null;
|
||||
bobber.classList.add("sinking");
|
||||
bobber.textContent = "🐟";
|
||||
|
||||
if (data.auto_fishing) {
|
||||
showAutoFishStopButton(0);
|
||||
updateAutoFishStopButtonCountdown(0, "自动收竿中 · 可拖动");
|
||||
appendFishingMessage(`<span style="color:#7c3aed;font-weight:bold;">🎣 自动钓鱼卡生效!自动收竿中... <span style="font-size:10px;opacity:0.7">(剩余${Number(data.auto_fishing_minutes_left) || 0}分钟)</span></span>`);
|
||||
fishingReelTimeout = window.setTimeout(() => {
|
||||
removeBobber();
|
||||
|
||||
Reference in New Issue
Block a user