Files
sources/mangabuddy/mangabuddy.js
T

114 lines
4.0 KiB
JavaScript
Raw Normal View History

2026-06-03 18:03:15 +02:00
async function searchResults(keyword, page = 0) {
2025-11-30 18:57:55 +00:00
const results = [];
try {
2026-06-03 18:03:15 +02:00
const response = await fetch("https://mangak.io/search?q=" + encodeURIComponent(keyword));
2025-11-30 18:57:55 +00:00
const html = await response.text();
2026-06-03 18:03:15 +02:00
const jsonRegex = /<script id="__NEXT_DATA__" type="application\/json">([\s\S]*?)<\/script>/;
const match = jsonRegex.exec(html);
if (match) {
const data = JSON.parse(match[1]);
const items = data.props?.pageProps?.ssrItems || [];
for (const item of items) {
if (item.url && item.name && item.id) {
results.push({
id: "https://mangak.io" + item.url.trim() + " | " + item.id.trim(),
imageURL: "https://passthrough-worker.simplepostrequest.workers.dev/?simple=" + (item.cover || "").trim() + "&referer=https://mangabuddy.com",
title: item.name.trim()
});
}
}
2025-11-30 18:57:55 +00:00
}
return results;
} catch (err) {
return [];
}
}
2026-01-14 00:07:39 +01:00
async function extractDetails(url) {
2025-11-30 18:57:55 +00:00
try {
2026-06-03 18:03:15 +02:00
const [urlPart] = url.split(" | ");
const response = await fetch(urlPart);
2025-11-30 18:57:55 +00:00
const html = await response.text();
const descRegex = /<meta name="description" content="([^"]+)"/i;
const descMatch = descRegex.exec(html);
const description = descMatch ? descMatch[1].trim() : "";
return {
description: description.replace(" - not found...", "").trim(),
tags: []
};
} catch (err) {
return {
description: "Error",
tags: []
};
}
}
2026-01-14 00:07:39 +01:00
async function extractChapters(url) {
2025-11-30 18:57:55 +00:00
const results = [];
try {
2026-06-03 18:03:15 +02:00
const [, titleId] = url.split(" | ");
if (!titleId) return { en: [] };
2025-11-30 18:57:55 +00:00
2026-06-03 18:03:15 +02:00
const chapUrl = `https://api.mangak.io/titles/${titleId.trim()}/chapters`;
2025-11-30 18:57:55 +00:00
const chapResponse = await fetch(chapUrl);
2026-06-03 18:03:15 +02:00
const chapJson = await chapResponse.json();
if (!chapJson.success || !chapJson.data || !chapJson.data.chapters) {
return { en: [] };
}
const chapters = chapJson.data.chapters;
for (const chapter of chapters) {
const match = /(\d+(?:\.\d+)?)/.exec(chapter.name);
const chapterNum = match ? match[1] : String(chapter.chapter_number || 0);
2025-11-30 18:57:55 +00:00
results.push([
String(chapterNum),
[{
2026-06-03 18:03:15 +02:00
id: "https://mangak.io" + chapter.url,
chapter: parseFloat(chapterNum) || 0,
scanlation_group: chapter.name || `Chapter ${chapterNum}`
2025-11-30 18:57:55 +00:00
}]
]);
}
results.reverse();
return { en: results };
} catch (err) {
return { en: [] };
}
}
2026-01-14 00:07:39 +01:00
async function extractImages(url) {
2025-11-30 18:57:55 +00:00
const results = [];
try {
const response = await fetch(url);
const html = await response.text();
2026-06-03 18:03:15 +02:00
const jsonRegex = /<script id="__NEXT_DATA__" type="application\/json">([\s\S]*?)<\/script>/;
const match = jsonRegex.exec(html);
2025-11-30 18:57:55 +00:00
if (match) {
2026-06-03 18:03:15 +02:00
const data = JSON.parse(match[1]);
const images = data.props?.pageProps?.initialChapter?.images || [];
2025-11-30 19:12:51 +00:00
const processedImages = images.map(img => "https://passthrough-worker.simplepostrequest.workers.dev/?simple=" + img.trim() + "&referer=https://mangabuddy.com");
2025-11-30 19:04:33 +00:00
results.push(...processedImages);
2026-06-03 18:03:15 +02:00
} else {
const regex = /var chapImages = '([^']*)'/;
const legacyMatch = regex.exec(html);
if (legacyMatch) {
const images = legacyMatch[1].split(',');
const processedImages = images.map(img => "https://passthrough-worker.simplepostrequest.workers.dev/?simple=" + img.trim() + "&referer=https://mangabuddy.com");
results.push(...processedImages);
}
2025-11-30 18:57:55 +00:00
}
return results;
} catch (err) {
return [];
}
}