The Javascript API is a set of functions that used to interact application.
There are following parts in the API:
Convert is a set of functions that used to convert data between different types.
Convert a string to an ArrayBuffer.
Convert an ArrayBuffer to a string.
Convert an ArrayBuffer to a base64 string.
Convert a base64 string to an ArrayBuffer.
Calculate the md5 hash of an ArrayBuffer.
Calculate the sha1 hash of an ArrayBuffer.
Calculate the sha256 hash of an ArrayBuffer.
Calculate the sha512 hash of an ArrayBuffer.
Calculate the hmac hash of an ArrayBuffer.
Calculate the hmac hash of an ArrayBuffer and return a string.
Decrypt an ArrayBuffer with AES ECB mode.
Decrypt an ArrayBuffer with AES CBC mode.
Decrypt an ArrayBuffer with AES CFB mode.
Decrypt an ArrayBuffer with AES OFB mode.
Decrypt an ArrayBuffer with RSA.
Convert an ArrayBuffer to a hex string.
Network is a set of functions that used to send network requests and manage network resources.
Network.fetchBytes(method: string, url: string, headers: object, data: ArrayBuffer): Promise<{status: number, headers: object, body: ArrayBuffer}>
Send a network request and return the response as an ArrayBuffer.
Network.sendRequest(method: string, url: string, headers: object, data: ArrayBuffer): Promise<{status: number, headers: object, body: string}>
Send a network request and return the response as a string.
Send a GET request and return the response as a string.
Network.post(url: string, headers: object, data: ArrayBuffer): Promise<{status: number, headers: object, body: string}>
Send a POST request and return the response as a string.
Network.put(url: string, headers: object, data: ArrayBuffer): Promise<{status: number, headers: object, body: string}>
Send a PUT request and return the response as a string.
Network.delete(url: string, headers: object): Promise<{status: number, headers: object, body: string}>
Send a DELETE request and return the response as a string.
Network.patch(url: string, headers: object, data: ArrayBuffer): Promise<{status: number, headers: object, body: string}>
Send a PATCH request and return the response as a string.
Set cookies for a specific url.
Get cookies for a specific url.
Delete cookies for a specific url.
The fetch function is a wrapper of the Network.fetchBytes
function. Same as the fetch
function in the browser.
Api for parsing HTML.
Create a HtmlDocument object from a html string.
Find the first element that matches the selector.
Find all elements that match the selector.
Find the element with the id.
Dispose the HtmlDocument object.
Find the first element that matches the selector.
Find all elements that match the selector.
Find the element with the id.
Get the text content of the element.
Get the attributes of the element.
Get the children
Get the child nodes
Get the parent element
Get the inner html
Get the class names
Get the id
Get the local name
Get the previous sibling
Get the next sibling
Get the node type ("text", "element", "comment", "document", "unknown")
Convert the node to an element
Get the text content of the node
Show a message.
UI.showDialog(title: string, content: string, actions: {text: string, callback: () => void | Promise<void>, style: "text"|"filled"|"danger"}[]): void
Show a dialog. Any action will close the dialog.
Open a url in external browser.
Show a loading dialog.
Cancel a loading dialog.
Show an input dialog.
Show a select dialog.
create a time-based uuid.
Generate a random integer between min and max.
Generate a random double between min and max.
Send log to application console. Same api as the browser console.
/**
* Create a cookie object.
* @param name {string}
* @param value {string}
* @param domain {string}
* @constructor
*/
function Cookie({name, value, domain}) {
this.name = name;
this.value = value;
this.domain = domain;
}
/**
* Create a comic object
* @param id {string}
* @param title {string}
* @param subtitle {string}
* @param subTitle {string} - equal to subtitle
* @param cover {string}
* @param tags {string[]}
* @param description {string}
* @param maxPage {number?}
* @param language {string?}
* @param favoriteId {string?} - Only set this field if the comic is from favorites page
* @param stars {number?} - 0-5, double
* @constructor
*/
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;
this.maxPage = maxPage;
this.language = language;
this.favoriteId = favoriteId;
this.stars = stars;
}
/**
* Create a comic details object
* @param title {string}
* @param subtitle {string}
* @param subTitle {string} - equal to subtitle
* @param cover {string}
* @param description {string?}
* @param tags {Map<string, string[]> | {} | null | undefined}
* @param chapters {Map<string, string> | {} | 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
* @param commentCount {number?}
* @param likesCount {number?}
* @param isLiked {boolean?}
* @param uploader {string?}
* @param updateTime {string?}
* @param uploadTime {string?}
* @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, subtitle, subTitle, cover, description, tags, chapters, isFavorite, subId, thumbnails, recommend, commentCount, likesCount, isLiked, uploader, updateTime, uploadTime, url, stars, maxPage, comments}) {
this.title = title;
this.subtitle = subtitle ?? subTitle;
this.cover = cover;
this.description = description;
this.tags = tags;
this.chapters = chapters;
this.isFavorite = isFavorite;
this.subId = subId;
this.thumbnails = thumbnails;
this.recommend = recommend;
this.commentCount = commentCount;
this.likesCount = likesCount;
this.isLiked = isLiked;
this.uploader = uploader;
this.updateTime = updateTime;
this.uploadTime = uploadTime;
this.url = url;
this.stars = stars;
this.maxPage = maxPage;
this.comments = comments;
}
/**
* Create a comment object
* @param userName {string}
* @param avatar {string?}
* @param content {string}
* @param time {string?}
* @param replyCount {number?}
* @param id {string?}
* @param isLiked {boolean?}
* @param score {number?}
* @param voteStatus {number?} - 1: upvote, -1: downvote, 0: none
* @constructor
*/
function Comment({userName, avatar, content, time, replyCount, id, isLiked, score, voteStatus}) {
this.userName = userName;
this.avatar = avatar;
this.content = content;
this.time = time;
this.replyCount = replyCount;
this.id = id;
this.isLiked = isLiked;
this.score = score;
this.voteStatus = voteStatus;
}
/**
* Create image loading config
* @param url {string?}
* @param method {string?} - http method, uppercase
* @param data {any} - request data, may be null
* @param headers {Object?} - request headers
* @param onResponse {((ArrayBuffer) => ArrayBuffer)?} - modify response data
* @param modifyImage {string?}
* A js script string.
* The script will be executed in a new Isolate.
* A function named `modifyImage` should be defined in the script, which receives an [Image] as the only argument, and returns an [Image]..
* @param onLoadFailed {(() => ImageLoadingConfig)?} - called when the image loading failed
* @constructor
* @since 1.0.5
*
* To keep the compatibility with the old version, do not use the constructor. Consider creating a new object with the properties directly.
*/
function ImageLoadingConfig({url, method, data, headers, onResponse, modifyImage, onLoadFailed}) {
this.url = url;
this.method = method;
this.data = data;
this.headers = headers;
this.onResponse = onResponse;
this.modifyImage = modifyImage;
this.onLoadFailed = onLoadFailed;
}
class ComicSource {
name = ""
key = ""
version = ""
minAppVersion = ""
url = ""
/**
* load data with its key
* @param {string} dataKey
* @returns {any}
*/
loadData(dataKey) {
return sendMessage({
method: 'load_data',
key: this.key,
data_key: dataKey
})
}
/**
* load a setting with its key
* @param key {string}
* @returns {any}
*/
loadSetting(key) {
return sendMessage({
method: 'load_setting',
key: this.key,
setting_key: key
})
}
/**
* save data
* @param {string} dataKey
* @param data
*/
saveData(dataKey, data) {
return sendMessage({
method: 'save_data',
key: this.key,
data_key: dataKey,
data: data
})
}
/**
* delete data
* @param {string} dataKey
*/
deleteData(dataKey) {
return sendMessage({
method: 'delete_data',
key: this.key,
data_key: dataKey,
})
}
/**
*
* @returns {boolean}
*/
get isLogged() {
return sendMessage({
method: 'isLogged',
key: this.key,
});
}
init() { }
static sources = {}
}