add proxy switch demo

This commit is contained in:
go0p
2026-08-06 15:11:35 +08:00
committed by go0p
parent 0407229e05
commit 57545ae80f
28 changed files with 12458 additions and 28 deletions
+7 -3
View File
@@ -3,6 +3,7 @@
return;
}
window.contentScriptInjected = true;
window.badgeCount = 0;
// 检查并插入 CSS 样式
const styleId = 'injected-css-style';
if (!document.getElementById(styleId)) {
@@ -38,18 +39,21 @@
script.remove();
};
(document.head || document.documentElement).appendChild(script);
window.addEventListener('message', function onMessage(event) {
window.addEventListener('message', async function onMessage(event) {
if (event.source !== window || event.data.type !== 'FROM_INJECT_JS') {
return;
}
window.removeEventListener('message', onMessage);
// Send the result to the background script
// chrome.runtime.sendMessage({ action: 'yakit_to_extension_page', result: event.data.result });
window.badgeCount += 1;
// 直接向向发送端返回结果
sendResponse({action: 'yakit_to_extension_page', result: event.data.result});
// Send updated badge count to background script
await chrome.runtime.sendMessage({action: 'yakit_badge', data: window.badgeCount.toString()});
});
return true;
}
});
})()