add nhentai & update template

This commit is contained in:
nyne
2024-10-17 12:24:37 +08:00
parent f072b27d67
commit 0b2c50c491
4 changed files with 1366 additions and 29 deletions

View File

@@ -51,6 +51,22 @@ class NewComicSource extends ComicSource {
}, },
/**
* [Optional] login with webview
*/
loginWithWebview: {
url: "",
/**
* check login status
* @param url {string} - current url
* @param title {string} - current title
* @returns {boolean} - return true if login success
*/
checkStatus: (url, title) => {
},
},
/** /**
* logout function, clear account related data * logout function, clear account related data
*/ */
@@ -74,13 +90,16 @@ class NewComicSource extends ComicSource {
// title is used to identify the page, it should be unique // title is used to identify the page, it should be unique
title: "", title: "",
/// singlePageWithMultiPart or multiPageComicList /// multiPartPage or multiPageComicList or mixed
type: "singlePageWithMultiPart", type: "multiPartPage",
/** /**
* load function * load function
* @param page {number | null} - page number, null for `singlePageWithMultiPart` type * @param page {number | null} - page number, null for `singlePageWithMultiPart` type
* @returns {{}} - for `singlePageWithMultiPart` type, return {[string]: Comic[]}; for `multiPageComicList` type, return {comics: Comic[], maxPage: number} * @returns {{}}
* - for `multiPartPage` type, return [{title: string, comics: Comic[], viewMore: string?}]
* - for `multiPageComicList` type, for each page(1-based), return {comics: Comic[], maxPage: number}
* - for `mixed` type, use param `page` as index. for each index(0-based), return {data: [], maxPage: number?}, data is an array contains Comic[] or {title: string, comics: Comic[], viewMore: string?}
*/ */
load: async (page) => { load: async (page) => {
/* /*
@@ -140,8 +159,11 @@ class NewComicSource extends ComicSource {
// if `search`, use search.load to load comics // if `search`, use search.load to load comics
itemType: "category", itemType: "category",
// [Optional] must have same length as categories, used to provide loading param for each category // [Optional] {string[]?} must have same length as categories, used to provide loading param for each category
categoryParams: ["all", "adventure", "school"] categoryParams: ["all", "adventure", "school"],
// [Optional] {string} cannot be used with `categoryParams`, set all category params to this value
groupParam: null,
} }
], ],
// enable ranking page // enable ranking page
@@ -286,7 +308,10 @@ class NewComicSource extends ComicSource {
// option label // option label
label: "sort" label: "sort"
} }
] ],
// enable tags suggestions
enableTagsSuggestions: false,
} }
// favorite related // favorite related
@@ -572,6 +597,27 @@ class NewComicSource extends ComicSource {
} }
*/ */
}, },
/**
* [Optional] Handle links
*/
link: {
/**
* set accepted domains
*/
domains: [
'example.com'
],
/**
* parse url to comic id
* @param url {string}
* @returns {string | null}
*/
linkToId: (url) => {
}
},
// enable tags translate
enableTagsTranslate: false,
} }

View File

