diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index 5c791ee..2e6fe40 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -7,6 +7,7 @@ export { BLOCKABLE_SYSTEM_SENDERS, BLOCKED_SYSTEM_SENDERS_STORAGE_KEY, CHAT_SOUND_MUTED_STORAGE_KEY, + bindSoundMuteControl, isSoundMuted, loadBlockedSystemSenders, normalizeChatPreferences, @@ -32,6 +33,7 @@ import { BLOCKABLE_SYSTEM_SENDERS, BLOCKED_SYSTEM_SENDERS_STORAGE_KEY, CHAT_SOUND_MUTED_STORAGE_KEY, + bindSoundMuteControl, isSoundMuted, loadBlockedSystemSenders, normalizeChatPreferences, @@ -63,6 +65,7 @@ if (typeof window !== "undefined") { BLOCKABLE_SYSTEM_SENDERS, BLOCKED_SYSTEM_SENDERS_STORAGE_KEY, CHAT_SOUND_MUTED_STORAGE_KEY, + bindSoundMuteControl, isSoundMuted, loadBlockedSystemSenders, normalizeChatPreferences, diff --git a/resources/js/chat-room/preferences-status.js b/resources/js/chat-room/preferences-status.js index f451a11..c672622 100644 --- a/resources/js/chat-room/preferences-status.js +++ b/resources/js/chat-room/preferences-status.js @@ -3,6 +3,7 @@ export const BLOCKABLE_SYSTEM_SENDERS = ["钓鱼播报", "星海小博士", "百家乐", "跑马", "神秘箱子"]; export const BLOCKED_SYSTEM_SENDERS_STORAGE_KEY = "chat_blocked_system_senders"; export const CHAT_SOUND_MUTED_STORAGE_KEY = "chat_sound_muted"; +let soundMuteEventsBound = false; /** * 规整聊天室偏好对象,过滤非法配置并补齐默认值。 @@ -137,6 +138,35 @@ export function setSoundMuted(muted) { return normalizedMuted; } +/** + * 绑定禁音复选框事件,后端保存逻辑由调用方提供。 + * + * @param {(muted:boolean)=>void|Promise} onChange 禁音变化回调 + * @returns {void} + */ +export function bindSoundMuteControl(onChange) { + if (soundMuteEventsBound || typeof document === "undefined") { + return; + } + + soundMuteEventsBound = true; + document.addEventListener("change", (event) => { + if (!(event.target instanceof HTMLInputElement) || event.target.id !== "sound_muted") { + return; + } + + const muted = setSoundMuted(event.target.checked); + + if (muted && typeof window.EffectSounds !== "undefined") { + window.EffectSounds.stop(); + } + + if (typeof onChange === "function") { + void onChange(muted); + } + }); +} + /** * 当前登录账号没有服务端偏好时,判断是否需要迁移旧本地偏好。 * diff --git a/resources/views/chat/partials/layout/input-bar.blade.php b/resources/views/chat/partials/layout/input-bar.blade.php index c876462..2c14dad 100644 --- a/resources/views/chat/partials/layout/input-bar.blade.php +++ b/resources/views/chat/partials/layout/input-bar.blade.php @@ -129,7 +129,7 @@ $welcomeMessages = [
可集中管理播报显示与特效声音
diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index f42a22a..0185b3d 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -3328,6 +3328,7 @@ void saveChatPreferences(); } window.toggleSoundMute = toggleSoundMute; + window.ChatRoomTools?.bindSoundMuteControl?.(() => saveChatPreferences()); // ── 发送消息(Enter 发送,防 IME 输入法重复触发)────────