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