diff --git a/comix/comix.js b/comix/comix.js index fd09aee..186cf74 100644 --- a/comix/comix.js +++ b/comix/comix.js @@ -71,20 +71,24 @@ async function getChapters(url) { allItems.reverse(); + const chaptersMap = new Map(); allItems.forEach(item => { - results.push([ - String(item.number), - [{ - id: url + "/" + item.chapter_id + "-chapter-" + item.number, - title: item.name || `Chapter ${item.number}`, - chapter: item.number, - scanlation_group: item.scanlation_group?.name || "Comix" - }] - ]); + const chapterNum = String(item.number); + if (!chaptersMap.has(chapterNum)) { + chaptersMap.set(chapterNum, [ + chapterNum, + [{ + id: url + "/" + item.chapter_id + "-chapter-" + item.number, + title: item.name || `Chapter ${item.number}`, + chapter: item.number, + scanlation_group: item.scanlation_group?.name || "Comix" + }] + ]); + } }); return { - en: results + en: Array.from(chaptersMap.values()) }; } catch (err) { return { @@ -94,6 +98,7 @@ async function getChapters(url) { } async function getChapterImages(url) { + const results = []; try { const response = await fetch("https://comix.to/title/" + url); const html = await response.text(); @@ -101,12 +106,16 @@ async function getChapterImages(url) { const match = html.match(/\\"images\\":\[([^\]]+)\]/); if (match) { const imagesJson = '[' + match[1].replace(/\\"/g, '"') + ']'; - const urls = JSON.parse(imagesJson); - return urls; + const images = JSON.parse(imagesJson); + const imageUrls = images.map(img => img.url); + results.push(...imageUrls); + return results; + } else { + console.error("Invalid response from server"); + return []; } - return []; - } catch (err) { - console.error(err); + } catch (error) { + console.error("Error fetching chapters: " + error); return []; } } \ No newline at end of file