mirror of
https://git.luna-app.eu/50n50/sources
synced 2025-12-21 21:26:19 +01:00
Add mangapark/mangapark.js
This commit is contained in:
parent
622dc6d061
commit
fa2c44fe4e
1 changed files with 139 additions and 0 deletions
139
mangapark/mangapark.js
Normal file
139
mangapark/mangapark.js
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
function decodeHtmlEntities(text) {
|
||||
const map = {
|
||||
''': "'",
|
||||
'"': '"',
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
''': "'",
|
||||
'/': '/',
|
||||
'`': '`',
|
||||
'=': '=',
|
||||
};
|
||||
return text.replace(/&#?\w+;/g, (entity) => map[entity] || entity);
|
||||
}
|
||||
|
||||
async function searchContent(keyword) {
|
||||
const results = [];
|
||||
|
||||
const pages = [0, 2, 3, 4, 5];
|
||||
|
||||
try {
|
||||
const promises = pages.map(page => {
|
||||
const url = page === 0
|
||||
? `https://mangapark.net/search?word=${encodeURIComponent(keyword)}`
|
||||
: `https://mangapark.net/search?word=${encodeURIComponent(keyword)}&page=${page}`;
|
||||
|
||||
return fetch(url)
|
||||
.then(response => response.text())
|
||||
.then(html => {
|
||||
const regex = /<a href="(\/title\/[^"]+)"[^>]*>[\s\S]*?<img src="([^"]+)"[^>]*?title="([^"]+)"/g;
|
||||
const pageResults = [];
|
||||
|
||||
let match;
|
||||
while ((match = regex.exec(html)) !== null) {
|
||||
pageResults.push({
|
||||
id: "https://mangapark.net" + match[1].trim(),
|
||||
imageURL: "https://mangapark.net" + match[2].trim(),
|
||||
title: decodeHtmlEntities(match[3].trim())
|
||||
});
|
||||
}
|
||||
|
||||
return pageResults;
|
||||
})
|
||||
.catch(() => []);
|
||||
});
|
||||
|
||||
const allResults = await Promise.all(promises);
|
||||
|
||||
return allResults.flat();
|
||||
|
||||
} catch (err) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function getContentData(url) {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const html = await response.text();
|
||||
|
||||
const descRegex = /<div class="limit-html-p">([\s\S]*?)<\/div>/;
|
||||
const descMatch = html.match(descRegex);
|
||||
let description = descMatch ? descMatch[1].trim() : "";
|
||||
description = description.replace(/<br\s*\/?>/g, '\n').replace(/<[^>]+>/g, '');
|
||||
|
||||
const tagsRegex = /<!--t=[a-z0-9]+>([^<]+)<!---->/g;
|
||||
const tags = [];
|
||||
let tagMatch;
|
||||
while ((tagMatch = tagsRegex.exec(html)) !== null) {
|
||||
tags.push(tagMatch[1].trim());
|
||||
}
|
||||
|
||||
return {
|
||||
description,
|
||||
tags
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
description: "Error",
|
||||
tags: []
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function getChapters(url) {
|
||||
const results = [];
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const html = await response.text();
|
||||
const regex = /<a href="([^"]+)"[^>]*>Chapter (\d+(?:\.\d+)?)[^<]*<\/a>/g;
|
||||
let match;
|
||||
let index = 0;
|
||||
while ((match = regex.exec(html)) !== null) {
|
||||
results.push([
|
||||
String(index),
|
||||
[{
|
||||
id: "https://mangapark.net" + match[1].trim(),
|
||||
title: `Chapter ${match[2].trim()}`,
|
||||
chapter: index,
|
||||
scanlation_group: "MangaPark"
|
||||
}]
|
||||
]);
|
||||
index++;
|
||||
}
|
||||
return { en: results.reverse() };
|
||||
} catch (err) {
|
||||
return { en: [] };
|
||||
}
|
||||
}
|
||||
|
||||
async function getChapterImages(url) {
|
||||
const results = [];
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const html = await response.text();
|
||||
|
||||
const jsonMatch = html.match(/<script type="qwik\/json">([\s\S]*?)<\/script>/);
|
||||
if (jsonMatch) {
|
||||
const jsonData = JSON.parse(jsonMatch[1]);
|
||||
|
||||
const findImages = (obj) => {
|
||||
if (typeof obj === 'string' && /^https:\/\/s\d+\.mp[a-z]+\.org\/media\/mpup\/[^"]+\.jpeg$/.test(obj)) {
|
||||
results.push(obj);
|
||||
} else if (Array.isArray(obj)) {
|
||||
obj.forEach(findImages);
|
||||
} else if (obj && typeof obj === 'object') {
|
||||
Object.values(obj).forEach(findImages);
|
||||
}
|
||||
};
|
||||
|
||||
findImages(jsonData);
|
||||
}
|
||||
|
||||
return results;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue