(prompt?: string)
| 115 | |
| 116 | // 截图并发送到聊天 |
| 117 | async function captureAndSendToChat(prompt?: string) { |
| 118 | try { |
| 119 | // 使用 Chrome API 截图 |
| 120 | const dataUrl = await chrome.runtime.sendMessage({ |
| 121 | action: "captureVisibleTab" |
| 122 | }) |
| 123 | |
| 124 | if (dataUrl) { |
| 125 | // 发送图片到聊天 |
| 126 | sendMessageToChat({ |
| 127 | type: "CHAT_INSERT_IMAGE", |
| 128 | payload: { |
| 129 | images: [dataUrl] |
| 130 | } |
| 131 | }) |
| 132 | |
| 133 | // 如果有提示文本,也发送 |
| 134 | if (prompt) { |
| 135 | setTimeout(() => { |
| 136 | sendMessageToChat({ |
| 137 | type: "CHAT_INPUT", |
| 138 | payload: { |
| 139 | text: prompt, |
| 140 | autoSend: false |
| 141 | } |
| 142 | }) |
| 143 | }, 100) |
| 144 | } |
| 145 | } |
| 146 | } catch (error) { |
| 147 | console.error("[Chat Integration] 截图失败:", error) |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // 导出工具函数供其他 content scripts 使用 |
| 152 | export function sendTextToChat(text: string, autoSend = false) { |
no test coverage detected