迁移屏蔠菜单事件绑定

This commit is contained in:
2026-04-25 03:45:30 +08:00
parent cf42071c29
commit 1429dee8a6
3 changed files with 36 additions and 3 deletions
+4
View File
@@ -9,6 +9,7 @@ export {
BLOCKABLE_SYSTEM_SENDERS,
BLOCKED_SYSTEM_SENDERS_STORAGE_KEY,
CHAT_SOUND_MUTED_STORAGE_KEY,
bindBlockMenuControls,
bindSoundMuteControl,
isSoundMuted,
loadBlockedSystemSenders,
@@ -38,6 +39,7 @@ import {
BLOCKABLE_SYSTEM_SENDERS,
BLOCKED_SYSTEM_SENDERS_STORAGE_KEY,
CHAT_SOUND_MUTED_STORAGE_KEY,
bindBlockMenuControls,
bindSoundMuteControl,
isSoundMuted,
loadBlockedSystemSenders,
@@ -74,6 +76,7 @@ if (typeof window !== "undefined") {
BLOCKABLE_SYSTEM_SENDERS,
BLOCKED_SYSTEM_SENDERS_STORAGE_KEY,
CHAT_SOUND_MUTED_STORAGE_KEY,
bindBlockMenuControls,
bindSoundMuteControl,
isSoundMuted,
loadBlockedSystemSenders,
@@ -99,4 +102,5 @@ if (typeof window !== "undefined") {
bindChatImageUploadControl();
bindChatRightPanelControls();
bindMobileDrawerControls();
bindBlockMenuControls();
}
@@ -4,6 +4,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;
let blockMenuEventsBound = false;
/**
* 规整聊天室偏好对象,过滤非法配置并补齐默认值。
@@ -167,6 +168,35 @@ export function bindSoundMuteControl(onChange) {
});
}
/**
* 绑定系统播报屏蔽菜单打开与菜单内点击拦截事件。
*
* @returns {void}
*/
export function bindBlockMenuControls() {
if (blockMenuEventsBound || typeof document === "undefined") {
return;
}
blockMenuEventsBound = true;
document.addEventListener("click", (event) => {
if (!(event.target instanceof Element)) {
return;
}
const trigger = event.target.closest("[data-chat-block-menu-toggle]");
if (trigger) {
event.preventDefault();
window.toggleBlockMenu?.(event);
return;
}
if (event.target.closest("[data-chat-block-menu]")) {
event.stopPropagation();
}
});
}
/**
* 当前登录账号没有服务端偏好时,判断是否需要迁移旧本地偏好。
*