diff --git a/mangafire/mangafire.js b/mangafire/mangafire.js index 154e01c..bd16e3d 100644 --- a/mangafire/mangafire.js +++ b/mangafire/mangafire.js @@ -1,155 +1,154 @@ -async function searchResults(input,page=0){ - function parseSearchResults(html) { - const results = []; - const regex = /
[\s\S]*?]*class="poster"[\s\S]*?]*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 = /
[\s\S]*?]*class="poster"[\s\S]*?]*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>/g; - const tags = []; - let match; + function parseHtmlData(htmlContent) { + const genreRegex = /([^<]+)<\/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 = /') + .replace(/\s+/g, ' ') + .trim(); + + if (uniqueTags.length === 0) { + uniqueTags.push("Unknown"); + } + + return { + description: description, + tags: uniqueTags + }; } - const uniqueTags = [...new Set(tags)]; - - const ogDescriptionRegex = - /') - .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>/gs; + const chapterRegex = /]*>(.*?)<\/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) {