From ec6a93f7ddc2595bd58b85c05322c4e9bff7e3ce Mon Sep 17 00:00:00 2001 From: K1ngfish3r Date: Mon, 13 Nov 2023 15:06:55 +0800 Subject: [PATCH] cleanup --- src/sources/ch/linovelib.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/sources/ch/linovelib.js b/src/sources/ch/linovelib.js index 9f6c0e8d8..eae3e6477 100644 --- a/src/sources/ch/linovelib.js +++ b/src/sources/ch/linovelib.js @@ -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)); @@ -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') @@ -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 = '

' + chapterName + '

'; } - 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 }; };