Update mangafire/mangafire.js

This commit is contained in:
aka paul 2025-11-26 18:24:38 +00:00
parent f44e29009c
commit f004a1ff3a

View file

@ -27,28 +27,42 @@ async function getContentData(url) {
let match; let match;
while ((match = genreRegex.exec(htmlContent)) !== null) { while ((match = genreRegex.exec(htmlContent)) !== null) {
tags.push(match[1]); if (match[1].trim()) tags.push(match[1].trim());
} }
const uniqueTags = [...new Set(tags)]; const uniqueTags = [...new Set(tags)];
const ogDescriptionRegex = /<meta property="og:description" content="([^"]*)"/; const ogDescriptionRegex =
const ogDescriptionMatch = htmlContent.match(ogDescriptionRegex); /<meta property="og:description" content=['"]([^'"]*)['"]/i;
let description = ogDescriptionMatch ? ogDescriptionMatch[1] : ""; const ogMatch = htmlContent.match(ogDescriptionRegex);
let description = ogMatch ? ogMatch[1] : "";
if (!description) { if (!description) {
const metaDescriptionRegex = /<meta name="description" content="([^"]*)"/; const metaDescriptionRegex =
/<meta name="description" content=['"]([^'"]*)['"]/i;
const metaMatch = htmlContent.match(metaDescriptionRegex); const metaMatch = htmlContent.match(metaDescriptionRegex);
description = metaMatch ? metaMatch[1] : ""; description = metaMatch ? metaMatch[1] : "";
} }
description = description.replace(/READ NOW!!\s*$/, "").trim(); description = description
.replace(/(&quot;)/g, '"')
.replace(/(&amp;)/g, '&')
.replace(/(&lt;)/g, '<')
.replace(/(&gt;)/g, '>')
.replace(/\s+/g, ' ')
.trim();
if (uniqueTags.length === 0) {
uniqueTags.push("Unknown");
}
return { return {
tags: uniqueTags, description: description,
description: description tags: uniqueTags
}; };
} }
const response = await fetch(`https://mangafire.to${url}`); const response = await fetch(`https://mangafire.to${url}`);
const data = await response.text(); const data = await response.text();
console.log(JSON.stringify(parseHtmlData(data))); console.log(JSON.stringify(parseHtmlData(data)));
@ -68,32 +82,32 @@ async function getChapters(url) {
function parseChapters(htmlContent) { function parseChapters(htmlContent) {
const chapters = {}; const chapters = {};
const chapterRegex = /<a href="\/read\/[^"]+\/([^/]+)\/chapter-[^"]*" data-number="([^"]+)" data-id="([^"]+)"[^>]*>([^<]+)<\/a>/g; const chapterRegex =
/<a href="\/read\/[^"]+\/([^/]+)\/chapter-[^"]*" data-number="([^"]+)" data-id="([^"]+)"[^>]*>(.*?)<\/a>/gs;
let match; let match;
while ((match = chapterRegex.exec(htmlContent)) !== null) { while ((match = chapterRegex.exec(htmlContent)) !== null) {
const langCode = match[1]; const langCode = match[1];
const chapterNumber = match[2]; const chapterNumber = match[2];
const chapterId = match[3]; const chapterId = match[3];
const title = match[4].trim(); const title = match[4].replace(/<[^>]*>/g, '').trim();
if (!chapters[langCode]) { if (!chapters[langCode]) chapters[langCode] = [];
chapters[langCode] = [];
}
chapters[langCode].push([ chapters[langCode].push([
chapterNumber, chapterNumber,
[
{ {
id: chapterId, id: chapterId,
scanlation_group: "Mangafire", title: title,
title: title chapter: Number(chapterNumber),
scanlation_group: "Mangafire"
} }
]
]); ]);
} }
Object.keys(chapters).forEach(lang => { Object.keys(chapters).forEach(lang => chapters[lang].reverse());
chapters[lang].reverse();
});
return chapters; return chapters;
} }