Feat: 输入栏增加字号选择器,自动应用到聊天窗口并持久化到localStorage
This commit is contained in:
@@ -42,6 +42,19 @@
|
|||||||
style="width: 22px; height: 18px; padding: 0; border: 1px solid navy; cursor: pointer;">
|
style="width: 22px; height: 18px; padding: 0; border: 1px solid navy; cursor: pointer;">
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<label>字号:
|
||||||
|
<select id="font_size_select" style="color: #224466;" onchange="applyFontSize(this.value)">
|
||||||
|
<option value="12">12</option>
|
||||||
|
<option value="13">13</option>
|
||||||
|
<option value="14" selected>14</option>
|
||||||
|
<option value="15">15</option>
|
||||||
|
<option value="16">16</option>
|
||||||
|
<option value="18">18</option>
|
||||||
|
<option value="20">20</option>
|
||||||
|
<option value="22">22</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
<label title="仅对方和自己可见">
|
<label title="仅对方和自己可见">
|
||||||
<input type="checkbox" id="is_secret" name="is_secret" value="1">
|
<input type="checkbox" id="is_secret" name="is_secret" value="1">
|
||||||
悄悄话
|
悄悄话
|
||||||
|
|||||||
@@ -653,6 +653,40 @@
|
|||||||
}
|
}
|
||||||
window.triggerEffect = triggerEffect;
|
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 发送) ───────────────────────
|
// ── 发送消息(Enter 发送) ───────────────────────
|
||||||
document.getElementById('content').addEventListener('keydown', function(e) {
|
document.getElementById('content').addEventListener('keydown', function(e) {
|
||||||
if (e.key === 'Enter' && !e.shiftKey) {
|
if (e.key === 'Enter' && !e.shiftKey) {
|
||||||
|
|||||||
Reference in New Issue
Block a user