haixunMaster/extension/haixun-threads-sync/content-haixun.js

39 lines
963 B
JavaScript
Raw Normal View History

2026-06-21 12:50:31 +00:00
window.addEventListener("message", (event) => {
if (event.source !== window) return;
if (event.data?.type === "HAIXUN_PING_EXTENSION") {
window.postMessage({ type: "HAIXUN_EXTENSION_READY" }, "*");
return;
}
if (event.data?.type !== "HAIXUN_REQUEST_THREADS_SYNC") return;
chrome.runtime
.sendMessage({
action: "sync",
serverUrl: event.data.serverUrl ?? window.location.origin,
accountId: event.data.accountId,
})
.then((result) => {
window.postMessage(
{
type: "HAIXUN_THREADS_SYNC_RESULT",
...result,
},
"*"
);
})
.catch((error) => {
window.postMessage(
{
type: "HAIXUN_THREADS_SYNC_RESULT",
success: false,
valid: false,
message: error instanceof Error ? error.message : "同步失敗",
},
"*"
);
});
});
window.postMessage({ type: "HAIXUN_EXTENSION_READY" }, "*");