Update template

This commit is contained in:
2025-04-05 21:06:11 +08:00
parent aa96fef8fb
commit a5802d7a1e
2 changed files with 49 additions and 24 deletions

View File

@@ -1,3 +1,4 @@
/** @type {import('./_venera_.js')} */
class NewComicSource extends ComicSource { class NewComicSource extends ComicSource {
// Note: The fields which are marked as [Optional] should be removed if not used // Note: The fields which are marked as [Optional] should be removed if not used
@@ -9,7 +10,7 @@ class NewComicSource extends ComicSource {
version = "1.0.0" version = "1.0.0"
minAppVersion = "1.0.0" minAppVersion = "1.4.0"
// update url // update url
url = "" url = ""
@@ -126,7 +127,7 @@ class NewComicSource extends ComicSource {
* 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 {{}} * @returns {{}}
* - for `multiPartPage` type, return [{title: string, comics: Comic[], viewMore: string?}] * - for `multiPartPage` type, return [{title: string, comics: Comic[], viewMore: PageJumpTarget}]
* - for `multiPageComicList` type, for each page(1-based), return {comics: Comic[], maxPage: number} * - 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?} * - 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?}
*/ */
@@ -182,25 +183,37 @@ class NewComicSource extends ComicSource {
// title of the part // title of the part
name: "Theme", name: "Theme",
// fixed or random // fixed or random or dynamic
// if random, need to provide `randomNumber` field, which indicates the number of comics to display at the same time // if random, need to provide `randomNumber` field, which indicates the number of comics to display at the same time
// if dynamic, need to provide `loader` field, which indicates the function to load comics
type: "fixed", type: "fixed",
// Remove this if type is dynamic
categories: [
{
label: "Category1",
/**
* @type {PageJumpTarget}
*/
target: {
page: "category",
attributes: {
category: "category1",
param: null,
},
},
},
]
// number of comics to display at the same time // number of comics to display at the same time
// randomNumber: 5, // randomNumber: 5,
categories: ["All", "Adventure", "School"], // load function for dynamic type
// loader: async () => {
// category or search // return [
// if `category`, use categoryComics.load to load comics // // ...
// if `search`, use search.load to load comics // ]
itemType: "category", // }
// [Optional] {string[]?} must have same length as categories, used to provide loading param for each category
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
@@ -303,7 +316,7 @@ class NewComicSource extends ComicSource {
/** /**
* load search result * load search result
* @param keyword {string} * @param keyword {string}
* @param options {(string | null)[]} - options from optionList * @param options {string[]} - options from optionList
* @param page {number} * @param page {number}
* @returns {Promise<{comics: Comic[], maxPage: number}>} * @returns {Promise<{comics: Comic[], maxPage: number}>}
*/ */
@@ -362,7 +375,7 @@ class NewComicSource extends ComicSource {
], ],
// option label // option label
label: "sort", label: "sort",
// default selected options // default selected options. If not set, use the first option as default
default: null, default: null,
} }
], ],
@@ -671,18 +684,16 @@ class NewComicSource extends ComicSource {
* [Optional] Handle tag click event * [Optional] Handle tag click event
* @param namespace {string} * @param namespace {string}
* @param tag {string} * @param tag {string}
* @returns {{action: string, keyword: string, param: string?}} * @returns {PageJumpTarget}
*/ */
onClickTag: (namespace, tag) => { onClickTag: (namespace, tag) => {
/* /*
``` ```
return { return new PageJumpTarget({
// 'search' or 'category' page: 'search',
action: 'search',
keyword: tag, keyword: tag,
// {string?} only for category action })
param: null, ```
}
*/ */
}, },
/** /**

View File

@@ -1012,6 +1012,20 @@ function ImageLoadingConfig({url, method, data, headers, onResponse, modifyImage
this.onLoadFailed = onLoadFailed; this.onLoadFailed = onLoadFailed;
} }
/**
* @typedef {Object} PageJumpTarget
* @Property {string} page - The page name (search, category)
* @Property {Object} attributes - The attributes of the page
*
* @example
* {
* page: "search",
* attributes: {
* keyword: "example",
* },
* }
*/
class ComicSource { class ComicSource {
name = "" name = ""