迁移字号选择器事件绑定

This commit is contained in:
2026-04-25 03:40:30 +08:00
parent e9c3fc989c
commit ca61dd42f7
3 changed files with 26 additions and 3 deletions
+21
View File
@@ -1,6 +1,7 @@
// 聊天室字号偏好控制,保留旧的 localStorage key 以兼容已有用户设置。
export const CHAT_FONT_SIZE_STORAGE_KEY = "chat_font_size";
let fontSizeEventsBound = false;
/**
* 应用字号到聊天消息窗口,并保存到 localStorage。
@@ -43,3 +44,23 @@ export function restoreChatFontSize() {
return saved ? applyFontSize(saved) : false;
}
/**
* 绑定字号选择器事件。
*
* @returns {void}
*/
export function bindChatFontSizeControl() {
if (fontSizeEventsBound || typeof document === "undefined") {
return;
}
fontSizeEventsBound = true;
document.addEventListener("change", (event) => {
if (!(event.target instanceof HTMLSelectElement) || event.target.id !== "font_size_select") {
return;
}
applyFontSize(event.target.value);
});
}