Agent_For_Supmea/content.js
2026-01-22 13:43:59 +08:00

19 lines
597 B
JavaScript

const script = document.createElement('script');
script.type = 'module';
script.src = chrome.runtime.getURL('main.js');
document.head.appendChild(script);
// 监听来自 main.js 的请求
window.addEventListener("DO_AI_REQUEST", async (event) => {
const { userInput, systemPrompt } = event.detail;
// 转发给 background.js
chrome.runtime.sendMessage({
type: "AI_TRANSLATE",
userInput,
systemPrompt
}, (response) => {
// 将结果传回给 main.js
window.dispatchEvent(new CustomEvent("AI_RESULT", { detail: response }));
});
});