Created
December 20, 2025 18:32
-
-
Save ONLym22/3e02e9e8517717ab6ff6dd76c01bdfbc to your computer and use it in GitHub Desktop.
ONLym BOT Gist Uploaded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const axios = require("axios"); | |
| const cheerio = require("cheerio"); | |
| async function fandomDetector(query, wiki = "honkai-impact-3rd-archives") { | |
| try { | |
| if (!query) throw new Error("Query is required"); | |
| const searchUrl = `https://${wiki}.fandom.com/wiki/Special:Search?query=${encodeURIComponent(query)}`; | |
| const searchRes = await axios.get(searchUrl, { | |
| headers: { "User-Agent": "Mozilla/5.0" } | |
| }); | |
| const $search = cheerio.load(searchRes.data); | |
| const firstResult = $search(".unified-search__result__title").first(); | |
| const pageUrl = firstResult.attr("href"); | |
| if (!pageUrl) throw new Error("No result found"); | |
| const pageRes = await axios.get(pageUrl, { | |
| headers: { "User-Agent": "Mozilla/5.0" } | |
| }); | |
| const $page = cheerio.load(pageRes.data); | |
| const title = | |
| $page("h1").first().text().trim() || | |
| $page("title").text().trim(); | |
| const content = | |
| $page("#mw-content-text").text().trim().slice(0, 5000); | |
| const images = []; | |
| $page("img").each((i, el) => { | |
| const src = $page(el).attr("src"); | |
| if (src && !src.startsWith("data:")) { | |
| images.push(src.startsWith("//") ? "https:" + src : src); | |
| } | |
| }); | |
| return { | |
| success: true, | |
| query, | |
| page: { | |
| title, | |
| url: pageUrl, | |
| content, | |
| images: images.slice(0, 10) | |
| } | |
| }; | |
| } catch (err) { | |
| return { | |
| success: false, | |
| message: err.message | |
| }; | |
| } | |
| } | |
| // usage | |
| fandomDetector("Mobius") | |
| .then(console.log) | |
| .catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment