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:
+37
-20
@@ -273,50 +273,67 @@ class ElloTL implements Plugin.PluginBase {
|
|||||||
return fetch(this.site + chapterPath)
|
return fetch(this.site + chapterPath)
|
||||||
.then(res => res.text())
|
.then(res => res.text())
|
||||||
.then(html => {
|
.then(html => {
|
||||||
|
let isParsingTitleBlock = false;
|
||||||
|
let isParsingTitle = false;
|
||||||
|
let isParsingSubtitle = false;
|
||||||
let isParsingContent = false;
|
let isParsingContent = false;
|
||||||
let chapterContent = '';
|
let chapterContent = '';
|
||||||
let notContent = false;
|
let notContent = false;
|
||||||
|
|
||||||
const parser = new Parser({
|
const parser = new Parser({
|
||||||
onopentag(name, attribs) {
|
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;
|
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) {
|
if (isParsingContent && !notContent) {
|
||||||
chapterContent += '<' + name;
|
chapterContent += `<${name}`;
|
||||||
for (let attrib in attribs) {
|
for (let attrib in attribs) {
|
||||||
chapterContent += ` ${attrib}="${attribs[attrib]}"`;
|
chapterContent += ` ${attrib}="${attribs[attrib]}"`;
|
||||||
}
|
}
|
||||||
chapterContent += '>';
|
chapterContent += `>`;
|
||||||
|
}
|
||||||
|
if (attribs['class']?.includes('mb-center')) {
|
||||||
|
notContent = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ontext(data) {
|
ontext(data) {
|
||||||
|
if (isParsingTitle) {
|
||||||
|
chapterContent += data;
|
||||||
|
}
|
||||||
|
if (isParsingSubtitle) {
|
||||||
|
chapterContent += data;
|
||||||
|
}
|
||||||
if (isParsingContent && !notContent) {
|
if (isParsingContent && !notContent) {
|
||||||
chapterContent += data;
|
chapterContent += data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onclosetag(name) {
|
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) {
|
if (isParsingContent && !notContent) {
|
||||||
chapterContent += `</${name}>`;
|
chapterContent += `</${name}>`;
|
||||||
}
|
}
|
||||||
if (notContent) {
|
if (notContent && name === 'span') {
|
||||||
notContent = false;
|
notContent = false;
|
||||||
}
|
}
|
||||||
if (isParsingContent && !notContent && name === 'div') {
|
if (isParsingContent && name === 'div') {
|
||||||
isParsingContent = false;
|
isParsingContent = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -182,24 +182,24 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
case 'anotivereads':
|
case 'anotivereads':
|
||||||
chapterTitle = loadedCheerio('#comic-nav-name').first().text()!;
|
chapterTitle = loadedCheerio('#comic-nav-name').first().text()!;
|
||||||
chapterContent = loadedCheerio('#spliced-comic').html()!;
|
chapterContent = loadedCheerio('#spliced-comic').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'asuratls':
|
case 'asuratls':
|
||||||
let titleElementAsura = loadedCheerio('.post-body div b').first();
|
let titleElementAsura = loadedCheerio('.post-body div b').first();
|
||||||
chapterTitle = titleElementAsura.first().text();
|
chapterTitle = titleElementAsura.first().text();
|
||||||
titleElementAsura.remove();
|
titleElementAsura.remove();
|
||||||
chapterContent = loadedCheerio('.post-body').html()!;
|
chapterContent = loadedCheerio('.post-body').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'hiraethtranslation':
|
case 'hiraethtranslation':
|
||||||
chapterTitle = loadedCheerio('li.active').first().text()!;
|
chapterTitle = loadedCheerio('li.active').first().text()!;
|
||||||
chapterContent = loadedCheerio('.text-left').html()!;
|
chapterContent = loadedCheerio('.text-left').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'hostednovel':
|
case 'hostednovel':
|
||||||
chapterTitle = loadedCheerio('#chapter-title').first().text()!;
|
chapterTitle = loadedCheerio('#chapter-title').first().text()!;
|
||||||
chapterContent = loadedCheerio('#chapter-content').html()!;
|
chapterContent = loadedCheerio('#chapter-content').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'inoveltranslation':
|
case 'inoveltranslation':
|
||||||
const link_inovel = 'https://api.' + url.slice(8);
|
const link_inovel = 'https://api.' + url.slice(8);
|
||||||
@@ -212,13 +212,18 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
'<br><hr><br>TL Notes:<br>' +
|
'<br><hr><br>TL Notes:<br>' +
|
||||||
json_inovel.notes.replace(/\n/g, '<br>');
|
json_inovel.notes.replace(/\n/g, '<br>');
|
||||||
}
|
}
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'ko-fi':
|
case 'ko-fi':
|
||||||
chapterText = loadedCheerio('script:contains("shadowDom.innerHTML")')
|
chapterText = loadedCheerio('script:contains("shadowDom.innerHTML")')
|
||||||
.html()
|
.html()
|
||||||
?.match(/shadowDom\.innerHTML \+= '(<div.*?)';/)![1]!;
|
?.match(/shadowDom\.innerHTML \+= '(<div.*?)';/)![1]!;
|
||||||
break;
|
break;
|
||||||
|
case 'novelplex':
|
||||||
|
chapterTitle = loadedCheerio('.halChap--jud').first().text()!;
|
||||||
|
chapterContent = loadedCheerio('.halChap--kontenInner ').html()!;
|
||||||
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
|
break;
|
||||||
case 'novelworldtranslations':
|
case 'novelworldtranslations':
|
||||||
bloatClasses = ['.separator', 'p[dir="ltr"]'];
|
bloatClasses = ['.separator', 'p[dir="ltr"]'];
|
||||||
bloatClasses.map(tag => loadedCheerio(tag).remove());
|
bloatClasses.map(tag => loadedCheerio(tag).remove());
|
||||||
@@ -228,7 +233,7 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
return paragraph.replace(/ /g, '').trim() + '<br>';
|
return paragraph.replace(/ /g, '').trim() + '<br>';
|
||||||
});
|
});
|
||||||
chapterContent = chapterContentArray.join('').trim();
|
chapterContent = chapterContentArray.join('').trim();
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'raeitranslations':
|
case 'raeitranslations':
|
||||||
const parts = url.split('/');
|
const parts = url.split('/');
|
||||||
@@ -246,7 +251,7 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
`<br><hr><br>Translator's Note:<br>` +
|
`<br><hr><br>Translator's Note:<br>` +
|
||||||
json.currentChapter.note;
|
json.currentChapter.note;
|
||||||
chapterContent = chapterContent.replace(/\n/g, '<br>');
|
chapterContent = chapterContent.replace(/\n/g, '<br>');
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'rainofsnow':
|
case 'rainofsnow':
|
||||||
loadedCheerio('.responsivevoice-button').remove();
|
loadedCheerio('.responsivevoice-button').remove();
|
||||||
@@ -257,12 +262,12 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
bloatClasses.map(tag => loadedCheerio(tag).remove());
|
bloatClasses.map(tag => loadedCheerio(tag).remove());
|
||||||
chapterTitle = loadedCheerio('.entry-title').first().text()!;
|
chapterTitle = loadedCheerio('.entry-title').first().text()!;
|
||||||
chapterContent = loadedCheerio('.entry-content').html()!;
|
chapterContent = loadedCheerio('.entry-content').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'scribblehub':
|
case 'scribblehub':
|
||||||
chapterTitle = loadedCheerio('.chapter-title').first().text()!;
|
chapterTitle = loadedCheerio('.chapter-title').first().text()!;
|
||||||
chapterContent = loadedCheerio('div.chp_raw').html()!;
|
chapterContent = loadedCheerio('div.chp_raw').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'stabbingwithasyringe':
|
case 'stabbingwithasyringe':
|
||||||
/**
|
/**
|
||||||
@@ -281,7 +286,7 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
chapterTitle = titleElementSyringe.first().text();
|
chapterTitle = titleElementSyringe.first().text();
|
||||||
titleElementSyringe.remove();
|
titleElementSyringe.remove();
|
||||||
chapterContent = loadedCheerioSyringe('.entry-content').html()!;
|
chapterContent = loadedCheerioSyringe('.entry-content').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
} else {
|
} else {
|
||||||
chapterText = chapterContent;
|
chapterText = chapterContent;
|
||||||
}
|
}
|
||||||
@@ -296,7 +301,7 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
chapterTitle = loadedCheerio('.title-content').first().text()!;
|
chapterTitle = loadedCheerio('.title-content').first().text()!;
|
||||||
loadedCheerio('.title-content').first().remove();
|
loadedCheerio('.title-content').first().remove();
|
||||||
chapterContent = loadedCheerio('.content').html()!;
|
chapterContent = loadedCheerio('.content').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'tumblr':
|
case 'tumblr':
|
||||||
chapterText = loadedCheerio('.post').html()!;
|
chapterText = loadedCheerio('.post').html()!;
|
||||||
@@ -304,7 +309,7 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
case 'wattpad':
|
case 'wattpad':
|
||||||
chapterTitle = loadedCheerio('.h2').first().text()!;
|
chapterTitle = loadedCheerio('.h2').first().text()!;
|
||||||
chapterContent = loadedCheerio('.part-content pre').html()!;
|
chapterContent = loadedCheerio('.part-content pre').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'webnovel':
|
case 'webnovel':
|
||||||
chapterTitle = loadedCheerio('.cha-tit .pr .dib').first().text()!;
|
chapterTitle = loadedCheerio('.cha-tit .pr .dib').first().text()!;
|
||||||
@@ -312,14 +317,14 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
if (!chapterContent) {
|
if (!chapterContent) {
|
||||||
chapterContent = loadedCheerio('._content').html()!;
|
chapterContent = loadedCheerio('._content').html()!;
|
||||||
}
|
}
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
case 'wuxiaworld':
|
case 'wuxiaworld':
|
||||||
bloatClasses = ['.MuiLink-root'];
|
bloatClasses = ['.MuiLink-root'];
|
||||||
bloatClasses.map(tag => loadedCheerio(tag).remove());
|
bloatClasses.map(tag => loadedCheerio(tag).remove());
|
||||||
chapterTitle = loadedCheerio('h4 span').first().text()!;
|
chapterTitle = loadedCheerio('h4 span').first().text()!;
|
||||||
chapterContent = loadedCheerio('.chapter-content').html()!;
|
chapterContent = loadedCheerio('.chapter-content').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return chapterText;
|
return chapterText;
|
||||||
@@ -423,7 +428,7 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
chapterContent =
|
chapterContent =
|
||||||
loadedCheerio('.entry-content').html() ||
|
loadedCheerio('.entry-content').html() ||
|
||||||
loadedCheerio('.post-body').html()!;
|
loadedCheerio('.post-body').html()!;
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
} else if (isWordPress) {
|
} else if (isWordPress) {
|
||||||
bloatClasses = [
|
bloatClasses = [
|
||||||
'.ad',
|
'.ad',
|
||||||
@@ -439,7 +444,6 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
'.sharedaddy',
|
'.sharedaddy',
|
||||||
'.sidebar',
|
'.sidebar',
|
||||||
'.wp-block-buttons',
|
'.wp-block-buttons',
|
||||||
'.wp-block-columns',
|
|
||||||
'.wp-block-image',
|
'.wp-block-image',
|
||||||
'.wp-dark-mode-switcher',
|
'.wp-dark-mode-switcher',
|
||||||
'.wp-next-post-navi',
|
'.wp-next-post-navi',
|
||||||
@@ -476,7 +480,7 @@ class NovelUpdates implements Plugin.PluginBase {
|
|||||||
if (chapterSubtitle) {
|
if (chapterSubtitle) {
|
||||||
chapterTitle = `${chapterTitle} | ${chapterSubtitle}`;
|
chapterTitle = `${chapterTitle} | ${chapterSubtitle}`;
|
||||||
}
|
}
|
||||||
chapterText = `<h1>${chapterTitle}</h1><br>${chapterContent}`;
|
chapterText = `<h2>${chapterTitle}</h2><br>${chapterContent}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chapterText) {
|
if (!chapterText) {
|
||||||
|
|||||||
Reference in New Issue
Block a user