From dbf6670da5a78404c0b898259e9124c9040ddc98 Mon Sep 17 00:00:00 2001 From: Lukas Richter <53831711+Batorian@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:03:16 +0200 Subject: [PATCH] fix: NU chapter titles,update: ElloTL `parseChapter` (#917) * refactored and updated Novel Updates' parseChapter() * added `ippotranslations` and `shanghaifantasy` to Novel Updates * small changes * removed switch cases and reverted back to `let` and `if`/`else if` structure * added lots of translation group support * added more site support and tried cleaning chapter content where possible * quick fix * quick fix * logic overhaul; implementation of switch cases (again) * small changes to `bloatClasses` and `chapterContent` * added Anomalously Creative (`anotivereads`) to outliers and added new `bloatClasses` to Wuxia World (`wuxiaworld`) * edited ElloTL (`ellotl.ts`) to match Novel Updates chapter content and slightly reduced title size in Novel Updates (`novelupdates.ts`) chapters; also added Novel Plex (`novelplex`) as supported site for Novel Updates * ElloTL fix --- plugins/english/ellotl.ts | 57 +++++++++++++++++++++------------ plugins/english/novelupdates.ts | 38 ++++++++++++---------- 2 files changed, 58 insertions(+), 37 deletions(-) diff --git a/plugins/english/ellotl.ts b/plugins/english/ellotl.ts index ba99a79..7c058e2 100644 --- a/plugins/english/ellotl.ts +++ b/plugins/english/ellotl.ts @@ -273,50 +273,67 @@ class ElloTL implements Plugin.PluginBase { return fetch(this.site + chapterPath) .then(res => res.text()) .then(html => { + let isParsingTitleBlock = false; + let isParsingTitle = false; + let isParsingSubtitle = false; let isParsingContent = false; let chapterContent = ''; let notContent = false; + const parser = new Parser({ onopentag(name, attribs) { - if (attribs['class']?.includes('epcontent' || 'entry-content')) { + if (attribs['class']?.includes('epheader')) { + chapterContent += `

`; + isParsingTitleBlock = true; + isParsingTitle = true; + } + if (isParsingSubtitle) { + chapterContent += ' | '; + } + if (attribs['class']?.includes('entry-content')) { isParsingContent = true; - chapterContent += '<' + name; - for (let attrib in attribs) { - chapterContent += ` ${attrib}="${attribs[attrib]}"`; - } - chapterContent += '>'; - } - if ( - attribs['class']?.includes( - 'wp-block-buttons' || 'wp-block-spacer' || 'wp-element-button', - ) - ) { - notContent = true; - } - if (name === 'span' && attribs['class']?.includes('maxbutton')) { - notContent = true; } if (isParsingContent && !notContent) { - chapterContent += '<' + name; + chapterContent += `<${name}`; for (let attrib in attribs) { chapterContent += ` ${attrib}="${attribs[attrib]}"`; } - chapterContent += '>'; + chapterContent += `>`; + } + if (attribs['class']?.includes('mb-center')) { + notContent = true; } }, ontext(data) { + if (isParsingTitle) { + chapterContent += data; + } + if (isParsingSubtitle) { + chapterContent += data; + } if (isParsingContent && !notContent) { chapterContent += data; } }, onclosetag(name) { + if (isParsingTitle && name === 'h1') { + isParsingTitle = false; + isParsingSubtitle = true; + } + if (isParsingSubtitle && name === 'div') { + isParsingSubtitle = false; + } + if (isParsingTitleBlock && !isParsingTitle && !isParsingSubtitle) { + chapterContent += `


`; + isParsingTitleBlock = false; + } if (isParsingContent && !notContent) { chapterContent += ``; } - if (notContent) { + if (notContent && name === 'span') { notContent = false; } - if (isParsingContent && !notContent && name === 'div') { + if (isParsingContent && name === 'div') { isParsingContent = false; } }, diff --git a/plugins/english/novelupdates.ts b/plugins/english/novelupdates.ts index bb96a14..a3e3c6d 100644 --- a/plugins/english/novelupdates.ts +++ b/plugins/english/novelupdates.ts @@ -182,24 +182,24 @@ class NovelUpdates implements Plugin.PluginBase { case 'anotivereads': chapterTitle = loadedCheerio('#comic-nav-name').first().text()!; chapterContent = loadedCheerio('#spliced-comic').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'asuratls': let titleElementAsura = loadedCheerio('.post-body div b').first(); chapterTitle = titleElementAsura.first().text(); titleElementAsura.remove(); chapterContent = loadedCheerio('.post-body').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'hiraethtranslation': chapterTitle = loadedCheerio('li.active').first().text()!; chapterContent = loadedCheerio('.text-left').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'hostednovel': chapterTitle = loadedCheerio('#chapter-title').first().text()!; chapterContent = loadedCheerio('#chapter-content').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'inoveltranslation': const link_inovel = 'https://api.' + url.slice(8); @@ -212,13 +212,18 @@ class NovelUpdates implements Plugin.PluginBase { '


TL Notes:
' + json_inovel.notes.replace(/\n/g, '
'); } - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'ko-fi': chapterText = loadedCheerio('script:contains("shadowDom.innerHTML")') .html() ?.match(/shadowDom\.innerHTML \+= '(${chapterTitle}
${chapterContent}`; + break; case 'novelworldtranslations': bloatClasses = ['.separator', 'p[dir="ltr"]']; bloatClasses.map(tag => loadedCheerio(tag).remove()); @@ -228,7 +233,7 @@ class NovelUpdates implements Plugin.PluginBase { return paragraph.replace(/ /g, '').trim() + '
'; }); chapterContent = chapterContentArray.join('').trim(); - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'raeitranslations': const parts = url.split('/'); @@ -246,7 +251,7 @@ class NovelUpdates implements Plugin.PluginBase { `


Translator's Note:
` + json.currentChapter.note; chapterContent = chapterContent.replace(/\n/g, '
'); - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'rainofsnow': loadedCheerio('.responsivevoice-button').remove(); @@ -257,12 +262,12 @@ class NovelUpdates implements Plugin.PluginBase { bloatClasses.map(tag => loadedCheerio(tag).remove()); chapterTitle = loadedCheerio('.entry-title').first().text()!; chapterContent = loadedCheerio('.entry-content').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'scribblehub': chapterTitle = loadedCheerio('.chapter-title').first().text()!; chapterContent = loadedCheerio('div.chp_raw').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'stabbingwithasyringe': /** @@ -281,7 +286,7 @@ class NovelUpdates implements Plugin.PluginBase { chapterTitle = titleElementSyringe.first().text(); titleElementSyringe.remove(); chapterContent = loadedCheerioSyringe('.entry-content').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; } else { chapterText = chapterContent; } @@ -296,7 +301,7 @@ class NovelUpdates implements Plugin.PluginBase { chapterTitle = loadedCheerio('.title-content').first().text()!; loadedCheerio('.title-content').first().remove(); chapterContent = loadedCheerio('.content').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'tumblr': chapterText = loadedCheerio('.post').html()!; @@ -304,7 +309,7 @@ class NovelUpdates implements Plugin.PluginBase { case 'wattpad': chapterTitle = loadedCheerio('.h2').first().text()!; chapterContent = loadedCheerio('.part-content pre').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'webnovel': chapterTitle = loadedCheerio('.cha-tit .pr .dib').first().text()!; @@ -312,14 +317,14 @@ class NovelUpdates implements Plugin.PluginBase { if (!chapterContent) { chapterContent = loadedCheerio('._content').html()!; } - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; case 'wuxiaworld': bloatClasses = ['.MuiLink-root']; bloatClasses.map(tag => loadedCheerio(tag).remove()); chapterTitle = loadedCheerio('h4 span').first().text()!; chapterContent = loadedCheerio('.chapter-content').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; break; } return chapterText; @@ -423,7 +428,7 @@ class NovelUpdates implements Plugin.PluginBase { chapterContent = loadedCheerio('.entry-content').html() || loadedCheerio('.post-body').html()!; - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; } else if (isWordPress) { bloatClasses = [ '.ad', @@ -439,7 +444,6 @@ class NovelUpdates implements Plugin.PluginBase { '.sharedaddy', '.sidebar', '.wp-block-buttons', - '.wp-block-columns', '.wp-block-image', '.wp-dark-mode-switcher', '.wp-next-post-navi', @@ -476,7 +480,7 @@ class NovelUpdates implements Plugin.PluginBase { if (chapterSubtitle) { chapterTitle = `${chapterTitle} | ${chapterSubtitle}`; } - chapterText = `

${chapterTitle}


${chapterContent}`; + chapterText = `

${chapterTitle}


${chapterContent}`; } if (!chapterText) {