diff --git a/mangakatana/mangakatana.js b/mangakatana/mangakatana.js new file mode 100644 index 0000000..abe1e65 --- /dev/null +++ b/mangakatana/mangakatana.js @@ -0,0 +1,141 @@ +async function searchContent(keyword, page = 0) { + let results = []; + try { + const headers = { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + "X-Requested-With": "XMLHttpRequest", + }; + const postData = `s=${encodeURIComponent(keyword)}&search_by=book_name`; + + const response = await fetch("https://mangakatana.com/", { + method: "POST", + headers: headers, + body: postData + }); + + const html = await response.text(); + + const regex = /]*data-id=["'](\d+)["'][^>]*>[\s\S]*?]*src=["']([^"']+)["'][^>]*>[\s\S]*?]*href=["']([^"']+)["'][^>]*class=["']title["'][^>]*>([^<]+)<\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + results.push({ + id: match[3].trim(), + imageURL: match[2].trim(), + title: match[4].trim() + }); + } + + console.log(`Found ${results.length} results for "${keyword}"`); + return results; + } catch (err) { + console.error('Search error:', err); + return []; + } +} + +async function getContentData(url) { + try { + const response = await fetch(url); + const html = await response.text(); + + const descRegex = /]*content=["']([^"']*)["']/; + const descMatch = html.match(descRegex); + let description = ""; + + if (descMatch && descMatch[1]) { + description = descMatch[1] + .replace(/^Summary:\s*/i, '') + .trim(); + } + + const tags = []; + const genresRegex = /]*>([\s\S]*?)<\/div>/; + const genresMatch = html.match(genresRegex); + + if (genresMatch && genresMatch[1]) { + const tagRegex = /]*>([^<]+)<\/a>/g; + let tagMatch; + while ((tagMatch = tagRegex.exec(genresMatch[1])) !== null) { + tags.push(tagMatch[1].trim()); + } + } + + return { + description: description, + tags: tags + }; + } catch (err) { + console.error('Error fetching content data:', 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><\/div><\/td>