Agent_For_Supmea/content.js

19 lines
597 B
JavaScript
Raw Normal View History

2026-01-02 21:06:54 +08:00
const script = document.createElement('script');
script.type = 'module';
script.src = chrome.runtime.getURL('main.js');
2026-01-11 12:22:49 +08:00
document.head.appendChild(script);
2026-01-22 13:43:59 +08:00
// 监听来自 main.js 的请求
2026-01-11 12:22:49 +08:00
window.addEventListener("DO_AI_REQUEST", async (event) => {
const { userInput, systemPrompt } = event.detail;
// 转发给 background.js
chrome.runtime.sendMessage({
type: "AI_TRANSLATE",
userInput,
systemPrompt
}, (response) => {
2026-01-22 13:43:59 +08:00
// 将结果传回给 main.js
2026-01-11 12:22:49 +08:00
window.dispatchEvent(new CustomEvent("AI_RESULT", { detail: response }));
});
});