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
This commit is contained in:
Lukas Richter
2024-04-29 18:03:16 +02:00
committed by GitHub
parent 129d3f8dfe
commit dbf6670da5
2 changed files with 58 additions and 37 deletions
+37 -20
View File
@@ -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 += `<h2>`;
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 += `</h2><br>`;
isParsingTitleBlock = false;
}
if (isParsingContent && !notContent) {
chapterContent += `</${name}>`;
}
if (notContent) {
if (notContent && name === 'span') {
notContent = false;
}
if (isParsingContent && !notContent && name === 'div') {
if (isParsingContent && name === 'div') {
isParsingContent = false;
}
},
+21 -17
View File
@@ -182,24 +182,24 @@ class NovelUpdates implements Plugin.PluginBase {
case 'anotivereads':
chapterTitle = loadedCheerio('#comic-nav-name').first().text()!;
chapterContent = loadedCheerio('#spliced-comic').html()!;
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
case 'asuratls':
let titleElementAsura = loadedCheerio('.post-body div b').first();
chapterTitle = titleElementAsura.first().text();
titleElementAsura.remove();
chapterContent = loadedCheerio('.post-body').html()!;
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
case 'hiraethtranslation':
chapterTitle = loadedCheerio('li.active').first().text()!;
chapterContent = loadedCheerio('.text-left').html()!;
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
case 'hostednovel':
chapterTitle = loadedCheerio('#chapter-title').first().text()!;
chapterContent = loadedCheerio('#chapter-content').html()!;
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
case 'inoveltranslation':
const link_inovel = 'https://api.' + url.slice(8);
@@ -212,13 +212,18 @@ class NovelUpdates implements Plugin.PluginBase {
'<br><hr><br>TL Notes:<br>' +
json_inovel.notes.replace(/\n/g, '<br>');
}
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
case 'ko-fi':
chapterText = loadedCheerio('script:contains("shadowDom.innerHTML")')
.html()
?.match(/shadowDom\.innerHTML \+= '(<div.*?)';/)![1]!;
break;
case 'novelplex':
chapterTitle = loadedCheerio('.halChap--jud').first().text()!;
chapterContent = loadedCheerio('.halChap--kontenInner ').html()!;
chapterText = `<h2>${chapterTitle}</h2><br>${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(/&nbsp;/g, '').trim() + '<br>';
});
chapterContent = chapterContentArray.join('').trim();
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
case 'raeitranslations':
const parts = url.split('/');
@@ -246,7 +251,7 @@ class NovelUpdates implements Plugin.PluginBase {
`<br><hr><br>Translator's Note:<br>` +
json.currentChapter.note;
chapterContent = chapterContent.replace(/\n/g, '<br>');
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${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 = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
case 'scribblehub':
chapterTitle = loadedCheerio('.chapter-title').first().text()!;
chapterContent = loadedCheerio('div.chp_raw').html()!;
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${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 = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${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 = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${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 = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${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 = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${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 = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
break;
}
return chapterText;
@@ -423,7 +428,7 @@ class NovelUpdates implements Plugin.PluginBase {
chapterContent =
loadedCheerio('.entry-content').html() ||
loadedCheerio('.post-body').html()!;
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${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 = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
}
if (!chapterText) {