Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
K1ngfish3r committed Nov 13, 2023
1 parent 670d2ec commit ec6a93f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/sources/ch/linovelib.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const parseNovelAndChapters = async novelUrl => {
};

const parseChapter = async (novelUrl, chapterUrl) => {
let chapterName, chapterText, hasNextPage, pageHasNextPage, pageText;
let chapterName, chapterText, hasNextPage, pageHasNextPage, pageText, urlNext;
let pageNumber = 1;
const delay = ms => new Promise(res => setTimeout(res, ms));

Expand Down Expand Up @@ -252,8 +252,10 @@ const parseChapter = async (novelUrl, chapterUrl) => {
const addPage = async pageCheerio => {
const formatPage = async () => {
// Remove JS
pageCheerio('.atitle').next().find('p:first').remove();
pageCheerio('.atitle').next().find('.cgo').remove();
let style = pageCheerio('style:first').prop('innerHTML');
style = style.replace(/(.*?)\{.*?\}/g, '$1,').split(',');
style.push(style.pop().replace(/\}/, '.cgo'));
style.map(tag => pageCheerio(tag).remove());

// Load lazyloaded images
pageCheerio('.atitle')
Expand Down Expand Up @@ -286,21 +288,23 @@ const parseChapter = async (novelUrl, chapterUrl) => {

await formatPage();
chapterName =
pageCheerio('#atitle + h3').text() +
' — ' +
pageCheerio('#atitle').text();
pageCheerio('.atitle h3').text() + ' — ' + pageCheerio('#atitle').text();
if (chapterText === undefined) {
chapterText = '<h2>' + chapterName + '</h2>';
}
chapterText += pageText;
chapterText +=
pageText ||
'Chapter not found, Report at lnreader github/discord if you see this message';
};

const loadPage = async url => {
const body = await fetchHtml({ url, sourceId });
const pageCheerio = cheerio.load(body);
await addPage(pageCheerio);
pageHasNextPage =
pageCheerio('#footlink a:last').text() === '下一页' ? true : false;
urlNext = pageCheerio('#aread script:first')
.prop('innerHTML')
.replace(/.*next:'(.*?)'.*/g, '$1');
pageHasNextPage = urlNext.match(/_/) ? true : false;
return { pageCheerio, pageHasNextPage };
};

Expand Down

0 comments on commit ec6a93f

Please sign in to comment.