迁移静音开关事件绑定
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<void>} 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录账号没有服务端偏好时,判断是否需要迁移旧本地偏好。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user