diff --git a/tokyoinsider/tokyoinsider.js b/tokyoinsider/tokyoinsider.js new file mode 100644 index 0000000..b828685 --- /dev/null +++ b/tokyoinsider/tokyoinsider.js @@ -0,0 +1,134 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://www.tokyoinsider.com/anime/search?k=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const regex = /]*><\/a>[\s\S]*?([^<]*(?:]*>[^<]*<\/span>[^<]*)*)<\/a>/g; + + let match; + while ((match = regex.exec(html)) !== null) { + const titleText = match[3].replace(/(.*?)<\/span>/g, '$1').replace(/ /g, ' '); + results.push({ + title: titleText.trim(), + image: match[1].trim(), + href: match[2].trim() + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +async function extractDetails(slug) { + try { + const response = await fetchv2("https://www.tokyoinsider.com" + slug); + const html = await response.text(); + + let titles = "N/A"; + let airdate = "N/A"; + let description = "N/A"; + + const titlesMatch = html.match(/Title\(s\):<\/b><\/td>\s*([\s\S]*?)<\/td>\s*<\/tr>/); + if (titlesMatch) { + titles = titlesMatch[1].replace(/
/g, ', ').replace(/\s+/g, ' ').trim(); + } + + const airdateMatch = html.match(/Vintage:<\/b><\/td>\s*([\s\S]*?)<\/td>\s*<\/tr>/); + if (airdateMatch) { + airdate = airdateMatch[1].replace(/\s+/g, ' ').trim(); + } + + const summaryMatch = html.match(/Summary:<\/b><\/td>\s*([\s\S]*?)<\/td>\s*<\/tr>/); + if (summaryMatch) { + description = summaryMatch[1].replace(/\s+/g, ' ').trim(); + } + + return JSON.stringify([{ + aliases: titles, + airdate: airdate, + description: description + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(url) { + const results = []; + try { + const response = await fetchv2("https://www.tokyoinsider.com" + url); + const html = await response.text(); + + const regex = /