@yeci226/nhentai-ts
Version:
A scraper for NHentai with types
57 lines (56 loc) • 2.3 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var list_exports = {};
__export(list_exports, {
parseDoujinList: () => parseDoujinList
});
module.exports = __toCommonJS(list_exports);
var import_List = require("../lib/Classes/List");
var import_lib = require("../lib");
const parseDoujinList = ($, site) => {
const data = [];
const baseURL = import_lib.baseURLS[site];
const currentPage = Number($(".pagination").find(".page.current").text());
const totalPages = Number(
($(".pagination").find("a.last").attr("href") || "").split("page=")[1]
);
const pagination = currentPage === 0 ? null : {
currentPage,
hasNextPage: totalPages > currentPage,
totalPages
};
$(".gallery").each((i, el) => {
const contentElements = $(el).find("a");
const slug = contentElements.attr("href");
const id = slug ? slug.split("g/")[1].replace("/", "") : "";
const url = "".concat(baseURL, "/g/").concat(id);
const coverSlug = contentElements.find("a > img").attr("data-src") || contentElements.find("a > img").attr("src");
const cover = coverSlug ? "".concat(coverSlug.startsWith("/galleries/") ? "https://t3.nhentai.net" : "").concat(coverSlug).replace("/g/", "/galleries/").replace(import_lib.imageSites[site], "t3.nhentai.net") : null;
const title = $(el).find(".caption").text().trim();
data.push(new import_List.List(title, id, cover, url));
});
return {
pagination,
data
};
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
parseDoujinList
});