Update lastest chapter logic (#853)
* update lastestchapter logic * update version
This commit is contained in:
+15
-26
@@ -16,7 +16,7 @@ class RanobesPlugin implements Plugin.PagePlugin {
|
|||||||
icon = 'src/en/ranobes/icon.png';
|
icon = 'src/en/ranobes/icon.png';
|
||||||
site = 'https://ranobes.top';
|
site = 'https://ranobes.top';
|
||||||
filters?: Filters | undefined;
|
filters?: Filters | undefined;
|
||||||
version = '1.0.0';
|
version = '1.1.0';
|
||||||
|
|
||||||
async sleep(ms: number) {
|
async sleep(ms: number) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
@@ -119,6 +119,17 @@ class RanobesPlugin implements Plugin.PagePlugin {
|
|||||||
novel.totalPages = Number(data.pages_count);
|
novel.totalPages = Number(data.pages_count);
|
||||||
novel.chapters = this.parseChapters(data);
|
novel.chapters = this.parseChapters(data);
|
||||||
|
|
||||||
|
const latestChapterUrl = data.chapters[0].link;
|
||||||
|
const latestChapterName = data.chapters[0].title;
|
||||||
|
const latestChapterDate = data.chapters[0].date;
|
||||||
|
|
||||||
|
novel.latestChapter = latestChapterUrl
|
||||||
|
? {
|
||||||
|
path: latestChapterUrl.replace(this.site, ''),
|
||||||
|
name: latestChapterName,
|
||||||
|
releaseTime: new Date(latestChapterDate).toISOString(),
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
return novel;
|
return novel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,35 +137,13 @@ class RanobesPlugin implements Plugin.PagePlugin {
|
|||||||
const pagePath = novelPath.split('-')[0];
|
const pagePath = novelPath.split('-')[0];
|
||||||
const firstUrl = this.site + '/chapters' + pagePath.replace('novels/', '');
|
const firstUrl = this.site + '/chapters' + pagePath.replace('novels/', '');
|
||||||
const pageUrl = firstUrl + '/page/' + page;
|
const pageUrl = firstUrl + '/page/' + page;
|
||||||
|
|
||||||
const body = await fetchApi(firstUrl).then(r => r.text());
|
|
||||||
|
|
||||||
let loadedCheerio = parseHTML(body);
|
|
||||||
let json = loadedCheerio('#dle-content main').next().html()!;
|
|
||||||
let data = JSON.parse(json.replace('window.__DATA__ =', ''));
|
|
||||||
|
|
||||||
const latestChapterUrl = data.chapters[0].link;
|
|
||||||
const latestChapterName = data.chapters[0].title;
|
|
||||||
const latestChapterDate = data.chapters[0].date;
|
|
||||||
|
|
||||||
const latestChapter: Plugin.ChapterItem | undefined = latestChapterUrl
|
|
||||||
? {
|
|
||||||
path: latestChapterUrl.replace(this.site, ''),
|
|
||||||
name: latestChapterName,
|
|
||||||
releaseTime: new Date(latestChapterDate).toISOString(),
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
await this.sleep(1000);
|
|
||||||
|
|
||||||
const pageBody = await fetchApi(pageUrl).then(r => r.text());
|
const pageBody = await fetchApi(pageUrl).then(r => r.text());
|
||||||
loadedCheerio = parseHTML(pageBody);
|
const loadedCheerio = parseHTML(pageBody);
|
||||||
json = loadedCheerio('#dle-content main').next().html()!;
|
const json = loadedCheerio('#dle-content main').next().html()!;
|
||||||
data = JSON.parse(json.replace('window.__DATA__ =', ''));
|
const data = JSON.parse(json.replace('window.__DATA__ =', ''));
|
||||||
const chapters = this.parseChapters(data);
|
const chapters = this.parseChapters(data);
|
||||||
return {
|
return {
|
||||||
chapters,
|
chapters,
|
||||||
latestChapter,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class TuNovelaLigera implements Plugin.PagePlugin {
|
|||||||
name = 'TuNovelaLigera';
|
name = 'TuNovelaLigera';
|
||||||
icon = 'src/es/tunovelaligera/icon.png';
|
icon = 'src/es/tunovelaligera/icon.png';
|
||||||
site = 'https://tunovelaligera.com';
|
site = 'https://tunovelaligera.com';
|
||||||
version = '1.0.0';
|
version = '1.1.0';
|
||||||
|
|
||||||
async sleep(ms: number) {
|
async sleep(ms: number) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
@@ -122,17 +122,6 @@ class TuNovelaLigera implements Plugin.PagePlugin {
|
|||||||
novel.summary = loadedCheerio('div.summary__content > p').text().trim();
|
novel.summary = loadedCheerio('div.summary__content > p').text().trim();
|
||||||
|
|
||||||
novel.chapters = this.parseChapters(loadedCheerio);
|
novel.chapters = this.parseChapters(loadedCheerio);
|
||||||
|
|
||||||
return novel;
|
|
||||||
}
|
|
||||||
|
|
||||||
async parsePage(novelPath: string, page: string): Promise<Plugin.SourcePage> {
|
|
||||||
const novelUrl = this.site + novelPath;
|
|
||||||
const pageUrl = this.site + novelPath + '?lcp_page0=' + page;
|
|
||||||
const result = await fetchApi(novelUrl);
|
|
||||||
const body = await result.text();
|
|
||||||
|
|
||||||
let loadedCheerio = parseHTML(body);
|
|
||||||
const latestChapterEle = loadedCheerio('#lcp_instance_0 li').first();
|
const latestChapterEle = loadedCheerio('#lcp_instance_0 li').first();
|
||||||
const latestChapterUrl = loadedCheerio(latestChapterEle)
|
const latestChapterUrl = loadedCheerio(latestChapterEle)
|
||||||
.find('a')
|
.find('a')
|
||||||
@@ -142,18 +131,22 @@ class TuNovelaLigera implements Plugin.PagePlugin {
|
|||||||
.text()
|
.text()
|
||||||
.replace(/[\t\n]/g, '')
|
.replace(/[\t\n]/g, '')
|
||||||
.trim();
|
.trim();
|
||||||
const latestChapter: Plugin.ChapterItem | undefined = latestChapterUrl
|
novel.latestChapter = latestChapterUrl
|
||||||
? {
|
? {
|
||||||
path: latestChapterUrl.replace(this.site, ''),
|
path: latestChapterUrl.replace(this.site, ''),
|
||||||
name: latestChapterName,
|
name: latestChapterName,
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
await this.sleep(1000);
|
|
||||||
|
return novel;
|
||||||
|
}
|
||||||
|
|
||||||
|
async parsePage(novelPath: string, page: string): Promise<Plugin.SourcePage> {
|
||||||
|
const pageUrl = this.site + novelPath + '?lcp_page0=' + page;
|
||||||
const pageText = await fetchApi(pageUrl).then(res => res.text());
|
const pageText = await fetchApi(pageUrl).then(res => res.text());
|
||||||
const chapters = this.parseChapters(parseHTML(pageText));
|
const chapters = this.parseChapters(parseHTML(pageText));
|
||||||
return {
|
return {
|
||||||
chapters,
|
chapters,
|
||||||
latestChapter,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async parseChapter(chapterPath: string): Promise<string> {
|
async parseChapter(chapterPath: string): Promise<string> {
|
||||||
|
|||||||
@@ -197,8 +197,6 @@
|
|||||||
<span class="sr-only">Loading...</span>
|
<span class="sr-only">Loading...</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="parsed-page-info">
|
<div class="parsed-page-info">
|
||||||
<div class="latest-chapter-item">
|
|
||||||
</div>
|
|
||||||
<div class="chapter-list-container">
|
<div class="chapter-list-container">
|
||||||
<div class="chapter-list">
|
<div class="chapter-list">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -849,6 +849,11 @@ class PluginWrapper {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (sourceNovel.latestChapter) {
|
||||||
|
novel_data
|
||||||
|
.children('div + div')
|
||||||
|
.append(PluginWrapper.createChapterItem(sourceNovel.latestChapter));
|
||||||
|
}
|
||||||
novel_item.replaceWith(novel_data);
|
novel_item.replaceWith(novel_data);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -872,7 +877,6 @@ class PluginWrapper {
|
|||||||
/** @type {JQuery<HTMLInputElement>} */
|
/** @type {JQuery<HTMLInputElement>} */
|
||||||
const novelPathInput = $('#parsePage #parse-page-novel-path');
|
const novelPathInput = $('#parsePage #parse-page-novel-path');
|
||||||
const pageInput = $('#parsePage #parse-page-index');
|
const pageInput = $('#parsePage #parse-page-index');
|
||||||
const latestChapter_item = $('#parseNovel latest-chapter-item');
|
|
||||||
const chapter_list = $('#parsePage .chapter-list');
|
const chapter_list = $('#parsePage .chapter-list');
|
||||||
const novelPath = novelPathInput.val();
|
const novelPath = novelPathInput.val();
|
||||||
const page = pageInput.val();
|
const page = pageInput.val();
|
||||||
@@ -895,12 +899,6 @@ class PluginWrapper {
|
|||||||
).json();
|
).json();
|
||||||
if ('error' in sourcePage)
|
if ('error' in sourcePage)
|
||||||
throw `Error getting the novel ${sourcePage.error}`;
|
throw `Error getting the novel ${sourcePage.error}`;
|
||||||
latestChapter_item.empty();
|
|
||||||
if (sourcePage.latestChapter) {
|
|
||||||
latestChapter_item.append(
|
|
||||||
PluginWrapper.createChapterItem(sourcePage.latestChapter),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
sourcePage?.chapters?.length !==
|
sourcePage?.chapters?.length !==
|
||||||
new Set(sourcePage?.chapters?.map(r => r.path) || []).size
|
new Set(sourcePage?.chapters?.map(r => r.path) || []).size
|
||||||
|
|||||||
+1
-1
@@ -32,11 +32,11 @@ export namespace Plugin {
|
|||||||
artist?: string;
|
artist?: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
chapters?: ChapterItem[];
|
chapters?: ChapterItem[];
|
||||||
|
latestChapter?: ChapterItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SourcePage {
|
export interface SourcePage {
|
||||||
chapters: ChapterItem[];
|
chapters: ChapterItem[];
|
||||||
latestChapter?: ChapterItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PopularNovelsOptions<
|
export interface PopularNovelsOptions<
|
||||||
|
|||||||
Reference in New Issue
Block a user