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);
|
|
|
|
|
|
|
|
|
|
// 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 }));
|
|
|
|
|
});
|
|
|
|
|
});
|