-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathplugin.ts
More file actions
125 lines (118 loc) · 3.2 KB
/
plugin.ts
File metadata and controls
125 lines (118 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { FilterToValues, Filters } from '@libs/filterInputs';
export namespace Plugin {
export type ChapterItem = {
name: string;
path: string;
/**
* "YYYY-MM-DD" format or ISO string format
* ```js
* chapter.releaseTime = '2023-12-02';
* chapter.releaseTime = new Date(2023, 12, 02).toISOString();
* ```
* or just a string
*/
releaseTime?: string | null;
chapterNumber?: number;
/**
* For novel without pages only
*/
page?: string;
};
export type NovelItem = {
name: string;
path: string;
cover?: string;
};
export type SourceNovel = {
/** Comma separated genre list -> "action,fantasy,romance" */
genres?: string;
summary?: string;
author?: string;
artist?: string;
status?: string;
/** Rating out of 5 as float */
rating?: number;
chapters?: ChapterItem[];
} & NovelItem;
export type SourcePage = {
chapters: ChapterItem[];
};
export type PopularNovelsOptions<
Q extends Filters | undefined = Filters | undefined,
> = {
showLatestNovels?: boolean;
filters: Q extends undefined ? undefined : FilterToValues<Q>;
};
export type PluginItem = {
id: string;
name: string;
version: string;
icon: string;
site: string;
};
export type ImageRequestInit = {
method?: string;
headers?: Record<string, string>;
body?: string;
};
export type PluginBase = {
id: string;
name: string;
/**
* Relative path without static. E.g:
* ```js
* "src/vi/hakolightnovel/icon.png"
* ```
*/
icon: string;
customJS?: string;
customCSS?: string;
site: string;
imageRequestInit?: ImageRequestInit;
filters?: Filters;
version: string;
// Flag indicates whether access to LocalStorage, SesesionStorage is required.
webStorageUtilized?: boolean;
// Flag indicates whether chapter status is synced.
syncChapter?: boolean;
popularNovels(
pageNo: number,
options: PopularNovelsOptions<Filters>,
): Promise<NovelItem[]>;
/**
*
* @param novelPath
* @returns novel metadata and its first page
*/
parseNovel(novelPath: string): Promise<SourceNovel>;
parseChapter(chapterPath: string): Promise<string>;
handleChapterEvent?(
novelPath: string,
chapter: ChapterItem,
): Promise<boolean>;
searchNovels(searchTerm: string, pageNo: number): Promise<NovelItem[]>;
resolveUrl?(path: string, isNovel?: boolean): string;
};
export type PagePlugin = {
parseNovel(
novelPath: string,
): Promise<SourceNovel & { totalPages: number }>;
parsePage(novelPath: string, page: string): Promise<SourcePage>;
} & PluginBase;
}
export namespace HTMLParser2Util {
type HandlerBase = {
onopentag?(name: string, attribs: Record<string, string>): void;
ontext?(data: string): void;
onclosetag?(name: string, isImplied: boolean): void;
};
export type Handler = {
isStarted?: boolean;
isDone?: boolean;
} & HandlerBase;
// route htmlparser2 event to handlers
export type HandlerRouter<ActionType extends string> = {
handlers: Record<ActionType, Handler | undefined>;
action: ActionType;
} & HandlerBase;
}