diff --git a/src/plugins/english/royalroad.ts b/src/plugins/english/royalroad.ts index fbb60ae7a..d8576607c 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.0.1'; + version = '2.1.0'; icon = 'src/en/royalroad/icon.png'; site = 'https://www.royalroad.com/'; @@ -232,115 +232,21 @@ class RoyalRoad implements Plugin.PluginBase { async parseChapter(chapterPath: string): Promise { const result = await fetchApi(this.site + chapterPath); const html = await result.text(); - let chapterText = ''; - let isChapter = false; - let isPtag = false; - let isStyle = false; - let isStyleText = false; - let styles = ''; - 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 === 'class' && value === 'chapter-inner chapter-content') { - isChapter = true; - } - if (name === 'class' && value === 'portlet light t-center-3') { - isChapter = false; - isPtag = false; - } - if (name === 'class' && value === styles) { - isPtag = false; - } - }, - onopentagname(name) { - if (isChapter && name === 'p') { - chapterText += '

'; - isPtag = true; - if (isStyleText) { - isStyleText = false; - } - } - if (name === 'style') { - isStyle = true; - } - if (isChapter && name === 'br') { - chapterText += `
`; - } - }, - ontext(data) { - if (isPtag) { - chapterText += data; - } - if (isStyleText) { - chapterText += data; - } - if (isStyle) { - if (data.includes('display: none;')) { - styles = data.match(/\.(.*)\{/)![1]; - } - } - }, - onclosetag(name) { - if (name === 'p') { - isPtag = false; - chapterText += '

'; - } - if (name === 'style') { - isStyle = false; - } - if (isChapter && name === 'td') { - chapterText += `
`; - } - if (isChapter && name === 'div') { - isStyleText = false; - chapterText += `
`; - } - }, - }); - parser.write(html); - parser.end(); + const parts: string[] = []; + const regexPatterns: RegExp[] = [ + /(