This commit is contained in:
Joey Yakimowich-Payne 2025-10-14 12:51:11 -06:00
commit c5f9dad0f9
18 changed files with 1845 additions and 0 deletions

28
firefox/background.js Normal file
View file

@ -0,0 +1,28 @@
import { SafariBooksDownloader } from "./safaribooks/downloader.js";
import { collectSessionCookies } from "./safaribooks/cookies.js";
const runtime = typeof browser !== "undefined" ? browser : chrome;
const downloader = new SafariBooksDownloader((message) => {
console.log(`[BackgroundDownloader] ${message}`);
});
runtime.runtime.onMessage.addListener(async (message) => {
if (message?.type !== "downloadBook") {
return undefined;
}
const { bookId, theme = "none", kindle = false } = message;
if (!bookId) {
return { ok: false, error: "Missing book ID." };
}
try {
await collectSessionCookies();
await downloader.download(bookId, { theme, kindle });
return { ok: true };
} catch (error) {
console.error("[BackgroundDownloader] Download failed:", error);
return { ok: false, error: error.message };
}
});