Agent_For_Supmea/content.js
2026-01-11 17:50:27 +08:00

19 lines
613 B
JavaScript

const script = document.createElement('script');
script.type = 'module';
script.src = chrome.runtime.getURL('main.js');
document.head.appendChild(script);
// 2. 监听来自网页(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 }));
});
});