Update comix/comix.js

This commit is contained in:
aka paul 2025-12-09 22:18:29 +00:00
parent 6658673165
commit 363a942e85

View file

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