Skip to content

Commit 0d4d71a

Browse files
fix: [Novel Updates]: Chapter Content (#1074)
* novel-updates: yoru * novel-updates: update raeitranslations * novel-updates: revert versions * novel-updates: update version Co-authored-by: Rajarshee Chatterjee <rajarshee.adm@gmail.com> --------- Co-authored-by: Rajarshee Chatterjee <rajarshee.adm@gmail.com>
1 parent 23d611e commit 0d4d71a

File tree

1 file changed

+58
-48
lines changed

1 file changed

+58
-48
lines changed

src/plugins/english/novelupdates.ts

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-case-declarations */
21
import { CheerioAPI, load as parseHTML } from 'cheerio';
32
import { fetchApi } from '@libs/fetch';
43
import { Filters, FilterTypes } from '@libs/filterInputs';
@@ -7,7 +6,7 @@ import { Plugin } from '@typings/plugin';
76
class NovelUpdates implements Plugin.PluginBase {
87
id = 'novelupdates';
98
name = 'Novel Updates';
10-
version = '0.7.1';
9+
version = '0.7.2';
1110
icon = 'src/en/novelupdates/icon.png';
1211
customCSS = 'src/en/novelupdates/customCSS.css';
1312
site = 'https://www.novelupdates.com/';
@@ -188,7 +187,7 @@ class NovelUpdates implements Plugin.PluginBase {
188187
let chapterContent = '';
189188
let chapterText = '';
190189

191-
const unwanted = ['blogspot', 'casper', 'wordpress', 'www'];
190+
const unwanted = ['app', 'blogspot', 'casper', 'wordpress', 'www'];
192191
const targetDomain = domain.find(d => !unwanted.includes(d));
193192

194193
switch (targetDomain) {
@@ -200,9 +199,9 @@ class NovelUpdates implements Plugin.PluginBase {
200199
}
201200
break;
202201
case 'asuratls':
203-
const titleElementAsura = loadedCheerio('.post-body div b').first();
204-
chapterTitle = titleElementAsura.text()!;
205-
titleElementAsura.remove();
202+
const titleElement_asura = loadedCheerio('.post-body div b').first();
203+
chapterTitle = titleElement_asura.text()!;
204+
titleElement_asura.remove();
206205
chapterContent = loadedCheerio('.post-body').html()!;
207206
if (chapterTitle && chapterContent) {
208207
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
@@ -219,7 +218,7 @@ class NovelUpdates implements Plugin.PluginBase {
219218
chapterTitle = loadedCheerio('.title-image span').first().text()!;
220219
loadedCheerio('.content')
221220
.children()
222-
.each((idx, ele) => {
221+
.each((_, ele) => {
223222
if (loadedCheerio(ele).attr('id')?.includes('Chaptertitle-info')) {
224223
loadedCheerio(ele).remove();
225224
return false;
@@ -242,13 +241,13 @@ class NovelUpdates implements Plugin.PluginBase {
242241
break;
243242
case 'helscans':
244243
chapterTitle = loadedCheerio('.entry-title-main').first().text()!;
245-
const chapterStringHelScans =
244+
const chapterString_helscans =
246245
'Chapter ' + chapterTitle.split('Chapter')[1].trim();
247246
loadedCheerio('#readerarea.rdminimal')
248247
.children()
249-
.each((idx, ele) => {
248+
.each((_, ele) => {
250249
const elementText = loadedCheerio(ele).text();
251-
if (elementText.includes(chapterStringHelScans)) {
250+
if (elementText.includes(chapterString_helscans)) {
252251
chapterTitle = elementText;
253252
loadedCheerio(ele).remove();
254253
return false;
@@ -305,25 +304,25 @@ class NovelUpdates implements Plugin.PluginBase {
305304
}
306305
break;
307306
case 'ko-fi':
308-
const matchResult = loadedCheerio(
307+
const matchResult_kofi = loadedCheerio(
309308
'script:contains("shadowDom.innerHTML")',
310309
)
311310
.html()
312311
?.match(/shadowDom\.innerHTML \+= '(<div.*?)';/);
313-
if (matchResult && matchResult[1]) {
314-
chapterText = matchResult[1];
312+
if (matchResult_kofi && matchResult_kofi[1]) {
313+
chapterText = matchResult_kofi[1];
315314
} else {
316315
chapterText = '';
317316
}
318317
break;
319318
case 'mirilu':
320319
bloatClasses = ['#jp-post-flair'];
321320
bloatClasses.map(tag => loadedCheerio(tag).remove());
322-
const titleElementMirilu = loadedCheerio(
321+
const titleElement_mirilu = loadedCheerio(
323322
'.entry-content p strong',
324323
).first();
325-
chapterTitle = titleElementMirilu.text()!;
326-
titleElementMirilu.remove();
324+
chapterTitle = titleElement_mirilu.text()!;
325+
titleElement_mirilu.remove();
327326
chapterContent = loadedCheerio('.entry-content').html()!;
328327
if (chapterTitle && chapterContent) {
329328
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
@@ -365,35 +364,39 @@ class NovelUpdates implements Plugin.PluginBase {
365364
case 'raeitranslations':
366365
const parts = url.split('/');
367366
const link_raei = `${parts[0]}//api.${parts[2]}/api/chapters/?id=${parts[3]}&num=${parts[4]}`;
368-
const json = await fetchApi(link_raei).then(r => r.json());
369-
chapterTitle = 'Chapter ' + json.currentChapter.num;
370-
chapterContent =
371-
json.currentChapter.head +
372-
`<br><hr><br>` +
373-
json.currentChapter.body +
374-
`<br><hr><br>Translator's Note:<br>` +
375-
json.currentChapter.note;
367+
const json_raei = await fetchApi(link_raei).then(r => r.json());
368+
const titleElement_raei = `Chapter ${json_raei.currentChapter.chapTag}`;
369+
chapterTitle = json_raei.currentChapter.chapTitle
370+
? `${titleElement_raei} - ${json_raei.currentChapter.chapTitle}`
371+
: titleElement_raei;
372+
chapterContent = [
373+
json_raei.currentChapter.head,
374+
`<br><hr><br>`,
375+
json_raei.currentChapter.body,
376+
`<br><hr><br>Translator's Note:<br>`,
377+
json_raei.currentChapter.note,
378+
].join('');
376379
chapterContent = chapterContent.replace(/\n/g, '<br>');
377380
if (chapterTitle && chapterContent) {
378381
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
379382
}
380383
break;
381384
case 'rainofsnow':
382-
const displayedDivSnow = loadedCheerio('.bb-item').filter(function () {
385+
const displayedDiv_snow = loadedCheerio('.bb-item').filter(function () {
383386
return loadedCheerio(this).css('display') === 'block';
384387
});
385-
const loadedCheerioSnow = parseHTML(displayedDivSnow.html()!);
388+
const loadedCheerioSnow = parseHTML(displayedDiv_snow.html()!);
386389
bloatClasses = [
387390
'.responsivevoice-button',
388391
'.zoomdesc-cont p img',
389392
'.zoomdesc-cont p noscript',
390393
];
391394
bloatClasses.map(tag => loadedCheerioSnow(tag).remove());
392395
chapterContent = loadedCheerioSnow('.zoomdesc-cont').html()!;
393-
const titleElementSnow = loadedCheerioSnow('.scroller h2').first();
394-
if (titleElementSnow.length) {
395-
chapterTitle = titleElementSnow.text()!;
396-
titleElementSnow.remove();
396+
const titleElement_snow = loadedCheerioSnow('.scroller h2').first();
397+
if (titleElement_snow.length) {
398+
chapterTitle = titleElement_snow.text()!;
399+
titleElement_snow.remove();
397400
chapterContent = loadedCheerioSnow('.zoomdesc-cont').html()!;
398401
if (chapterTitle && chapterContent) {
399402
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
@@ -466,8 +469,10 @@ class NovelUpdates implements Plugin.PluginBase {
466469
/**
467470
* Check for age verification
468471
*/
469-
const ageVerification = loadedCheerio('main').text().toLowerCase()!;
470-
if (ageVerification.includes('age verification required')) {
472+
const ageVerification_skydemon = loadedCheerio('main')
473+
.text()
474+
.toLowerCase()!;
475+
if (ageVerification_skydemon.includes('age verification required')) {
471476
throw new Error('Age verification required, please open in webview.');
472477
}
473478
chapterTitle = `${loadedCheerio('.pl-4 h1').first().text()!} | ${loadedCheerio('.pl-4 div').first().text()!}`;
@@ -485,24 +490,24 @@ class NovelUpdates implements Plugin.PluginBase {
485490
/**
486491
* Get the chapter link from the main page
487492
*/
488-
const linkSyringe = loadedCheerio('.entry-content a').attr('href')!;
489-
const resultSyringe = await fetchApi(linkSyringe);
490-
const bodySyringe = await resultSyringe.text();
491-
const loadedCheerioSyringe = parseHTML(bodySyringe);
493+
const link_syringe = loadedCheerio('.entry-content a').attr('href')!;
494+
const result_syringe = await fetchApi(link_syringe);
495+
const body_syringe = await result_syringe.text();
496+
const loadedCheerio_syringe = parseHTML(body_syringe);
492497
bloatClasses = [
493498
'.has-inline-color',
494499
'.wp-block-buttons',
495500
'.wpcnt',
496501
'#jp-post-flair',
497502
];
498-
bloatClasses.map(tag => loadedCheerioSyringe(tag).remove());
499-
chapterContent = loadedCheerioSyringe('.entry-content').html()!;
500-
const titleElementSyringe =
501-
loadedCheerioSyringe('.entry-content h3').first();
502-
if (titleElementSyringe.length) {
503-
chapterTitle = titleElementSyringe.text();
504-
titleElementSyringe.remove();
505-
chapterContent = loadedCheerioSyringe('.entry-content').html()!;
503+
bloatClasses.map(tag => loadedCheerio_syringe(tag).remove());
504+
chapterContent = loadedCheerio_syringe('.entry-content').html()!;
505+
const titleElement_syringe =
506+
loadedCheerio_syringe('.entry-content h3').first();
507+
if (titleElement_syringe.length) {
508+
chapterTitle = titleElement_syringe.text();
509+
titleElement_syringe.remove();
510+
chapterContent = loadedCheerio_syringe('.entry-content').html()!;
506511
if (chapterTitle && chapterContent) {
507512
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
508513
}
@@ -555,14 +560,19 @@ class NovelUpdates implements Plugin.PluginBase {
555560
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
556561
}
557562
break;
563+
case 'yoru':
564+
const chapterId_yoru = url.split('/').pop();
565+
const link_yoru = `https://pxp-main-531j.onrender.com/api/v1/book_chapters/${chapterId_yoru}/content`;
566+
const json_yoru = await fetchApi(link_yoru).then(r => r.json());
567+
chapterText = await fetchApi(json_yoru).then(r => r.text());
558568
case 'zetrotranslation':
559569
bloatClasses = ['hr', 'p:contains("\u00a0")'];
560570
bloatClasses.map(tag => loadedCheerio(tag).remove());
561571
chapterContent = loadedCheerio('.text-left').html()!;
562-
const titleElementZetro = loadedCheerio('.text-left h2').first();
563-
if (titleElementZetro.length) {
564-
chapterTitle = titleElementZetro.text()!;
565-
titleElementZetro.remove();
572+
const titleElement_zetro = loadedCheerio('.text-left h2').first();
573+
if (titleElement_zetro.length) {
574+
chapterTitle = titleElement_zetro.text()!;
575+
titleElement_zetro.remove();
566576
chapterContent = loadedCheerio('.text-left').html()!;
567577
if (chapterTitle && chapterContent) {
568578
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;

0 commit comments

Comments
 (0)