@danmaku-anywhere/extension-protocol 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/src/handshake.d.ts +6 -0
- package/dist/src/handshake.js +15 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +4 -0
- package/dist/src/kazumi.d.ts +136 -0
- package/dist/src/kazumi.js +106 -0
- package/dist/src/messages.d.ts +81 -0
- package/dist/src/messages.js +14 -0
- package/dist/src/payloads.d.ts +33 -0
- package/dist/src/payloads.js +1 -0
- package/package.json +44 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Copyright (c) Mr-Quin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @danmaku-anywhere/extension-protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The messages the Danmaku Anywhere extension exchanges with the pages it talks to, such as the web app: action and message types, request and response helpers, the attributes the extension sets on the page so the page can detect it, and the Kazumi policy schema those messages carry.
|
|
4
|
+
|
|
5
|
+
It has no Chrome dependency. The helpers that read and write the page attributes need a DOM.
|
|
6
|
+
|
|
7
|
+
Whatever goes over the wire (action names, message fields, source strings, attribute names) has to stay compatible with extension versions that are already installed.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const DA_EXT_ATTR = 'da-ext-version';
|
|
2
|
+
export const setExtensionAttr = (info) => {
|
|
3
|
+
document.documentElement.setAttribute(DA_EXT_ATTR, info.version);
|
|
4
|
+
if (info.id) {
|
|
5
|
+
document.documentElement.setAttribute('da-ext-id', info.id);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
export const getExtensionAttr = () => {
|
|
9
|
+
const version = document.documentElement.getAttribute('da-ext-version');
|
|
10
|
+
const id = document.documentElement.getAttribute('da-ext-id');
|
|
11
|
+
return {
|
|
12
|
+
version: version ?? undefined,
|
|
13
|
+
id: id ?? undefined,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const zKazumiManifest: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
version: z.ZodString;
|
|
5
|
+
useNativePlayer: z.ZodBoolean;
|
|
6
|
+
author: z.ZodString;
|
|
7
|
+
lastUpdate: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export type KazumiManifest = z.output<typeof zKazumiManifest>;
|
|
10
|
+
declare const zKazumiApiRequest: z.ZodObject<{
|
|
11
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
12
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
13
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
14
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
15
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
16
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
17
|
+
}, z.core.$loose>;
|
|
18
|
+
export type KazumiApiRequest = z.output<typeof zKazumiApiRequest>;
|
|
19
|
+
export declare const zKazumiSearchApiConfig: z.ZodObject<{
|
|
20
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
21
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
22
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
23
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
25
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
26
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
27
|
+
}, z.core.$loose>>;
|
|
28
|
+
listPath: z.ZodPrefault<z.ZodString>;
|
|
29
|
+
namePath: z.ZodPrefault<z.ZodString>;
|
|
30
|
+
sourcePath: z.ZodPrefault<z.ZodString>;
|
|
31
|
+
sourceTemplate: z.ZodPrefault<z.ZodString>;
|
|
32
|
+
}, z.core.$loose>;
|
|
33
|
+
export type KazumiSearchApiConfig = z.output<typeof zKazumiSearchApiConfig>;
|
|
34
|
+
export declare const zKazumiEpisodePage: z.ZodObject<{
|
|
35
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
36
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
37
|
+
}, z.core.$loose>;
|
|
38
|
+
export type KazumiEpisodePage = z.output<typeof zKazumiEpisodePage>;
|
|
39
|
+
export declare const zKazumiChapterApiConfig: z.ZodObject<{
|
|
40
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
41
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
42
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
43
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
44
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
45
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
46
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
47
|
+
}, z.core.$loose>>;
|
|
48
|
+
format: z.ZodPrefault<z.ZodString>;
|
|
49
|
+
roadsPath: z.ZodPrefault<z.ZodString>;
|
|
50
|
+
roadNamePath: z.ZodPrefault<z.ZodString>;
|
|
51
|
+
episodesPath: z.ZodPrefault<z.ZodString>;
|
|
52
|
+
episodeNamePath: z.ZodPrefault<z.ZodString>;
|
|
53
|
+
episodeUrlPath: z.ZodPrefault<z.ZodString>;
|
|
54
|
+
roadNamesPath: z.ZodPrefault<z.ZodString>;
|
|
55
|
+
roadEpisodesPath: z.ZodPrefault<z.ZodString>;
|
|
56
|
+
roadSeparator: z.ZodPrefault<z.ZodString>;
|
|
57
|
+
episodeSeparator: z.ZodPrefault<z.ZodString>;
|
|
58
|
+
fieldSeparator: z.ZodPrefault<z.ZodString>;
|
|
59
|
+
variables: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
60
|
+
episodePage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
61
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
62
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
63
|
+
}, z.core.$loose>>>;
|
|
64
|
+
}, z.core.$loose>;
|
|
65
|
+
export type KazumiChapterApiConfig = z.output<typeof zKazumiChapterApiConfig>;
|
|
66
|
+
export declare const zKazumiPolicy: z.ZodObject<{
|
|
67
|
+
api: z.ZodString;
|
|
68
|
+
type: z.ZodString;
|
|
69
|
+
name: z.ZodString;
|
|
70
|
+
version: z.ZodString;
|
|
71
|
+
muliSources: z.ZodPrefault<z.ZodBoolean>;
|
|
72
|
+
useWebview: z.ZodPrefault<z.ZodBoolean>;
|
|
73
|
+
useNativePlayer: z.ZodPrefault<z.ZodBoolean>;
|
|
74
|
+
usePost: z.ZodPrefault<z.ZodBoolean>;
|
|
75
|
+
useLegacyParser: z.ZodPrefault<z.ZodBoolean>;
|
|
76
|
+
userAgent: z.ZodPrefault<z.ZodString>;
|
|
77
|
+
baseURL: z.ZodString;
|
|
78
|
+
searchMode: z.ZodPrefault<z.ZodEnum<{
|
|
79
|
+
api: "api";
|
|
80
|
+
xpath: "xpath";
|
|
81
|
+
}>>;
|
|
82
|
+
chapterMode: z.ZodPrefault<z.ZodEnum<{
|
|
83
|
+
api: "api";
|
|
84
|
+
xpath: "xpath";
|
|
85
|
+
}>>;
|
|
86
|
+
searchURL: z.ZodPrefault<z.ZodString>;
|
|
87
|
+
searchList: z.ZodPrefault<z.ZodString>;
|
|
88
|
+
searchName: z.ZodPrefault<z.ZodString>;
|
|
89
|
+
searchResult: z.ZodPrefault<z.ZodString>;
|
|
90
|
+
chapterRoads: z.ZodPrefault<z.ZodString>;
|
|
91
|
+
chapterResult: z.ZodPrefault<z.ZodString>;
|
|
92
|
+
referer: z.ZodPrefault<z.ZodString>;
|
|
93
|
+
searchApiConfig: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
94
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
95
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
96
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
97
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
98
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
99
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
100
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
101
|
+
}, z.core.$loose>>;
|
|
102
|
+
listPath: z.ZodPrefault<z.ZodString>;
|
|
103
|
+
namePath: z.ZodPrefault<z.ZodString>;
|
|
104
|
+
sourcePath: z.ZodPrefault<z.ZodString>;
|
|
105
|
+
sourceTemplate: z.ZodPrefault<z.ZodString>;
|
|
106
|
+
}, z.core.$loose>>>;
|
|
107
|
+
chapterApiConfig: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
108
|
+
request: z.ZodPrefault<z.ZodObject<{
|
|
109
|
+
method: z.ZodPrefault<z.ZodString>;
|
|
110
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
111
|
+
headers: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
112
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
113
|
+
bodyType: z.ZodPrefault<z.ZodString>;
|
|
114
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
115
|
+
}, z.core.$loose>>;
|
|
116
|
+
format: z.ZodPrefault<z.ZodString>;
|
|
117
|
+
roadsPath: z.ZodPrefault<z.ZodString>;
|
|
118
|
+
roadNamePath: z.ZodPrefault<z.ZodString>;
|
|
119
|
+
episodesPath: z.ZodPrefault<z.ZodString>;
|
|
120
|
+
episodeNamePath: z.ZodPrefault<z.ZodString>;
|
|
121
|
+
episodeUrlPath: z.ZodPrefault<z.ZodString>;
|
|
122
|
+
roadNamesPath: z.ZodPrefault<z.ZodString>;
|
|
123
|
+
roadEpisodesPath: z.ZodPrefault<z.ZodString>;
|
|
124
|
+
roadSeparator: z.ZodPrefault<z.ZodString>;
|
|
125
|
+
episodeSeparator: z.ZodPrefault<z.ZodString>;
|
|
126
|
+
fieldSeparator: z.ZodPrefault<z.ZodString>;
|
|
127
|
+
variables: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
128
|
+
episodePage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
129
|
+
url: z.ZodPrefault<z.ZodString>;
|
|
130
|
+
query: z.ZodPrefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
131
|
+
}, z.core.$loose>>>;
|
|
132
|
+
}, z.core.$loose>>>;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
export type KazumiPolicy = z.output<typeof zKazumiPolicy>;
|
|
135
|
+
export declare function isXPathPolicy(policy: KazumiPolicy): boolean;
|
|
136
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const zKazumiManifest = z.object({
|
|
3
|
+
name: z.string(),
|
|
4
|
+
version: z.string(),
|
|
5
|
+
useNativePlayer: z.boolean(),
|
|
6
|
+
author: z.string(),
|
|
7
|
+
lastUpdate: z.number(),
|
|
8
|
+
});
|
|
9
|
+
const zKazumiRuleMode = z.enum(['xpath', 'api']).prefault('xpath');
|
|
10
|
+
// A rule that searches or lists chapters through an API describes the request
|
|
11
|
+
// as a template (values reference @keyword for search and @source for
|
|
12
|
+
// chapters) and reads the response with JSONPath expressions. Unknown fields
|
|
13
|
+
// are kept because Kazumi grows the format independently of this schema.
|
|
14
|
+
const zKazumiApiRequest = z.looseObject({
|
|
15
|
+
method: z.string().prefault('GET'),
|
|
16
|
+
url: z.string().prefault(''),
|
|
17
|
+
headers: z.record(z.string(), z.unknown()).prefault({}),
|
|
18
|
+
query: z.record(z.string(), z.unknown()).prefault({}),
|
|
19
|
+
bodyType: z.string().prefault('none'),
|
|
20
|
+
body: z.unknown().optional(),
|
|
21
|
+
});
|
|
22
|
+
export const zKazumiSearchApiConfig = z.looseObject({
|
|
23
|
+
request: zKazumiApiRequest.prefault({}),
|
|
24
|
+
listPath: z.string().prefault('$.data[*]'),
|
|
25
|
+
namePath: z.string().prefault('$.name'),
|
|
26
|
+
sourcePath: z.string().prefault('$.url'),
|
|
27
|
+
sourceTemplate: z.string().prefault(''),
|
|
28
|
+
});
|
|
29
|
+
export const zKazumiEpisodePage = z.looseObject({
|
|
30
|
+
url: z.string().prefault(''),
|
|
31
|
+
query: z.record(z.string(), z.unknown()).prefault({}),
|
|
32
|
+
});
|
|
33
|
+
export const zKazumiChapterApiConfig = z.looseObject({
|
|
34
|
+
request: zKazumiApiRequest.prefault({}),
|
|
35
|
+
format: z.string().prefault('nested'),
|
|
36
|
+
roadsPath: z.string().prefault('$.data.roads[*]'),
|
|
37
|
+
roadNamePath: z.string().prefault('$.name'),
|
|
38
|
+
episodesPath: z.string().prefault('$.episodes[*]'),
|
|
39
|
+
episodeNamePath: z.string().prefault('$.name'),
|
|
40
|
+
episodeUrlPath: z.string().prefault('$.url'),
|
|
41
|
+
roadNamesPath: z.string().prefault(''),
|
|
42
|
+
roadEpisodesPath: z.string().prefault(''),
|
|
43
|
+
roadSeparator: z.string().prefault('$$$'),
|
|
44
|
+
episodeSeparator: z.string().prefault('#'),
|
|
45
|
+
fieldSeparator: z.string().prefault('$'),
|
|
46
|
+
variables: z.record(z.string(), z.string()).prefault({}),
|
|
47
|
+
episodePage: zKazumiEpisodePage.nullish(),
|
|
48
|
+
});
|
|
49
|
+
const searchSelectors = [
|
|
50
|
+
'searchURL',
|
|
51
|
+
'searchList',
|
|
52
|
+
'searchName',
|
|
53
|
+
'searchResult',
|
|
54
|
+
];
|
|
55
|
+
const chapterSelectors = ['chapterRoads', 'chapterResult'];
|
|
56
|
+
// A rule that searches or lists chapters through an API leaves the matching
|
|
57
|
+
// XPath fields empty, so emptiness is only an error in xpath mode.
|
|
58
|
+
export const zKazumiPolicy = z
|
|
59
|
+
.object({
|
|
60
|
+
api: z.string(),
|
|
61
|
+
type: z.string(),
|
|
62
|
+
name: z.string().min(1),
|
|
63
|
+
version: z.string(),
|
|
64
|
+
muliSources: z.boolean().prefault(false),
|
|
65
|
+
useWebview: z.boolean().prefault(false),
|
|
66
|
+
useNativePlayer: z.boolean().prefault(false),
|
|
67
|
+
usePost: z.boolean().prefault(false),
|
|
68
|
+
useLegacyParser: z.boolean().prefault(false),
|
|
69
|
+
userAgent: z.string().prefault(''),
|
|
70
|
+
baseURL: z.string().min(1),
|
|
71
|
+
searchMode: zKazumiRuleMode,
|
|
72
|
+
chapterMode: zKazumiRuleMode,
|
|
73
|
+
searchURL: z.string().prefault(''),
|
|
74
|
+
searchList: z.string().prefault(''),
|
|
75
|
+
searchName: z.string().prefault(''),
|
|
76
|
+
searchResult: z.string().prefault(''),
|
|
77
|
+
chapterRoads: z.string().prefault(''),
|
|
78
|
+
chapterResult: z.string().prefault(''),
|
|
79
|
+
referer: z.string().prefault(''),
|
|
80
|
+
searchApiConfig: zKazumiSearchApiConfig.nullish(),
|
|
81
|
+
chapterApiConfig: zKazumiChapterApiConfig.nullish(),
|
|
82
|
+
})
|
|
83
|
+
.superRefine((policy, ctx) => {
|
|
84
|
+
const required = [];
|
|
85
|
+
if (policy.searchMode === 'xpath') {
|
|
86
|
+
required.push(...searchSelectors);
|
|
87
|
+
}
|
|
88
|
+
if (policy.chapterMode === 'xpath') {
|
|
89
|
+
required.push(...chapterSelectors);
|
|
90
|
+
}
|
|
91
|
+
for (const key of required) {
|
|
92
|
+
if (policy[key] === '') {
|
|
93
|
+
ctx.addIssue({
|
|
94
|
+
code: 'custom',
|
|
95
|
+
path: [key],
|
|
96
|
+
message: `${key} is required in xpath mode`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
// Whether every step of a rule opens a page and reads it with XPath, as
|
|
102
|
+
// opposed to a step that goes through an API. Rules stored before the mode
|
|
103
|
+
// fields existed have no mode at all, and are xpath rules.
|
|
104
|
+
export function isXPathPolicy(policy) {
|
|
105
|
+
return policy.searchMode !== 'api' && policy.chapterMode !== 'api';
|
|
106
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CommentEntity, GenericEpisodeLite } from '@danmaku-anywhere/danmaku-model';
|
|
2
|
+
import type { KazumiPolicy } from './kazumi.js';
|
|
3
|
+
import type { HTTPHeader, MediaInfo } from './payloads.js';
|
|
4
|
+
export declare const DA_EXT_SOURCE_CONTENT = "content-script";
|
|
5
|
+
export declare const DA_EXT_SOURCE_APP = "app";
|
|
6
|
+
export type ExtMessageSource = typeof DA_EXT_SOURCE_CONTENT | typeof DA_EXT_SOURCE_APP;
|
|
7
|
+
export type ExtActionType = keyof ExtAction;
|
|
8
|
+
export type ExtActionDef<TIn, TOut> = {
|
|
9
|
+
input: TIn;
|
|
10
|
+
output: TOut;
|
|
11
|
+
};
|
|
12
|
+
export type ExtAction = {
|
|
13
|
+
kazumiSearch: ExtActionDef<{
|
|
14
|
+
keyword: string;
|
|
15
|
+
policy: KazumiPolicy;
|
|
16
|
+
}, {
|
|
17
|
+
name: string;
|
|
18
|
+
url: string;
|
|
19
|
+
}[]>;
|
|
20
|
+
kazumiGetChapters: ExtActionDef<{
|
|
21
|
+
url: string;
|
|
22
|
+
policy: KazumiPolicy;
|
|
23
|
+
}, {
|
|
24
|
+
name: string;
|
|
25
|
+
url: string;
|
|
26
|
+
}[][]>;
|
|
27
|
+
extractMedia: ExtActionDef<{
|
|
28
|
+
url: string;
|
|
29
|
+
}, MediaInfo>;
|
|
30
|
+
episodeGetAll: ExtActionDef<void, GenericEpisodeLite[]>;
|
|
31
|
+
danmakuGet: ExtActionDef<GenericEpisodeLite, CommentEntity[]>;
|
|
32
|
+
setRequestHeaders: ExtActionDef<SetHeaderRule, number | undefined>;
|
|
33
|
+
removeRequestHeaders: ExtActionDef<{
|
|
34
|
+
ruleId: number;
|
|
35
|
+
}, void>;
|
|
36
|
+
};
|
|
37
|
+
type ExtRequestBase<T extends ExtActionType> = {
|
|
38
|
+
id: string;
|
|
39
|
+
type: 'request';
|
|
40
|
+
action: T;
|
|
41
|
+
data: ExtAction[T]['input'];
|
|
42
|
+
source: ExtMessageSource;
|
|
43
|
+
};
|
|
44
|
+
type ExtRequestMap = {
|
|
45
|
+
[K in ExtActionType]: ExtRequestBase<K>;
|
|
46
|
+
};
|
|
47
|
+
export type ExtRequest = ExtRequestMap[ExtActionType];
|
|
48
|
+
export type ExtResponseSuccess<T extends ExtActionType = ExtActionType> = {
|
|
49
|
+
id: string;
|
|
50
|
+
type: 'response';
|
|
51
|
+
action: T;
|
|
52
|
+
success: true;
|
|
53
|
+
source: ExtMessageSource;
|
|
54
|
+
isLast: boolean;
|
|
55
|
+
data: ExtAction[T]['output'];
|
|
56
|
+
};
|
|
57
|
+
export type ExtResponseError = {
|
|
58
|
+
id: string;
|
|
59
|
+
type: 'response';
|
|
60
|
+
action: ExtActionType;
|
|
61
|
+
success: false;
|
|
62
|
+
source: ExtMessageSource;
|
|
63
|
+
isLast: true;
|
|
64
|
+
err: string;
|
|
65
|
+
};
|
|
66
|
+
export type ExtResponse<T extends ExtActionType = ExtActionType> = ExtResponseSuccess<T> | ExtResponseError;
|
|
67
|
+
export type ExtMessage = ExtRequest | ExtResponse;
|
|
68
|
+
export declare const createExtRequest: <T extends ExtActionType>(req: {
|
|
69
|
+
id: string;
|
|
70
|
+
action: T;
|
|
71
|
+
data: ExtAction[T]['input'];
|
|
72
|
+
source: ExtMessageSource;
|
|
73
|
+
}) => ExtRequestBase<T>;
|
|
74
|
+
export declare const createExtResponse: <T extends ExtActionType>(req: Omit<ExtResponseSuccess<T>, 'type'> | Omit<ExtResponseError, 'type'>) => ExtResponse<T>;
|
|
75
|
+
export type SetHeaderRule = {
|
|
76
|
+
headers?: HTTPHeader[];
|
|
77
|
+
url: string;
|
|
78
|
+
referer: string;
|
|
79
|
+
origin?: string;
|
|
80
|
+
};
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const DA_EXT_SOURCE_CONTENT = 'content-script';
|
|
2
|
+
export const DA_EXT_SOURCE_APP = 'app';
|
|
3
|
+
export const createExtRequest = (req) => {
|
|
4
|
+
return {
|
|
5
|
+
...req,
|
|
6
|
+
type: 'request',
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export const createExtResponse = (req) => {
|
|
10
|
+
return {
|
|
11
|
+
type: 'response',
|
|
12
|
+
...req,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { KazumiPolicy } from './kazumi.js';
|
|
2
|
+
export interface KazumiSearchResult {
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
}
|
|
6
|
+
export interface KazumiChapterResult {
|
|
7
|
+
name: string;
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ExtractMediaResult {
|
|
11
|
+
media: MediaInfo[];
|
|
12
|
+
}
|
|
13
|
+
export type KazumiSearchPayload = {
|
|
14
|
+
keyword: string;
|
|
15
|
+
policy: KazumiPolicy;
|
|
16
|
+
};
|
|
17
|
+
export type KazumiChapterPayload = {
|
|
18
|
+
url: string;
|
|
19
|
+
policy: KazumiPolicy;
|
|
20
|
+
};
|
|
21
|
+
export type ExtractMediaPayload = {
|
|
22
|
+
url: string;
|
|
23
|
+
};
|
|
24
|
+
export type HTTPHeader = {
|
|
25
|
+
name: string;
|
|
26
|
+
value?: string;
|
|
27
|
+
};
|
|
28
|
+
export type MediaInfo = {
|
|
29
|
+
src: string;
|
|
30
|
+
contentType: string;
|
|
31
|
+
type: 'video' | 'audio';
|
|
32
|
+
headers?: HTTPHeader[];
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danmaku-anywhere/extension-protocol",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Messages exchanged between the Danmaku Anywhere extension and the pages it talks to",
|
|
5
|
+
"author": "Mr-Quin",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/Danmaku-Anywhere/danmaku-anywhere",
|
|
9
|
+
"directory": "packages/extension-protocol"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"!dist/tsconfig.tsbuildinfo"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/src/index.js",
|
|
19
|
+
"types": "dist/src/index.d.ts",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"registry": "https://registry.npmjs.org/",
|
|
22
|
+
"access": "public",
|
|
23
|
+
"provenance": true
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@danmaku-anywhere/danmaku-model": "^0.2.1"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"zod": "^4.6.5"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"vitest": "^5.1.2",
|
|
33
|
+
"zod": "^4.6.7"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"lint": "oxlint --fix && oxfmt",
|
|
38
|
+
"type-check": "tsc --noEmit",
|
|
39
|
+
"test": "vitest run"
|
|
40
|
+
},
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./dist/src/index.d.ts",
|
|
44
|
+
"default": "./dist/src/index.js"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
6
47
|
}
|