diff --git a/_venera_.js b/_venera_.js index 6d08177..8ea0e8b 100644 --- a/_venera_.js +++ b/_venera_.js @@ -699,7 +699,7 @@ class HtmlElement { doc: this.doc, }) if(k == null) return null; - return new HtmlElement(k); + return new HtmlElement(k, this.doc); } /** @@ -850,6 +850,7 @@ let console = { * @param id {string} * @param title {string} * @param subtitle {string} + * @param subTitle {string} - equal to subtitle * @param cover {string} * @param tags {string[]} * @param description {string} @@ -859,10 +860,11 @@ let console = { * @param stars {number?} - 0-5, double * @constructor */ -function Comic({id, title, subtitle, cover, tags, description, maxPage, language, favoriteId, stars}) { +function Comic({id, title, subtitle, subTitle, cover, tags, description, maxPage, language, favoriteId, stars}) { this.id = id; this.title = title; this.subtitle = subtitle; + this.subTitle = subTitle; this.cover = cover; this.tags = tags; this.description = description; @@ -878,8 +880,8 @@ function Comic({id, title, subtitle, cover, tags, description, maxPage, language * @param cover {string} * @param description {string?} * @param tags {Map | {} | null | undefined} - * @param chapters {Map | {} | null | undefined}} - key: chapter id, value: chapter title - * @param isFavorite {boolean | null | undefined}} - favorite status. If the comic source supports multiple folders, this field should be null + * @param chapters {Map | {} | null | undefined} - key: chapter id, value: chapter title + * @param isFavorite {boolean | null | undefined} - favorite status. If the comic source supports multiple folders, this field should be null * @param subId {string?} - a param which is passed to comments api * @param thumbnails {string[]?} - for multiple page thumbnails, set this to null, and use `loadThumbnails` api to load thumbnails * @param recommend {Comic[]?} - related comics @@ -892,9 +894,10 @@ function Comic({id, title, subtitle, cover, tags, description, maxPage, language * @param url {string?} * @param stars {number?} - 0-5, double * @param maxPage {number?} + * @param comments {Comment[]?}- `since 1.0.7` App will display comments in the details page. * @constructor */ -function ComicDetails({title, cover, description, tags, chapters, isFavorite, subId, thumbnails, recommend, commentCount, likesCount, isLiked, uploader, updateTime, uploadTime, url, stars, maxPage}) { +function ComicDetails({title, cover, description, tags, chapters, isFavorite, subId, thumbnails, recommend, commentCount, likesCount, isLiked, uploader, updateTime, uploadTime, url, stars, maxPage, comments}) { this.title = title; this.cover = cover; this.description = description; @@ -913,6 +916,7 @@ function ComicDetails({title, cover, description, tags, chapters, isFavorite, su this.url = url; this.stars = stars; this.maxPage = maxPage; + this.comments = comments; } /** diff --git a/ehentai.js b/ehentai.js index d34866a..8cf2213 100644 --- a/ehentai.js +++ b/ehentai.js @@ -7,7 +7,7 @@ class Ehentai extends ComicSource { // unique id of the source key = "ehentai" - version = "1.0.9" + version = "1.0.10" minAppVersion = "1.0.0" @@ -681,6 +681,7 @@ class Ehentai extends ComicSource { if(subtitle != null && subtitle.trim() === "") { subtitle = null; } + let comments = this.comic.parseComments(document) let comic = new ComicDetails({ id: id, @@ -694,6 +695,7 @@ class Ehentai extends ComicSource { uploader: uploader, uploadTime: time, url: id, + comments: comments.comments, }) comic.folder = folder @@ -957,22 +959,7 @@ class Ehentai extends ComicSource { } } }, - /** - * [Optional] load comments - * @param comicId {string} - * @param subId {string?} - ComicDetails.subId - * @param page {number} - * @param replyTo {string?} - commentId to reply, not null when reply to a comment - * @returns {Promise<{comments: Comment[], maxPage: number?}>} - */ - loadComments: async (comicId, subId, page, replyTo) => { - let res = await Network.get(`${comicId}?hc=1`, { - 'cookie': 'nw=1' - }); - if(res.status !== 200) { - throw `Invalid status code: ${res.status}` - } - let document = new HtmlDocument(res.body) + parseComments: (document) => { let comments = [] for(let c of document.querySelectorAll('div.c1')) { let name = c.querySelector('div.c3 > a').text @@ -1002,13 +989,31 @@ class Ehentai extends ComicSource { })) } - document.dispose() - return { comments: comments, maxPage: 1 } }, + /** + * [Optional] load comments + * @param comicId {string} + * @param subId {string?} - ComicDetails.subId + * @param page {number} + * @param replyTo {string?} - commentId to reply, not null when reply to a comment + * @returns {Promise<{comments: Comment[], maxPage: number?}>} + */ + loadComments: async (comicId, subId, page, replyTo) => { + let res = await Network.get(`${comicId}?hc=1`, { + 'cookie': 'nw=1' + }); + if(res.status !== 200) { + throw `Invalid status code: ${res.status}` + } + let document = new HtmlDocument(res.body) + let result = this.comic.parseComments(document) + document.dispose() + return result + }, /** * [Optional] send a comment, return any value to indicate success * @param comicId {string} diff --git a/index.json b/index.json index d215a56..c28beed 100644 --- a/index.json +++ b/index.json @@ -45,7 +45,7 @@ "name": "ehentai", "fileName": "ehentai.js", "key": "ehentai", - "version": "1.0.9" + "version": "1.0.10" }, { "name": "禁漫天堂",