feat(modifier): add `getIdRandomPururin` method

このコミットが含まれているのは:
sinkaroid 2022-06-07 23:16:39 +07:00
コミット 276a36dd98
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: A7DF4E245FDD8159
1個のファイルの変更18行の追加1行の削除

ファイルの表示

@ -1,4 +1,6 @@
import p from "phin";
import { load } from "cheerio";
import c from "./options";
function getPururinInfo(value: string) {
@ -22,6 +24,10 @@ function getId(url: string) {
return url.replace(/^https?:\/\/[^\\/]+/, "").replace(/\/$/, "");
}
function removeNonNumeric(input: string) {
return input.replace(/[^0-9]/g, "");
}
function getDate(date: Date) {
return date.toLocaleDateString("en-US", {
year: "numeric",
@ -66,5 +72,16 @@ export const isNumeric = (val: string) : boolean => {
return !isNaN(Number(val));
};
export async function getIdRandomPururin (): Promise<number> {
const randomNumber = Math.floor(Math.random() * 500) + 1;
const raw = await p(`${c.PURURIN}/browse/random?page=${randomNumber}`);
const $ = load(raw.body);
const gallery = $("img.card-img-top").map((i, el) => $(el).attr("data-src")).get();
const galleryNumber = gallery.map(el => removeNonNumeric(el));
const randomgallery = galleryNumber[Math.floor(Math.random() * galleryNumber.length)];
return parseInt(randomgallery);
}
export { getPururinInfo, getPururinPageCount, getUrl, getId, getDate, timeAgo, mock, getPururinLanguage };
export { getPururinInfo, getPururinPageCount, getUrl, getId, getDate, timeAgo,
mock, getPururinLanguage, removeNonNumeric };