diff --git a/comix/comix.js b/comix/comix.js new file mode 100644 index 0000000..c8a6d95 --- /dev/null +++ b/comix/comix.js @@ -0,0 +1,112 @@ +async function searchContent(keyword, page = 0) { + try { + const response = await fetch("https://comix.to/api/v2/manga?order[relevance]=desc&keyword=" + encodeURIComponent(keyword) + "&limit=100"); + const data = await response.json(); + + const results = data.result.items.map(manga => ({ + title: manga.title, + image: manga.poster.large, + href: manga.hash_id + "-" + manga.slug + })); + + return results; + } catch (err) { + return []; + } +} + +async function getContentData(slug) { + try { + const response = await fetch("https://comix.to/title/" + slug); + const html = await response.text(); + const descriptionMatch = html.match(/', + '"': '"' + }; + text = text.replace(/'|&|<|>|"/g, match => htmlEntities[match] || match); + text = text.replace(/\[([^\]]+)\]\([^\)]+\)/g, '$1'); + text = text.replace(/[*_~`]/g, ''); + text = text.replace(/___.*$/g, ''); + text = text.replace(/[\n\r\t]+/g, ' ').replace(/\s+/g, ' '); + return text.trim(); + } + + return { + description: cleanDescription({ description }), + tags: [] + }; + } catch (err) { + return { + description: "Error", + tags: [] + }; + } +} + +async function getChapters(url) { + const hash = url.split("-")[0] + const results = []; + try { + const firstResponse = await fetch("https://comix.to/api/v2/manga/" + hash + "/chapters?limit=100&page=1&order[number]=desc") + const firstData = await firstResponse.json(); + const lastPage = firstData.result.pagination.last_page; + let allItems = []; + + for (let page = 1; page <= lastPage; page++) { + const response = await fetch("https://comix.to/api/v2/manga/" + hash + "/chapters?limit=100&page=" + page + "&order[number]=desc") + const data = await response.json(); + allItems = allItems.concat(data.result.items); + } + + allItems.reverse(); + + 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" + }] + ]); + }); + + return { + en: results + }; + } catch (err) { + return { + en: [] + }; + } +} + +async function getChapterImages(url) { + try { + const response = await fetch("https://comix.to/title/" + url); + const html = await response.text(); + + const match = html.match(/\\"images\\":\[([^\]]+)\]/); + if (match) { + const imagesJson = '[' + match[1].replace(/\\"/g, '"') + ']'; + const urls = JSON.parse(imagesJson); + return urls; + } + return []; + } catch (err) { + console.error(err); + return []; + } +} \ No newline at end of file