Enhancement: NU Improvements (#978)

* Enhancement: remove filler text

* Enhancement: added  	FictionRead to NU sites

* Fix: removed logs

* Enhancement: removed bloat

* Fix: <nr> -> <br>

* Enhancement: remove bloat

* Enhancement: added NU Femme Fables support

* fix: version

* Enhancement: added NU Redox Translation support

* Fix: updated versions

* Fix: import

* Fix: ElloMTL

* Enhancement: added regex to turn markdown into html

* Enhancement: better regex

* Enhancement: wordpress remove bloat

* Enhancement: added NU mii translates support

* Fix: mii translates

* Fix: mii translates

* Fix: mii translates

* Fix: mii translates

* novelUpdates: remove bloat

* novelUpdates: fix search

* novelUpdates: update wordpress

* novelUpdates: fetch image

* novelUpdates: fetch image

* novelUpdates: fetch image

* novelUpdates: fetch image

* novelUpdates: update version
This commit is contained in:
Batorian
2024-06-29 12:29:01 +02:00
committed by GitHub
parent c2388e9efa
commit 938e3b16a3
+102 -21
View File
@@ -1,12 +1,12 @@
import { CheerioAPI, load as parseHTML } from 'cheerio'; import { CheerioAPI, load as parseHTML } from 'cheerio';
import { fetchApi, fetchFile } from '@libs/fetch'; import { fetchApi } from '@libs/fetch';
import { Filters, FilterTypes } from '@libs/filterInputs'; import { Filters, FilterTypes } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin'; import { Plugin } from '@typings/plugin';
class NovelUpdates implements Plugin.PluginBase { class NovelUpdates implements Plugin.PluginBase {
id = 'novelupdates'; id = 'novelupdates';
name = 'Novel Updates'; name = 'Novel Updates';
version = '0.5.4'; version = '0.6.0';
icon = 'src/en/novelupdates/icon.png'; icon = 'src/en/novelupdates/icon.png';
site = 'https://www.novelupdates.com/'; site = 'https://www.novelupdates.com/';
@@ -180,14 +180,13 @@ class NovelUpdates implements Plugin.PluginBase {
loadedCheerio: CheerioAPI, loadedCheerio: CheerioAPI,
domain: string[], domain: string[],
url: string, url: string,
result: Response,
) { ) {
let bloatClasses = []; let bloatClasses = [];
let chapterTitle = ''; let chapterTitle = '';
let chapterContent = ''; let chapterContent = '';
let chapterText = ''; let chapterText = '';
const unwanted = ['blogspot', 'wordpress', 'www']; const unwanted = ['blogspot', 'casper', 'wordpress', 'www'];
const targetDomain = domain.find(d => !unwanted.includes(d)); const targetDomain = domain.find(d => !unwanted.includes(d));
switch (targetDomain) { switch (targetDomain) {
@@ -207,6 +206,28 @@ class NovelUpdates implements Plugin.PluginBase {
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`; chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
} }
break; break;
case 'fictionread':
bloatClasses = [
'.content > style',
'.highlight-ad-container',
'.meaning',
'.word',
];
bloatClasses.map(tag => loadedCheerio(tag).remove());
chapterTitle = loadedCheerio('.title-image span').first().text()!;
loadedCheerio('.content')
.children()
.each((idx, ele) => {
if (loadedCheerio(ele).attr('id')?.includes('Chaptertitle-info')) {
loadedCheerio(ele).remove();
return false;
}
});
chapterContent = loadedCheerio('.content').html()!;
if (chapterTitle && chapterContent) {
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
}
break;
case 'helscans': case 'helscans':
chapterTitle = loadedCheerio('.entry-title-main').first().text()!; chapterTitle = loadedCheerio('.entry-title-main').first().text()!;
const chapterStringHelScans = const chapterStringHelScans =
@@ -255,6 +276,22 @@ class NovelUpdates implements Plugin.PluginBase {
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`; chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
} }
break; break;
case 'isotls': // mii translates
bloatClasses = [
'footer',
'header',
'nav',
'.ezoic-ad',
'.ezoic-adpicker-ad',
'.ezoic-videopicker-video',
];
bloatClasses.map(tag => loadedCheerio(tag).remove());
chapterTitle = loadedCheerio('head title').first().text()!;
chapterContent = loadedCheerio('main article').html()!;
if (chapterTitle && chapterContent) {
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
}
break;
case 'ko-fi': case 'ko-fi':
chapterText = loadedCheerio('script:contains("shadowDom.innerHTML")') chapterText = loadedCheerio('script:contains("shadowDom.innerHTML")')
.html() .html()
@@ -346,6 +383,39 @@ class NovelUpdates implements Plugin.PluginBase {
chapterText = chapterContent; chapterText = chapterContent;
} }
break; break;
case 'redoxtranslation':
const chapterID_redox = url.split('/').pop();
chapterTitle = `Chapter ${chapterID_redox}`;
const url_redox = `${url.split('chapter')[0]}txt/${chapterID_redox}.txt`;
chapterContent = await fetchApi(url_redox)
.then(r => r.text())
.then(text => {
// Split text into sentences based on newline characters
const sentences_redox = text.split('\n');
// Process each sentence individually
const formattedSentences_redox = sentences_redox.map(sentence => {
// Check if the sentence contains "<hr>"
if (sentence.includes('{break}')) {
// Create a centered sentence with three stars
return '<br> <p>****</p>';
} else {
// Replace text enclosed within ** with <strong> tags
sentence = sentence.replace(
/\*\*(.*?)\*\*/g,
'<strong>$1</strong>',
);
// Replace text enclosed within ++ with <em> tags
sentence = sentence.replace(/\+\+(.*?)\+\+/g, '<em>$1</em>');
return sentence;
}
});
// Join the formatted sentences back together with newline characters
return formattedSentences_redox.join('<br>');
});
if (chapterTitle && chapterContent) {
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
}
break;
case 'sacredtexttranslations': case 'sacredtexttranslations':
bloatClasses = [ bloatClasses = [
'.entry-content blockquote', '.entry-content blockquote',
@@ -360,8 +430,10 @@ class NovelUpdates implements Plugin.PluginBase {
} }
break; break;
case 'scribblehub': case 'scribblehub':
bloatClasses = ['.wi_authornotes'];
bloatClasses.map(tag => loadedCheerio(tag).remove());
chapterTitle = loadedCheerio('.chapter-title').first().text()!; chapterTitle = loadedCheerio('.chapter-title').first().text()!;
chapterContent = loadedCheerio('div.chp_raw').html()!; chapterContent = loadedCheerio('.chp_raw').html()!;
if (chapterTitle && chapterContent) { if (chapterTitle && chapterContent) {
chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`; chapterText = `<h2>${chapterTitle}</h2><hr><br>${chapterContent}`;
} }
@@ -393,7 +465,12 @@ class NovelUpdates implements Plugin.PluginBase {
const resultSyringe = await fetchApi(linkSyringe); const resultSyringe = await fetchApi(linkSyringe);
const bodySyringe = await resultSyringe.text(); const bodySyringe = await resultSyringe.text();
const loadedCheerioSyringe = parseHTML(bodySyringe); const loadedCheerioSyringe = parseHTML(bodySyringe);
bloatClasses = ['.wp-block-buttons', '#jp-post-flair', '.wpcnt']; bloatClasses = [
'.has-inline-color',
'.wp-block-buttons',
'.wpcnt',
'#jp-post-flair',
];
bloatClasses.map(tag => loadedCheerioSyringe(tag).remove()); bloatClasses.map(tag => loadedCheerioSyringe(tag).remove());
chapterContent = loadedCheerioSyringe('.entry-content').html()!; chapterContent = loadedCheerioSyringe('.entry-content').html()!;
let titleElementSyringe = let titleElementSyringe =
@@ -483,8 +560,8 @@ class NovelUpdates implements Plugin.PluginBase {
const result = await fetchApi(this.site + chapterPath); const result = await fetchApi(this.site + chapterPath);
const body = await result.text(); const body = await result.text();
const url = result.url.toLowerCase(); const url = result.url;
const domain = url.split('/')[2].split('.'); const domain = url.toLowerCase().split('/')[2].split('.');
const loadedCheerio = parseHTML(body); const loadedCheerio = parseHTML(body);
@@ -513,12 +590,15 @@ class NovelUpdates implements Plugin.PluginBase {
/** /**
* Detect if the site is a Blogspot site * Detect if the site is a Blogspot site
*/ */
let isBlogspotStr = loadedCheerio( let isBlogspotStr =
'meta[name="google-adsense-platform-domain"]', loadedCheerio('meta[name="google-adsense-platform-domain"]').attr(
).attr('content'); 'content',
) || loadedCheerio('meta[name="generator"]').attr('content');
let isBlogspot = false; let isBlogspot = false;
if (isBlogspotStr) { if (isBlogspotStr) {
isBlogspot = isBlogspotStr.toLowerCase().includes('blogspot'); isBlogspot =
isBlogspotStr.toLowerCase().includes('blogspot') ||
isBlogspotStr.toLowerCase().includes('blogger');
} }
/** /**
@@ -539,7 +619,7 @@ class NovelUpdates implements Plugin.PluginBase {
/** /**
* In case sites are not detected correctly * In case sites are not detected correctly
*/ */
const manualWordPress = ['genesistls']; const manualWordPress = ['genesistls', 'soafp'];
if (!isWordPress && domain.find(wp => manualWordPress.includes(wp))) { if (!isWordPress && domain.find(wp => manualWordPress.includes(wp))) {
isWordPress = true; isWordPress = true;
} }
@@ -550,6 +630,7 @@ class NovelUpdates implements Plugin.PluginBase {
const outliers = [ const outliers = [
'anotivereads', 'anotivereads',
'asuratls', 'asuratls',
'fictionread',
'helscans', 'helscans',
'mirilu', 'mirilu',
'novelworldtranslations', 'novelworldtranslations',
@@ -567,6 +648,7 @@ class NovelUpdates implements Plugin.PluginBase {
* Blogspot sites: * Blogspot sites:
* - ¼-Assed * - ¼-Assed
* - AsuraTls (Outlier) * - AsuraTls (Outlier)
* - FictionRead (Outlier)
* - Novel World Translations (Outlier) * - Novel World Translations (Outlier)
* - SacredText TL (Outlier) * - SacredText TL (Outlier)
* *
@@ -576,6 +658,7 @@ class NovelUpdates implements Plugin.PluginBase {
* - Blossom Translation * - Blossom Translation
* - Dumahs Translations * - Dumahs Translations
* - ElloMTL * - ElloMTL
* - Femme Fables
* - Gem Novels * - Gem Novels
* - Genesis Translations (Manually added) * - Genesis Translations (Manually added)
* - Goblinslate * - Goblinslate
@@ -586,7 +669,7 @@ class NovelUpdates implements Plugin.PluginBase {
* - Mirilu - Novel Reader Attempts Translating (Outlier) * - Mirilu - Novel Reader Attempts Translating (Outlier)
* - Neosekai Translations * - Neosekai Translations
* - Shanghai Fantasy * - Shanghai Fantasy
* - Soafp * - Soafp (Manually added)
* - Stabbing with a Syringe (Outlier) * - Stabbing with a Syringe (Outlier)
* - StoneScape * - StoneScape
* - TinyTL (Outlier) * - TinyTL (Outlier)
@@ -595,12 +678,7 @@ class NovelUpdates implements Plugin.PluginBase {
* - Zetro Translation (Outlier) * - Zetro Translation (Outlier)
*/ */
if (!isWordPress && !isBlogspot) { if (!isWordPress && !isBlogspot) {
chapterText = await this.getChapterBody( chapterText = await this.getChapterBody(loadedCheerio, domain, url);
loadedCheerio,
domain,
url,
result,
);
} else if (isBlogspot) { } else if (isBlogspot) {
bloatClasses = ['.button-container', '.separator']; bloatClasses = ['.button-container', '.separator'];
bloatClasses.map(tag => loadedCheerio(tag).remove()); bloatClasses.map(tag => loadedCheerio(tag).remove());
@@ -628,10 +706,12 @@ class NovelUpdates implements Plugin.PluginBase {
'.pre-bar', '.pre-bar',
'.sharedaddy', '.sharedaddy',
'.sidebar', '.sidebar',
'.swg-button-v2-light',
'.wp-block-buttons', '.wp-block-buttons',
'.wp-block-image', '.wp-block-image',
'.wp-dark-mode-switcher', '.wp-dark-mode-switcher',
'.wp-next-post-navi', '.wp-next-post-navi',
'#hpk',
'#jp-post-flair', '#jp-post-flair',
'#textbox', '#textbox',
]; ];
@@ -660,6 +740,7 @@ class NovelUpdates implements Plugin.PluginBase {
loadedCheerio('.single_post').html() || loadedCheerio('.single_post').html() ||
loadedCheerio('.post-entry').html() || loadedCheerio('.post-entry').html() ||
loadedCheerio('.main-content').html() || loadedCheerio('.main-content').html() ||
loadedCheerio('.post-content').html() ||
loadedCheerio('.content').html() || loadedCheerio('.content').html() ||
loadedCheerio('.page-body').html() || loadedCheerio('.page-body').html() ||
loadedCheerio('.td-page-content').html() || loadedCheerio('.td-page-content').html() ||
@@ -706,7 +787,7 @@ class NovelUpdates implements Plugin.PluginBase {
); );
searchTerm = longestSearchTerm.replace(/[‘’]/g, "'").replace(/\s+/g, '+'); searchTerm = longestSearchTerm.replace(/[‘’]/g, "'").replace(/\s+/g, '+');
const url = this.site + '?s=' + searchTerm + '&post_type=seriesplans'; const url = `${this.site}series-finder/?sf=1&sh=${searchTerm}&sort=srank&order=asc&pg=${page}`;
const result = await fetchApi(url); const result = await fetchApi(url);
const body = await result.text(); const body = await result.text();
const loadedCheerio = parseHTML(body); const loadedCheerio = parseHTML(body);