From 7c46ff0f137797d88cbfa50cd2150d4b5fb358d2 Mon Sep 17 00:00:00 2001 From: lhk1337 <25325997+lhk1337@users.noreply.github.com> Date: Sun, 23 Jan 2022 17:54:52 +0100 Subject: [PATCH] allow downloading selected chapters in separate files --- src/pages/[manga]/index.svelte | 44 +++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/pages/[manga]/index.svelte b/src/pages/[manga]/index.svelte index 56f532b..00db6ec 100644 --- a/src/pages/[manga]/index.svelte +++ b/src/pages/[manga]/index.svelte @@ -83,15 +83,10 @@ cbz: CBZGenerator } - async function downloadSingle(chapter) { - const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, { - writableStrategy: undefined, // (optional) - readableStrategy: undefined, // (optional) - }); - - const generator = new generators[format]({ + function createGenerator(chapter, file) { + return new generators[format]({ file, - id: chapter.id, + id: window.location.toString() + "-" + chapter.id, language: chapter.attributes.translatedLanguage, updatedAt: chapter.attributes.updatedAt, title: manga.title.en, @@ -102,6 +97,14 @@ volume: chapter.attributes.volume }] }); + } + async function downloadSingle(chapter) { + const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, { + writableStrategy: undefined, // (optional) + readableStrategy: undefined, // (optional) + }); + + const generator = createGenerator(chapter, file) console.log(generator); queue.push(generator); @@ -154,6 +157,30 @@ selected = []; processQueue(); } + function downloadSeparate() { + selected.sort((a, b) => a.attributes.chapter - b.attributes.chapter); + if(!selected.length) return; + if(selected.length === 1) { + downloadSingle(selected.shift()); + selected = []; + return; + } + + for (const chapter of selected) { + const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, { + writableStrategy: undefined, // (optional) + readableStrategy: undefined, // (optional) + }); + + const generator = createGenerator(chapter, file) + + console.log(generator); + queue.push(generator); + } + + selected = []; + processQueue(); + } /** * @param {BeforeUnloadEvent} e @@ -230,6 +257,7 @@ +