Fix silent market CSV export

This commit is contained in:
2026-04-29 11:33:00 +08:00
parent fe60253cd3
commit 07d1dffe78
12 changed files with 2255 additions and 171 deletions
+22 -1
View File
@@ -39,15 +39,18 @@ export async function bootContentScript(
return null;
}
installMarketPageBridge(currentDocument);
const authState = await readAuthState(sendAuthMessage);
if (!authState?.isAuthenticated) {
await waitForBodyReady(currentDocument, currentWindow);
renderMarketAuthGate(currentDocument, currentWindow);
return {
ready: Promise.resolve()
};
}
installMarketPageBridge(currentDocument);
await waitForBodyReady(currentDocument, currentWindow);
return controllerFactory({
document: currentDocument,
@@ -144,6 +147,24 @@ function createRuntimeMessageSender(): (message: unknown) => Promise<unknown> {
};
}
async function waitForBodyReady(document: Document, currentWindow: Window): Promise<void> {
if (document.body) {
return;
}
await new Promise<void>((resolve) => {
const handleReady = () => {
if (document.body) {
document.removeEventListener("DOMContentLoaded", handleReady);
resolve();
}
};
document.addEventListener("DOMContentLoaded", handleReady);
currentWindow.setTimeout(handleReady, 0);
});
}
function downloadCsv(document: Document, window: Window, csv: string): void {
const blob = new Blob(["\uFEFF", csv], {
type: "text/csv;charset=utf-8"