Feat: 输入栏增加字号选择器,自动应用到聊天窗口并持久化到localStorage
This commit is contained in:
@@ -653,6 +653,40 @@
|
||||
}
|
||||
window.triggerEffect = triggerEffect;
|
||||
|
||||
// ── 字号设置(持久化到 localStorage)─────────────────
|
||||
/**
|
||||
* 应用字号到聊天消息窗口,并保存到 localStorage
|
||||
*
|
||||
* @param {string|number} size 字号大小(px 数字)
|
||||
*/
|
||||
function applyFontSize(size) {
|
||||
const px = parseInt(size, 10);
|
||||
if (isNaN(px) || px < 10 || px > 30) return;
|
||||
|
||||
// 同时应用到公聊窗和包厢窗
|
||||
const c1 = document.getElementById('chat-messages-container');
|
||||
const c2 = document.getElementById('chat-messages-container2');
|
||||
if (c1) c1.style.fontSize = px + 'px';
|
||||
if (c2) c2.style.fontSize = px + 'px';
|
||||
|
||||
// 持久化(key 带房间 ID,不同房间各自记住)
|
||||
const key = 'chat_font_size';
|
||||
localStorage.setItem(key, px);
|
||||
|
||||
// 同步 select 显示
|
||||
const sel = document.getElementById('font_size_select');
|
||||
if (sel) sel.value = String(px);
|
||||
}
|
||||
window.applyFontSize = applyFontSize;
|
||||
|
||||
// 页面加载后从 localStorage 恢复之前保存的字号
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const saved = localStorage.getItem('chat_font_size');
|
||||
if (saved) {
|
||||
applyFontSize(saved);
|
||||
}
|
||||
});
|
||||
|
||||
// ── 发送消息(Enter 发送) ───────────────────────
|
||||
document.getElementById('content').addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
|
||||
Reference in New Issue
Block a user