Update mangafire/mangafire.js
This commit is contained in:
+126
-127
@@ -1,155 +1,154 @@
|
|||||||
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;
|
||||||
|
|
||||||
let match;
|
let match;
|
||||||
while ((match = regex.exec(html)) !== null) {
|
while ((match = regex.exec(html)) !== null) {
|
||||||
results.push({
|
results.push({
|
||||||
title: match[3],
|
title: match[3],
|
||||||
imageURL: match[2],
|
imageURL: match[2],
|
||||||
id: match[1]
|
id: match[1]
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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)));
|
return parseSearchResults(data);
|
||||||
return parseSearchResults(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extractDetails(url) {
|
async function extractDetails(url) {
|
||||||
function parseHtmlData(htmlContent) {
|
function parseHtmlData(htmlContent) {
|
||||||
const genreRegex = /<a href="\/genre\/[^"]*">([^<]+)<\/a>/g;
|
const genreRegex = /<a href="\/genre\/[^"]*">([^<]+)<\/a>/g;
|
||||||
const tags = [];
|
const tags = [];
|
||||||
let match;
|
let match;
|
||||||
|
|
||||||
while ((match = genreRegex.exec(htmlContent)) !== null) {
|
while ((match = genreRegex.exec(htmlContent)) !== null) {
|
||||||
if (match[1].trim()) tags.push(match[1].trim());
|
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(/(")/g, '"')
|
||||||
|
.replace(/(&)/g, '&')
|
||||||
|
.replace(/(<)/g, '<')
|
||||||
|
.replace(/(>)/g, '>')
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
if (uniqueTags.length === 0) {
|
||||||
|
uniqueTags.push("Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
description: description,
|
||||||
|
tags: uniqueTags
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const uniqueTags = [...new Set(tags)];
|
const response = await fetch(`https://mangafire.to${url}`);
|
||||||
|
const data = await response.text();
|
||||||
const ogDescriptionRegex =
|
console.log(JSON.stringify(parseHtmlData(data)));
|
||||||
/<meta property="og:description" content=['"]([^'"]*)['"]/i;
|
return parseHtmlData(data);
|
||||||
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(/(")/g, '"')
|
|
||||||
.replace(/(&)/g, '&')
|
|
||||||
.replace(/(<)/g, '<')
|
|
||||||
.replace(/(>)/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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extractChapters(url) {
|
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) {
|
||||||
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].replace(/<[^>]*>/g, '').trim();
|
const title = match[4].replace(/<[^>]*>/g, '').trim();
|
||||||
|
|
||||||
if (!chapters[langCode]) chapters[langCode] = [];
|
if (!chapters[langCode]) chapters[langCode] = [];
|
||||||
|
|
||||||
chapters[langCode].push([
|
chapters[langCode].push([
|
||||||
chapterNumber,
|
chapterNumber,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
id: chapterId,
|
id: chapterId,
|
||||||
title: title,
|
title: title,
|
||||||
chapter: Number(chapterNumber),
|
chapter: Number(chapterNumber),
|
||||||
scanlation_group: "Mangafire"
|
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) {
|
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}`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.status === 200 && data.result && data.result.images) {
|
if (data.status === 200 && data.result && data.result.images) {
|
||||||
const images = data.result.images.map(img => img[0]);
|
const images = data.result.images.map(img => img[0]);
|
||||||
console.log(JSON.stringify(images));
|
console.log(JSON.stringify(images));
|
||||||
return images;
|
return images;
|
||||||
} else {
|
} else {
|
||||||
console.error("Invalid response from server");
|
console.error("Invalid response from server");
|
||||||
return null;
|
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) {
|
function b64encode(data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user