diff --git a/src/plugins/english/lightnovelpub.ts b/src/plugins/english/lightnovelpub.ts index c997298..9178e89 100644 --- a/src/plugins/english/lightnovelpub.ts +++ b/src/plugins/english/lightnovelpub.ts @@ -7,7 +7,7 @@ import dayjs from 'dayjs'; class LightNovelPub implements Plugin.PagePlugin { id = 'lightnovelpub'; name = 'LightNovelPub'; - version = '2.0.0'; + version = '2.1.0'; icon = 'src/en/lightnovelpub/icon.png'; site = 'https://www.lightnovelpub.com/'; headers = { @@ -236,102 +236,20 @@ class LightNovelPub implements Plugin.PagePlugin { } async parseChapter(chapterPath: string): Promise { - const body = await fetchApi(this.site + chapterPath).then(r => r.text()); - - let chapterText = ''; - let isChapter = false; - let isPtag = false; - let isStyleText = false; - const parser = new Parser({ - onopentag(name, attribs) { - if (isChapter && name === 'div') { - const stylediv = attribs['style']; - if (stylediv) { - chapterText += `
`; - isStyleText = true; - } else { - chapterText += `
`; - } - } - if (isChapter && name === 'table') { - const w = attribs['width']; - if (w) { - chapterText += ``; - } else { - chapterText += `
`; - } - } - if (isChapter && name === 'tbody') { - chapterText += ``; - } - if (isChapter && name === 'tr') { - chapterText += ``; - } - if (isChapter && name === 'td') { - const w1 = attribs['width']; - if (w1) { - chapterText += ``; - } - if (isChapter && name === 'tr') { - chapterText += ``; - } - if (isChapter && name === 'tbody') { - chapterText += ``; - } - if (isChapter && name === 'table') { - chapterText += `
`; - } else { - chapterText += ``; - } - } - }, - onattribute(name, value) { - if (name === 'id' && value === 'chapter-container') { - isChapter = true; - } - if (name === 'class' && value?.includes('chapternav')) { - isChapter = false; - isPtag = false; - } - }, - onopentagname(name) { - if (isChapter && name === 'p') { - chapterText += '

'; - isPtag = true; - if (isStyleText) { - isStyleText = false; - } - } - if (isChapter && name === 'br') { - chapterText += `
`; - } - }, - ontext(data) { - if (isPtag) { - chapterText += data; - } - if (isStyleText) { - chapterText += data; - } - }, - onclosetag(name) { - if (name === 'p') { - isPtag = false; - chapterText += '

'; - } - if (isChapter && name === 'td') { - chapterText += `
`; - } - if (isChapter && name === 'div') { - isStyleText = false; - chapterText += `
`; - } - }, - }); - parser.write(body); - parser.end(); - - return chapterText; + const html = await fetchApi(this.site + chapterPath).then(r => r.text()); + const parts: string[] = []; + const regexPatterns: RegExp[] = [ + /(
{ + patterns.forEach(regex => { + const match = html.match(regex)?.[1]; + if (match) parts.push(match); + }); + }; + extractContent(regexPatterns); + const chapterText = parts.join(); + return chapterText.replace(/(?<=\/p>).*?(?=

)/g, ''); } async searchNovels(searchTerm: string): Promise { diff --git a/src/plugins/english/royalroad.ts b/src/plugins/english/royalroad.ts index b0f0c1d..4447086 100644 --- a/src/plugins/english/royalroad.ts +++ b/src/plugins/english/royalroad.ts @@ -7,7 +7,7 @@ import { NovelStatus } from '@libs/novelStatus'; class RoyalRoad implements Plugin.PluginBase { id = 'royalroad'; name = 'Royal Road'; - version = '2.1.1'; + version = '2.1.2'; icon = 'src/en/royalroad/icon.png'; site = 'https://www.royalroad.com/'; @@ -234,10 +234,10 @@ class RoyalRoad implements Plugin.PluginBase { const html = await result.text(); const parts: string[] = []; const regexPatterns: RegExp[] = [ - /