迁移聊天室滚屏状态入口
This commit is contained in:
@@ -78,3 +78,42 @@ export function localClearScreen(roomId = window.chatContext?.roomId, maxMessage
|
||||
publicPane.scrollTop = publicPane.scrollHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步自动滚屏复选框与状态文字。
|
||||
*
|
||||
* @param {boolean} enabled 是否开启自动滚屏
|
||||
* @returns {void}
|
||||
*/
|
||||
export function syncAutoScrollControls(enabled) {
|
||||
const checkbox = document.getElementById("auto_scroll");
|
||||
const status = document.getElementById("scroll-status");
|
||||
|
||||
if (checkbox) {
|
||||
checkbox.checked = enabled;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
status.textContent = enabled ? "开" : "关";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换自动滚屏状态。
|
||||
* 真实状态仍由 Blade 大脚本闭包保存,这里通过 getter/setter 桥接,避免 Vite 模块持有第二份状态。
|
||||
*
|
||||
* @param {() => boolean} getCurrent 读取当前状态
|
||||
* @param {(enabled:boolean) => void} setCurrent 写回当前状态
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function toggleAutoScroll(getCurrent, setCurrent) {
|
||||
const nextEnabled = !Boolean(typeof getCurrent === "function" ? getCurrent() : true);
|
||||
|
||||
if (typeof setCurrent === "function") {
|
||||
setCurrent(nextEnabled);
|
||||
}
|
||||
|
||||
syncAutoScrollControls(nextEnabled);
|
||||
|
||||
return nextEnabled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user