@@ -307,7 +307,7 @@ let Network = {
* @param {string} url - The URL to send the request to. * @param {string} url - The URL to send the request to.
* @param {Object} headers - The headers to include in the request. * @param {Object} headers - The headers to include in the request.
* @param data - The data to send with the request. * @param data - The data to send with the request.
* @returns {Promise<ArrayBuffer>} The response from the request. * @returns {Promise<{status: number, headers: {}, body: ArrayBuffer}>} The response from the request.
*/ */
async fetchBytes(method, url, headers, data) { async fetchBytes(method, url, headers, data) {
let result = await sendMessage({ let result = await sendMessage({
@@ -332,7 +332,7 @@ let Network = {
* @param {string} url - The URL to send the request to. * @param {string} url - The URL to send the request to.
* @param {Object} headers - The headers to include in the request. * @param {Object} headers - The headers to include in the request.
* @param data - The data to send with the request. * @param data - The data to send with the request.
* @returns {Promise<Object>} The response from the request. * @returns {Promise<{status: number, headers: {}, body: string}>} The response from the request.
*/ */
async sendRequest(method, url, headers, data) { async sendRequest(method, url, headers, data) {
let result = await sendMessage({ let result = await sendMessage({
@@ -354,7 +354,7 @@ let Network = {
* Sends an HTTP GET request. * Sends an HTTP GET request.
* @param {string} url - The URL to send the request to. * @param {string} url - The URL to send the request to.
* @param {Object} headers - The headers to include in the request. * @param {Object} headers - The headers to include in the request.
* @returns {Promise<Object>} The response from the request. * @returns {Promise<{status: number, headers: {}, body: string}>} The response from the request.
*/ */
async get(url, headers) { async get(url, headers) {
return this.sendRequest('GET', url, headers); return this.sendRequest('GET', url, headers);
@@ -365,7 +365,7 @@ let Network = {
* @param {string} url - The URL to send the request to. * @param {string} url - The URL to send the request to.
* @param {Object} headers - The headers to include in the request. * @param {Object} headers - The headers to include in the request.
* @param data - The data to send with the request. * @param data - The data to send with the request.
* @returns {Promise<Object>} The response from the request. * @returns {Promise<{status: number, headers: {}, body: string}>} The response from the request.
*/ */
async post(url, headers, data) { async post(url, headers, data) {
return this.sendRequest('POST', url, headers, data); return this.sendRequest('POST', url, headers, data);
@@ -376,7 +376,7 @@ let Network = {
* @param {string} url - The URL to send the request to. * @param {string} url - The URL to send the request to.
* @param {Object} headers - The headers to include in the request. * @param {Object} headers - The headers to include in the request.
* @param data - The data to send with the request. * @param data - The data to send with the request.
* @returns {Promise<Object>} The response from the request. * @returns {Promise<{status: number, headers: {}, body: string}>} The response from the request.
*/ */
async put(url, headers, data) { async put(url, headers, data) {
return this.sendRequest('PUT', url, headers, data); return this.sendRequest('PUT', url, headers, data);
@@ -387,7 +387,7 @@ let Network = {
* @param {string} url - The URL to send the request to. * @param {string} url - The URL to send the request to.
* @param {Object} headers - The headers to include in the request. * @param {Object} headers - The headers to include in the request.
* @param data - The data to send with the request. * @param data - The data to send with the request.
* @returns {Promise<Object>} The response from the request. * @returns {Promise<{status: number, headers: {}, body: string}>} The response from the request.
*/ */
async patch(url, headers, data) { async patch(url, headers, data) {
return this.sendRequest('PATCH', url, headers, data); return this.sendRequest('PATCH', url, headers, data);
@@ -397,7 +397,7 @@ let Network = {
* Sends an HTTP DELETE request. * Sends an HTTP DELETE request.
* @param {string} url - The URL to send the request to. * @param {string} url - The URL to send the request to.
* @param {Object} headers - The headers to include in the request. * @param {Object} headers - The headers to include in the request.
* @returns {Promise<Object>} The response from the request. * @returns {Promise<{status: number, headers: {}, body: string}>} The response from the request.
*/ */
async delete(url, headers) { async delete(url, headers) {
return this.sendRequest('DELETE', url, headers); return this.sendRequest('DELETE', url, headers);
@@ -579,6 +579,91 @@ class HtmlElement {
}) })
return ks.map(k => new HtmlElement(k)); return ks.map(k => new HtmlElement(k));
} }
/**
* Get the nodes of the current element.
* @returns {HtmlNode[]} An array of nodes.
*/
get nodes() {
let ks = sendMessage({
method: "html",
function: "getNodes",
key: this.key
})
return ks.map(k => new HtmlNode(k));
}
/**
* Get inner HTML of the element.
* @returns {string} The inner HTML.
*/
get innerHTML() {
return sendMessage({
method: "html",
function: "getInnerHTML",
key: this.key
})
}
/**
* Get parent element of the element. If the element has no parent, return null.
* @returns {HtmlElement|null}
*/
get parent() {
let k = sendMessage({
method: "html",
function: "getParent",
key: this.key
})
if(!k) return null;
return new HtmlElement(k);
}
}
class HtmlNode {
key = 0;
constructor(k) {
this.key = k;
}
/**
* Get the text content of the node.
* @returns {string} The text content.
*/
get text() {
return sendMessage({
method: "html",
function: "node_text",
key: this.key
})
}
/**
* Get the type of the node.
* @returns {string} The type of the node. ("text", "element", "comment", "document", "unknown")
*/
get type() {
return sendMessage({
method: "html",
function: "node_type",
key: this.key
})
}
/**
* Convert the node to an HtmlElement. If the node is not an element, return null.
* @returns {HtmlElement|null}
*/
toElement() {
let k = sendMessage({
method: "html",
function: "node_toElement",
key: this.key
})
if(!k) return null;
return new HtmlElement(k);
}
} }
function log(level, title, content) { function log(level, title, content) {
@@ -610,10 +695,11 @@ let console = {
* @param cover {string} * @param cover {string}
* @param tags {string[]} * @param tags {string[]}
* @param description {string} * @param description {string}
* @param maxPage {number | null} * @param maxPage {number?}
* @param language {string?}
* @constructor * @constructor
*/ */
function Comic({id, title, subtitle, cover, tags, description, maxPage}) { function Comic({id, title, subtitle, cover, tags, description, maxPage, language}) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.subtitle = subtitle; this.subtitle = subtitle;
@@ -621,26 +707,27 @@ function Comic({id, title, subtitle, cover, tags, description, maxPage}) {
this.tags = tags; this.tags = tags;
this.description = description; this.description = description;
this.maxPage = maxPage; this.maxPage = maxPage;
this.language = language;
} }
/** /**
* Create a comic details object * Create a comic details object
* @param title {string} * @param title {string}
* @param cover {string} * @param cover {string}
* @param description {string | null} * @param description {string?}
* @param tags {Map<string, string[]> | {} | null} * @param tags {Map<string, string[]> | {} | null | undefined}
* @param chapters {Map<string, string> | {} | null} - key: chapter id, value: chapter title * @param chapters {Map<string, string> | {} | null | undefined}} - key: chapter id, value: chapter title
* @param isFavorite {boolean | null} - favorite status. If the comic source supports multiple folders, this field should be null * @param isFavorite {boolean | null | undefined}} - favorite status. If the comic source supports multiple folders, this field should be null
* @param subId {string | null} - a param which is passed to comments api * @param subId {string?} - a param which is passed to comments api
* @param thumbnails {string[] | null} - for multiple page thumbnails, set this to null, and use `loadThumbnails` api to load thumbnails * @param thumbnails {string[]?} - for multiple page thumbnails, set this to null, and use `loadThumbnails` api to load thumbnails
* @param recommend {Comic[] | null} - related comics * @param recommend {Comic[]?} - related comics
* @param commentCount {number | null} * @param commentCount {number?}
* @param likesCount {number | null} * @param likesCount {number?}
* @param isLiked {boolean | null} * @param isLiked {boolean?}
* @param uploader {string | null} * @param uploader {string?}
* @param updateTime {string | null} * @param updateTime {string?}
* @param uploadTime {string | null} * @param uploadTime {string?}
* @param url {string | null} * @param url {string?}
* @constructor * @constructor
*/ */
function ComicDetails({title, cover, description, tags, chapters, isFavorite, subId, thumbnails, recommend, commentCount, likesCount, isLiked, uploader, updateTime, uploadTime, url}) { function ComicDetails({title, cover, description, tags, chapters, isFavorite, subId, thumbnails, recommend, commentCount, likesCount, isLiked, uploader, updateTime, uploadTime, url}) {

View File

@@ -28,5 +28,11 @@
"fileName": "picacg.js", "fileName": "picacg.js",
"key": "picacg", "key": "picacg",
"version": "1.0.0" "version": "1.0.0"
},
{
"name": "nhentai",
"fileName": "nhentai.js",
"key": "nhentai",
"version": "1.0.0"
} }
] ]

1198
nhentai.js Normal file

File diff suppressed because it is too large Load Diff