mirror of
https://git.luna-app.eu/50n50/sources
synced 2025-12-21 21:26:19 +01:00
Add comix/comix.js
This commit is contained in:
parent
e8a813381d
commit
750991fa6b
1 changed files with 112 additions and 0 deletions
112
comix/comix.js
Normal file
112
comix/comix.js
Normal file
|
|
@ -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(/<meta name="description" content="([^"]*)"/);
|
||||
const description = descriptionMatch ? descriptionMatch[1] : "";
|
||||
|
||||
function cleanDescription(obj) {
|
||||
if (!obj.description) return '';
|
||||
|
||||
let text = obj.description;
|
||||
|
||||
const htmlEntities = {
|
||||
''': "'",
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"'
|
||||
};
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue