Upload files to "/"
This commit is contained in:
61
novelfire.js
61
novelfire.js
@@ -52,43 +52,42 @@ class novelfire {
|
||||
}
|
||||
|
||||
async findChapters(bookId) {
|
||||
const base = `https://novelfire.net/book/${bookId}/chapters`;
|
||||
const chapters = [];
|
||||
const url = `https://novelfire.net/book/${bookId}/chapter-1`;
|
||||
|
||||
const firstRes = await this.fetch(base);
|
||||
const firstHtml = await firstRes.text();
|
||||
let $ = this.cheerio.load(firstHtml);
|
||||
const options = await this.browser.scrape(
|
||||
url,
|
||||
async () => {
|
||||
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
let totalPages = 1;
|
||||
const pageLinks = $(".pagination a.page-link");
|
||||
pageLinks.each((_, el) => {
|
||||
const num = parseInt($(el).text().trim(), 10);
|
||||
if (!isNaN(num) && num > totalPages) totalPages = num;
|
||||
});
|
||||
const select = document.querySelector('.chapindex');
|
||||
if (!select) return [];
|
||||
|
||||
for (let page = 1; page <= totalPages; page++) {
|
||||
const url = page === 1 ? base : `${base}?page=${page}`;
|
||||
select.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
|
||||
select.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
|
||||
const res = await this.fetch(url);
|
||||
const html = await res.text();
|
||||
$ = this.cheerio.load(html);
|
||||
for (let i = 0; i < 20; i++) {
|
||||
if (document.querySelectorAll('.select2-results__option').length > 0) break;
|
||||
await sleep(300);
|
||||
}
|
||||
|
||||
$(".chapter-list li").each((_, el) => {
|
||||
const a = $(el).find("a");
|
||||
const href = a.attr("href");
|
||||
const title = a.find(".chapter-title").text().trim();
|
||||
const chapterNumber = parseInt(a.find(".chapter-no").text().trim(), 10);
|
||||
return [...select.querySelectorAll('option')].map(opt => ({
|
||||
id: opt.value,
|
||||
title: opt.textContent.trim(),
|
||||
chapter: Number(opt.dataset.n_sort || 0),
|
||||
}));
|
||||
},
|
||||
{
|
||||
waitSelector: '.chapindex',
|
||||
timeout: 10000
|
||||
}
|
||||
);
|
||||
|
||||
chapters.push({
|
||||
id: href,
|
||||
title,
|
||||
chapter: chapterNumber,
|
||||
language: "en"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return chapters;
|
||||
return options.map(o => ({
|
||||
id: `https://novelfire.net/book/${bookId}/chapter-${o.chapter}`,
|
||||
title: o.title,
|
||||
chapter: o.chapter,
|
||||
language: "en"
|
||||
}));
|
||||
}
|
||||
|
||||
async findChapterPages(chapterId) {
|
||||
|
||||
Reference in New Issue
Block a user