import "@johnlindquist/kit";
import * as cheerio from "cheerio";
import axios from "axios";
let baseURL = "https://novelfull.net";
function template(title, link, img) {
return {
name: title,
value: link,
html: `
<div class="flex flex-row h-full w-full py-2">
<img class="h-auto" src="${img}" />
<h2 class="flex-1 flex flex-row items-center justify-center">${title}</h2>
<div class="flex flex-row text-xxs items-center justify-right">open</div>
</div>
`,
};
}
let url = await arg("keyword...", async (keyword) => {
if (keyword.trim() === "") return [];
let { data } = await axios.get(
`${baseURL}/search?keyword=${keyword.toLowerCase().replace(" ", "+")}`
);
let $ = cheerio.load(data);
let novels = $("div.row")
.get()
.map((tag) => {
if ($(tag).hasClass("row")) {
let title = $(tag).find(".truyen-title").text();
let link =
baseURL + $(tag).find(".truyen-title").find("a").attr("href");
let img = baseURL + $(tag).find("img").attr("src");
return template(title, link, img);
}
});
return novels.filter((n) => n.value !== `${baseURL}undefined`);
});
await $`open ${url}`;