完善一下

This commit is contained in:
go0p
2024-05-15 14:43:04 +08:00
committed by go0p
parent 26c3bbc570
commit 6358fc720d
14 changed files with 299 additions and 373 deletions
+5 -5
View File
@@ -4,12 +4,12 @@
}
window.contentScriptInjected = true;
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === 'INJECT_CODE') {
if (request.type === 'yakit_inject_script') {
const injectedScriptURL = chrome.runtime.getURL('inject.js');
const script = document.createElement('script');
script.src = injectedScriptURL;
script.onload = () => {
window.postMessage({ type: 'CALL_FUNCTION', value: request.value }, '*');
window.postMessage({type: request.value.mode, value: request.value}, '*');
script.remove();
};
(document.head || document.documentElement).appendChild(script);
@@ -19,10 +19,10 @@
}
window.removeEventListener('message', onMessage);
// Send the result to the background script
chrome.runtime.sendMessage({ action: 'SEND_RES_FROM_PAGE', result: event.data.result });
sendResponse({ result: event.data.result });
// chrome.runtime.sendMessage({ action: 'yakit_to_extension_page', result: event.data.result });
// 直接向向发送端返回结果
sendResponse({action: 'yakit_to_extension_page', result: event.data.result});
});
// Return true to indicate that the response will be sent asynchronously
return true;
}
});