迁移屏蔠菜单事件绑定

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();
}
});
}
/**
* 当前登录账号没有服务端偏好时,判断是否需要迁移旧本地偏好。
*
@@ -118,12 +118,11 @@ $welcomeMessages = [
</button>
<div style="position:relative;display:inline-block;" id="block-btn-wrap">
<button type="button" onclick="toggleBlockMenu(event)"
<button type="button" data-chat-block-menu-toggle
style="font-size:11px;padding:1px 6px;background:#475569;color:#fff;border:none;border-radius:2px;cursor:pointer;">
🔕 屏蔽
</button>
<div id="block-menu"
onclick="event.stopPropagation()"
<div id="block-menu" data-chat-block-menu
style="display:none;position:absolute;bottom:calc(100% + 6px);left:0;z-index:10020;min-width:168px;padding:10px;background:#f8fafc;border:1px solid #cbd5e1;border-radius:10px;box-shadow:0 10px 24px rgba(15,23,42,.18);">
<div style="font-size:10px;color:#475569;padding:0 2px 8px;">可集中管理播报显示与特效声音</div>
<label