| 75 | |
| 76 | // 查找聊天应用窗口 |
| 77 | function findChatWindow(): Window | null { |
| 78 | // 检查是否有特定的 iframe |
| 79 | const chatIframe = document.querySelector( |
| 80 | 'iframe[src*="chat"], iframe[name="chat"]' |
| 81 | ) as HTMLIFrameElement |
| 82 | |
| 83 | if (chatIframe && chatIframe.contentWindow) { |
| 84 | return chatIframe.contentWindow |
| 85 | } |
| 86 | |
| 87 | // 检查所有 iframe |
| 88 | const iframes = document.querySelectorAll("iframe") |
| 89 | for (const iframe of iframes) { |
| 90 | if (iframe.contentWindow) { |
| 91 | return iframe.contentWindow |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // 如果没有 iframe,返回当前窗口 |
| 96 | return window |
| 97 | } |
| 98 | |
| 99 | // 监听来自聊天应用的响应 |
| 100 | window.addEventListener("message", (event) => { |