Update mangafire/mangafire.js

This commit is contained in:
aka paul
2026-03-05 21:20:30 +00:00
parent bf095bc654
commit 083098d20e
+126 -127
View File
@@ -1,155 +1,154 @@
async function searchResults(input,page=0){
function parseSearchResults(html) {
const results = [];
const regex = /<div class="unit item-\d+">[\s\S]*?<a href="\/manga\/([\w\-\.]+)"[^>]*class="poster"[\s\S]*?<img src="([^"]*)"[^>]*alt="([^"]*)"/g;
let match;
while ((match = regex.exec(html)) !== null) {
results.push({
title: match[3],
imageURL: match[2],
id: match[1]
});
async function searchResults(input, page = 0) {
function parseSearchResults(html) {
const results = [];
const regex = /<div class="unit item-\d+">[\s\S]*?<a href="\/manga\/([\w\-\.]+)"[^>]*class="poster"[\s\S]*?<img src="([^"]*)"[^>]*alt="([^"]*)"/g;
let match;
while ((match = regex.exec(html)) !== null) {
results.push({
title: match[3],
imageURL: match[2],
id: match[1]
});
}
return results;
}
return results;
} const vrf = generate_vrf(input);
const response = await fetch("https://mangafire.to/filter?keyword=" + encodeURIComponent(input) + "&vrf=" + vrf);
const data = await response.text();
console.log(JSON.stringify(parseSearchResults(data)));
return parseSearchResults(data);
const vrf = generate_vrf(input);
const response = await fetch("https://mangafire.to/filter?keyword=" + encodeURIComponent(input) + "&vrf=" + vrf);
const data = await response.text();
console.log(JSON.stringify(parseSearchResults(data)));
return parseSearchResults(data);
}
async function extractDetails(url) {
function parseHtmlData(htmlContent) {
const genreRegex = /<a href="\/genre\/[^"]*">([^<]+)<\/a>/g;
const tags = [];
let match;
function parseHtmlData(htmlContent) {
const genreRegex = /<a href="\/genre\/[^"]*">([^<]+)<\/a>/g;
const tags = [];
let match;
while ((match = genreRegex.exec(htmlContent)) !== null) {
if (match[1].trim()) tags.push(match[1].trim());
while ((match = genreRegex.exec(htmlContent)) !== null) {
if (match[1].trim()) tags.push(match[1].trim());
}
const uniqueTags = [...new Set(tags)];
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=['"]([^'"]*)['"]/i;
const metaMatch = htmlContent.match(metaDescriptionRegex);
description = metaMatch ? metaMatch[1] : "";
}
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 {
description: description,
tags: uniqueTags
};
}
const uniqueTags = [...new Set(tags)];
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=['"]([^'"]*)['"]/i;
const metaMatch = htmlContent.match(metaDescriptionRegex);
description = metaMatch ? metaMatch[1] : "";
}
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 {
description: description,
tags: uniqueTags
};
}
const response = await fetch(`https://mangafire.to${url}`);
const data = await response.text();
console.log(JSON.stringify(parseHtmlData(data)));
return parseHtmlData(data);
const response = await fetch(`https://mangafire.to${url}`);
const data = await response.text();
console.log(JSON.stringify(parseHtmlData(data)));
return parseHtmlData(data);
}
async function extractChapters(url) {
const mangaIdMatch = url.match(/\.([a-z0-9]+)$/);
const mangaId = mangaIdMatch ? mangaIdMatch[1] : null;
const mangaIdMatch = url.match(/\.([a-z0-9]+)$/);
const mangaId = mangaIdMatch ? mangaIdMatch[1] : null;
vrf = generate_vrf(`${mangaId}@chapter@en`);
if (!mangaId) {
console.error("Could not extract manga ID from URL");
return null;
}
if (!mangaId) {
console.error("Could not extract manga ID from URL");
return null;
}
const vrf = generate_vrf(`${mangaId}@chapter@en`);
function parseChapters(htmlContent) {
const chapters = {};
const chapters = {};
const chapterRegex =
/<a href="\/read\/[^"]+\/([^/]+)\/chapter-[^"]*" data-number="([^"]+)" data-id="([^"]+)"[^>]*>(.*?)<\/a>/gs;
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].replace(/<[^>]*>/g, '').trim();
let match;
while ((match = chapterRegex.exec(htmlContent)) !== null) {
const langCode = match[1];
const chapterNumber = match[2];
const chapterId = match[3];
const title = match[4].replace(/<[^>]*>/g, '').trim();
if (!chapters[langCode]) chapters[langCode] = [];
if (!chapters[langCode]) chapters[langCode] = [];
chapters[langCode].push([
chapterNumber,
[
{
id: chapterId,
title: title,
chapter: Number(chapterNumber),
scanlation_group: "Mangafire"
}
]
]);
chapters[langCode].push([
chapterNumber,
[
{
id: chapterId,
title: title,
chapter: Number(chapterNumber),
scanlation_group: "Mangafire"
}
]
]);
}
Object.keys(chapters).forEach(lang => chapters[lang].reverse());
return chapters;
}
Object.keys(chapters).forEach(lang => chapters[lang].reverse());
try {
const response = await fetch(`https://mangafire.to/ajax/read/${mangaId}/chapter/en?vrf=${vrf}`);
const data = await response.json();
return chapters;
if (data.status === 200 && data.result && data.result.html) {
const chapters = parseChapters(data.result.html);
console.log(JSON.stringify(chapters));
return chapters;
} else {
console.error("Invalid response from server");
return null;
}
} catch (error) {
console.error("Error fetching chapters:" + error);
return null;
}
try {
const response = await fetch(`https://mangafire.to/ajax/read/${mangaId}/chapter/en?vrf=${vrf}`);
const data = await response.json();
if (data.status === 200 && data.result && data.result.html) {
const chapters = parseChapters(data.result.html);
console.log(JSON.stringify(chapters));
return chapters;
} else {
console.error("Invalid response from server");
return null;
}
} catch (error) {
console.error("Error fetching chapters:" + error);
return null;
}
}
async function extractImages(ID) {
vrf = generate_vrf(`chapter@${ID}`);
async function extractImages(ID) {
const vrf = generate_vrf(`chapter@${ID}`);
try {
const response = await fetch(`https://mangafire.to/ajax/read/chapter/${ID}?vrf=${vrf}`);
const data = await response.json();
if (data.status === 200 && data.result && data.result.images) {
const images = data.result.images.map(img => img[0]);
console.log(JSON.stringify(images));
return images;
} else {
console.error("Invalid response from server");
return null;
try {
const response = await fetch(`https://mangafire.to/ajax/read/chapter/${ID}?vrf=${vrf}`);
const data = await response.json();
if (data.status === 200 && data.result && data.result.images) {
const images = data.result.images.map(img => img[0]);
console.log(JSON.stringify(images));
return images;
} else {
console.error("Invalid response from server");
return null;
}
} catch (error) {
console.error("Error fetching images:" + error);
return null;
}
} catch (error) {
console.error("Error fetching chapters:" + error);
return null;
}
}
function b64encode(data) {