fix(indonesian/indowebnovel): restore chapter list and chapter text (#2528)
Publish Plugins / Publish Plugins (push) Has been cancelled
Publish Plugins / Publish Plugins (push) Has been cancelled
This commit is contained in:
@@ -9,20 +9,53 @@ class IndoWebNovel implements Plugin.PluginBase {
|
|||||||
name = 'IndoWebNovel';
|
name = 'IndoWebNovel';
|
||||||
icon = 'src/id/indowebnovel/icon.png';
|
icon = 'src/id/indowebnovel/icon.png';
|
||||||
site = 'https://indowebnovel.id/';
|
site = 'https://indowebnovel.id/';
|
||||||
version = '1.2.3';
|
version = '1.3.1';
|
||||||
|
|
||||||
|
private headers = {
|
||||||
|
'User-Agent':
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||||
|
Accept:
|
||||||
|
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
||||||
|
'Accept-Language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
|
||||||
|
Referer: 'https://indowebnovel.id/',
|
||||||
|
};
|
||||||
|
|
||||||
|
private async fetchPage(url: string) {
|
||||||
|
const res = await fetchApi(url, { headers: this.headers });
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Object.assign(new Error('Request failed: ' + res.status), {
|
||||||
|
status: res.status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return res.text();
|
||||||
|
}
|
||||||
|
|
||||||
parseNovels(loadedCheerio: CheerioAPI) {
|
parseNovels(loadedCheerio: CheerioAPI) {
|
||||||
const novels: Plugin.NovelItem[] = [];
|
const novels: Plugin.NovelItem[] = [];
|
||||||
|
|
||||||
loadedCheerio('.flexbox2-item').each((i, el) => {
|
// The search/paged listing (`page/<n>/?s`) renders `.flexbox2-item`
|
||||||
const novelName = loadedCheerio(el)
|
// cards, while the front page renders `.flexbox3-item` cards (latest
|
||||||
.find('.flexbox2-title span')
|
// updates) and `.popular .flexbox-item` cards (ranked list). Accept
|
||||||
.first()
|
// every variant so a listing page never parses to zero novels just
|
||||||
.text();
|
// because the server returned another listing layout.
|
||||||
const novelCover = loadedCheerio(el).find('img').attr('src');
|
const items = loadedCheerio('.flexbox2-item').length
|
||||||
const novelUrl = loadedCheerio(el)
|
? loadedCheerio('.flexbox2-item')
|
||||||
.find('.flexbox2-content > a')
|
: loadedCheerio('.flexbox3-item').length
|
||||||
.attr('href');
|
? loadedCheerio('.flexbox3-item')
|
||||||
|
: loadedCheerio('.popular .flexbox-item');
|
||||||
|
|
||||||
|
items.each((i, el) => {
|
||||||
|
const item = loadedCheerio(el);
|
||||||
|
const novelName = (
|
||||||
|
item.find('.flexbox2-title span').first().text() ||
|
||||||
|
item.find('.title a').first().text() ||
|
||||||
|
item.find('.flexbox-title').first().text()
|
||||||
|
).trim();
|
||||||
|
const novelCover = item.find('img').attr('src');
|
||||||
|
const novelUrl =
|
||||||
|
item.find('.flexbox2-content > a').attr('href') ||
|
||||||
|
item.find('.flexbox3-content > a').attr('href') ||
|
||||||
|
item.find('a').attr('href');
|
||||||
|
|
||||||
if (!novelUrl) return;
|
if (!novelUrl) return;
|
||||||
|
|
||||||
@@ -52,16 +85,14 @@ class IndoWebNovel implements Plugin.PluginBase {
|
|||||||
link += filters.genre.value.map(i => `&genre[]=${i}`).join('');
|
link += filters.genre.value.map(i => `&genre[]=${i}`).join('');
|
||||||
*/
|
*/
|
||||||
const link = this.site + `page/${page}/?s`;
|
const link = this.site + `page/${page}/?s`;
|
||||||
const result = await fetchApi(link);
|
const body = await this.fetchPage(link);
|
||||||
const body = await result.text();
|
|
||||||
|
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
return this.parseNovels(loadedCheerio);
|
return this.parseNovels(loadedCheerio);
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||||
const result = await fetchApi(this.site + novelPath);
|
const body = await this.fetchPage(this.site + novelPath);
|
||||||
const body = await result.text();
|
|
||||||
|
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
loadedCheerio('.series-synops div').remove();
|
loadedCheerio('.series-synops div').remove();
|
||||||
@@ -88,16 +119,36 @@ class IndoWebNovel implements Plugin.PluginBase {
|
|||||||
|
|
||||||
const chapters: Plugin.ChapterItem[] = [];
|
const chapters: Plugin.ChapterItem[] = [];
|
||||||
|
|
||||||
loadedCheerio('.series-chapterlist li').each((i, el) => {
|
loadedCheerio('.series-chapterlists li').each((i, el) => {
|
||||||
const chapterName = loadedCheerio(el).find('a').text().trim();
|
// The list entry also holds a `span.date`; drop it so the chapter name
|
||||||
|
// does not end with the release date.
|
||||||
|
const chapterName = loadedCheerio(el)
|
||||||
|
.find('a span')
|
||||||
|
.not('.date')
|
||||||
|
.first()
|
||||||
|
.text()
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
.trim();
|
||||||
const chapterUrl = loadedCheerio(el).find('a').attr('href');
|
const chapterUrl = loadedCheerio(el).find('a').attr('href');
|
||||||
|
|
||||||
if (!chapterUrl) return;
|
if (!chapterUrl) return;
|
||||||
|
|
||||||
chapters.push({
|
const chapter: Plugin.ChapterItem = {
|
||||||
name: chapterName,
|
name: chapterName,
|
||||||
path: chapterUrl.slice(this.site.length),
|
path: chapterUrl.slice(this.site.length),
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Each entry also holds a `span.date` like "October 23, 2025".
|
||||||
|
const releaseDate = loadedCheerio(el)
|
||||||
|
.find('span.date')
|
||||||
|
.first()
|
||||||
|
.text()
|
||||||
|
.trim();
|
||||||
|
if (releaseDate && !isNaN(Date.parse(releaseDate))) {
|
||||||
|
chapter.releaseTime = new Date(releaseDate).toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
chapters.push(chapter);
|
||||||
});
|
});
|
||||||
|
|
||||||
novel.chapters = chapters.reverse();
|
novel.chapters = chapters.reverse();
|
||||||
@@ -106,12 +157,15 @@ class IndoWebNovel implements Plugin.PluginBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async parseChapter(chapterPath: string): Promise<string> {
|
async parseChapter(chapterPath: string): Promise<string> {
|
||||||
const result = await fetchApi(this.site + chapterPath);
|
const body = await this.fetchPage(this.site + chapterPath);
|
||||||
const body = await result.text();
|
|
||||||
|
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
|
|
||||||
const chapterText = loadedCheerio('.adsads').html() || '';
|
// The chapter body is nested in `main .content .container` behind a div
|
||||||
|
// whose class is a rotating random token (the previous hardcoded name,
|
||||||
|
// `.adsads`, no longer exists), so use the stable inner `#content`
|
||||||
|
// element instead of that wrapper class.
|
||||||
|
const chapterText = loadedCheerio('main #content').html() || '';
|
||||||
|
|
||||||
return chapterText;
|
return chapterText;
|
||||||
}
|
}
|
||||||
@@ -128,8 +182,7 @@ class IndoWebNovel implements Plugin.PluginBase {
|
|||||||
link += this.filters.lang.value.map(i => `&country[]=${i}`).join('');
|
link += this.filters.lang.value.map(i => `&country[]=${i}`).join('');
|
||||||
*/
|
*/
|
||||||
const link = this.site + `page/${page}/?s=${searchTerm}`;
|
const link = this.site + `page/${page}/?s=${searchTerm}`;
|
||||||
const result = await fetchApi(link);
|
const body = await this.fetchPage(link);
|
||||||
const body = await result.text();
|
|
||||||
|
|
||||||
const loadedCheerio = parseHTML(body);
|
const loadedCheerio = parseHTML(body);
|
||||||
return this.parseNovels(loadedCheerio);
|
return this.parseNovels(loadedCheerio);
|
||||||
|
|||||||
Reference in New Issue
Block a user