Update mangafire/mangafire.js

This commit is contained in:
aka paul
2026-03-05 21:20:30 +00:00
parent bf095bc654
commit 083098d20e
+11 -12
View File
@@ -1,4 +1,4 @@
async function searchResults(input,page=0){ async function searchResults(input, page = 0) {
function parseSearchResults(html) { function parseSearchResults(html) {
const results = []; const results = [];
const regex = /<div class="unit item-\d+">[\s\S]*?<a href="\/manga\/([\w\-\.]+)"[^>]*class="poster"[\s\S]*?<img src="([^"]*)"[^>]*alt="([^"]*)"/g; const regex = /<div class="unit item-\d+">[\s\S]*?<a href="\/manga\/([\w\-\.]+)"[^>]*class="poster"[\s\S]*?<img src="([^"]*)"[^>]*alt="([^"]*)"/g;
@@ -13,7 +13,9 @@ async function searchResults(input,page=0){
} }
return results; return results;
} const vrf = generate_vrf(input); }
const vrf = generate_vrf(input);
const response = await fetch("https://mangafire.to/filter?keyword=" + encodeURIComponent(input) + "&vrf=" + vrf); const response = await fetch("https://mangafire.to/filter?keyword=" + encodeURIComponent(input) + "&vrf=" + vrf);
const data = await response.text(); const data = await response.text();
console.log(JSON.stringify(parseSearchResults(data))); console.log(JSON.stringify(parseSearchResults(data)));
@@ -32,15 +34,13 @@ async function extractDetails(url) {
const uniqueTags = [...new Set(tags)]; const uniqueTags = [...new Set(tags)];
const ogDescriptionRegex = const ogDescriptionRegex = /<meta property="og:description" content=['"]([^'"]*)['"]/i;
/<meta property="og:description" content=['"]([^'"]*)['"]/i;
const ogMatch = htmlContent.match(ogDescriptionRegex); const ogMatch = htmlContent.match(ogDescriptionRegex);
let description = ogMatch ? ogMatch[1] : ""; let description = ogMatch ? ogMatch[1] : "";
if (!description) { if (!description) {
const metaDescriptionRegex = const metaDescriptionRegex = /<meta name="description" content=['"]([^'"]*)['"]/i;
/<meta name="description" content=['"]([^'"]*)['"]/i;
const metaMatch = htmlContent.match(metaDescriptionRegex); const metaMatch = htmlContent.match(metaDescriptionRegex);
description = metaMatch ? metaMatch[1] : ""; description = metaMatch ? metaMatch[1] : "";
} }
@@ -73,17 +73,17 @@ async function extractChapters(url) {
const mangaIdMatch = url.match(/\.([a-z0-9]+)$/); const mangaIdMatch = url.match(/\.([a-z0-9]+)$/);
const mangaId = mangaIdMatch ? mangaIdMatch[1] : null; const mangaId = mangaIdMatch ? mangaIdMatch[1] : null;
vrf = generate_vrf(`${mangaId}@chapter@en`);
if (!mangaId) { if (!mangaId) {
console.error("Could not extract manga ID from URL"); console.error("Could not extract manga ID from URL");
return null; return null;
} }
const vrf = generate_vrf(`${mangaId}@chapter@en`);
function parseChapters(htmlContent) { function parseChapters(htmlContent) {
const chapters = {}; const chapters = {};
const chapterRegex = const chapterRegex = /<a href="\/read\/[^"]+\/([^/]+)\/chapter-[^"]*" data-number="([^"]+)" data-id="([^"]+)"[^>]*>(.*?)<\/a>/gs;
/<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) {
@@ -131,7 +131,7 @@ async function extractChapters(url) {
} }
async function extractImages(ID) { async function extractImages(ID) {
vrf = generate_vrf(`chapter@${ID}`); const vrf = generate_vrf(`chapter@${ID}`);
try { try {
const response = await fetch(`https://mangafire.to/ajax/read/chapter/${ID}?vrf=${vrf}`); const response = await fetch(`https://mangafire.to/ajax/read/chapter/${ID}?vrf=${vrf}`);
@@ -145,9 +145,8 @@ async function extractImages(ID) {
console.error("Invalid response from server"); console.error("Invalid response from server");
return null; return null;
} }
} catch (error) { } catch (error) {
console.error("Error fetching chapters:" + error); console.error("Error fetching images:" + error);
return null; return null;
} }
} }