迁移聊天室前端工具并优化消息渲染

This commit is contained in:
2026-04-25 03:34:31 +08:00
parent e3cba255f9
commit f1d8d20180
12 changed files with 786 additions and 154 deletions
+45
View File
@@ -0,0 +1,45 @@
// 聊天室字号偏好控制,保留旧的 localStorage key 以兼容已有用户设置。
export const CHAT_FONT_SIZE_STORAGE_KEY = "chat_font_size";
/**
* 应用字号到聊天消息窗口,并保存到 localStorage。
*
* @param {string|number} size 字号大小
* @returns {boolean}
*/
export function applyFontSize(size) {
const px = Number.parseInt(size, 10);
if (Number.isNaN(px) || px < 10 || px > 30) {
return false;
}
const publicContainer = document.getElementById("chat-messages-container");
const privateContainer = document.getElementById("chat-messages-container2");
if (publicContainer) {
publicContainer.style.fontSize = `${px}px`;
}
if (privateContainer) {
privateContainer.style.fontSize = `${px}px`;
}
localStorage.setItem(CHAT_FONT_SIZE_STORAGE_KEY, String(px));
const selector = document.getElementById("font_size_select");
if (selector) {
selector.value = String(px);
}
return true;
}
/**
* 从 localStorage 恢复已保存的聊天室字号。
*
* @returns {boolean}
*/
export function restoreChatFontSize() {
const saved = localStorage.getItem(CHAT_FONT_SIZE_STORAGE_KEY);
return saved ? applyFontSize(saved) : false;
}