修复聊天室滚屏开关失效

This commit is contained in:
pllx
2026-04-30 15:19:38 +08:00
parent 8c7b1086ff
commit b21f583fe5
6 changed files with 70 additions and 10 deletions
+17 -6
View File
@@ -4,6 +4,7 @@
import { escapeHtml, normalizeSafeChatUrl } from "./html.js";
import { normalizeDailyStatus } from "./preferences-status.js";
import { enqueueChatMessage } from "./message-renderer.js";
import { isAutoScrollEnabled, scrollChatToBottom } from "./message-utils.js";
// ── 事件注册标记 ──
let chatEventsBound = false;
@@ -19,6 +20,16 @@ function getState() {
return window.chatState;
}
/**
* 在开启自动滚屏时把指定聊天窗格滚动到底部。
*
* @param {HTMLElement|null|undefined} container 聊天消息容器
* @returns {void}
*/
function scrollWhenEnabled(container) {
scrollChatToBottom(container, isAutoScrollEnabled);
}
/**
* 启动 WebSocket 初始化(DOMContentLoaded 之后调用)。
*/
@@ -79,7 +90,7 @@ function handleMutedEvent(e) {
: (state?.container);
if (targetContainer) {
targetContainer.appendChild(div);
targetContainer.scrollTop = targetContainer.scrollHeight;
scrollWhenEnabled(targetContainer);
}
if (isMe && d.mute_time > 0) {
@@ -99,7 +110,7 @@ function handleMutedEvent(e) {
const say2 = document.getElementById("say2");
if (say2) {
say2.appendChild(unmuteDiv);
say2.scrollTop = say2.scrollHeight;
scrollWhenEnabled(say2);
}
}, d.mute_time * 60 * 1000);
}
@@ -148,7 +159,7 @@ function setupScreenClearedListener() {
sysDiv.innerHTML = `<span style="color: #dc2626; font-weight: bold;">🧹 管理员 <b>${safeOperator}</b> 已执行全员清屏</span><span class="msg-time">(${timeStr})</span>`;
if (say1) {
say1.appendChild(sysDiv);
say1.scrollTop = say1.scrollHeight;
scrollWhenEnabled(say1);
}
});
}
@@ -205,7 +216,7 @@ function setupChangelogPublishedListener() {
const say1 = document.getElementById("chat-messages-container");
if (say1) {
say1.appendChild(sysDiv);
say1.scrollTop = say1.scrollHeight;
scrollWhenEnabled(say1);
}
});
}
@@ -255,7 +266,7 @@ function setupGomokuInviteListener() {
const say1 = document.getElementById("chat-messages-container");
if (say1) {
say1.appendChild(div);
say1.scrollTop = say1.scrollHeight;
scrollWhenEnabled(say1);
}
if (!isSelf) {
@@ -294,7 +305,7 @@ function setupGomokuInviteListener() {
const say1 = document.getElementById("chat-messages-container");
if (say1) {
say1.appendChild(div);
say1.scrollTop = say1.scrollHeight;
scrollWhenEnabled(say1);
}
});
}