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

@ -25,30 +25,44 @@ async function getContentData(url) {
const genreRegex = /<a href="\/genre\/[^"]*">([^<]+)<\/a>/g;
const tags = [];
let match;
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 ogDescriptionRegex = /<meta property="og:description" content="([^"]*)"/;
const ogDescriptionMatch = htmlContent.match(ogDescriptionRegex);
let description = ogDescriptionMatch ? ogDescriptionMatch[1] : "";
const ogDescriptionRegex =
/<meta property="og:description" content=['"]([^'"]*)['"]/i;
const ogMatch = htmlContent.match(ogDescriptionRegex);
let description = ogMatch ? ogMatch[1] : "";
if (!description) {
const metaDescriptionRegex = /<meta name="description" content="([^"]*)"/;
const metaMatch = htmlContent.match(metaDescriptionRegex);
description = metaMatch ? metaMatch[1] : "";
const metaDescriptionRegex =
/<meta name="description" content=['"]([^'"]*)['"]/i;
const metaMatch = htmlContent.match(metaDescriptionRegex);
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 {
tags: uniqueTags,
description: description
description: description,
tags: uniqueTags
};
}
const response = await fetch(`https://mangafire.to${url}`);
const data = await response.text();
console.log(JSON.stringify(parseHtmlData(data)));
@ -65,38 +79,38 @@ async function getChapters(url) {
return null;
}
function parseChapters(htmlContent) {
function parseChapters(htmlContent) {
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;
while ((match = chapterRegex.exec(htmlContent)) !== null) {
const langCode = match[1];
const chapterNumber = match[2];
const chapterId = match[3];
const title = match[4].trim();
if (!chapters[langCode]) {
chapters[langCode] = [];
}
chapters[langCode].push([
const langCode = match[1];
const chapterNumber = match[2];
const chapterId = match[3];
const title = match[4].replace(/<[^>]*>/g, '').trim();
if (!chapters[langCode]) chapters[langCode] = [];
chapters[langCode].push([
chapterNumber,
{
id: chapterId,
scanlation_group: "Mangafire",
title: title
}
]);
[
{
id: chapterId,
title: title,
chapter: Number(chapterNumber),
scanlation_group: "Mangafire"
}
]
]);
}
Object.keys(chapters).forEach(lang => {
chapters[lang].reverse();
});
Object.keys(chapters).forEach(lang => chapters[lang].reverse());
return chapters;
}
}
try {
const response = await fetch(`https://mangafire.to/ajax/read/${mangaId}/chapter/en?vrf=${vrf}`);