@henrikvilhelmberglund/vite-plugin-monkey 4.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -0
- package/client.d.ts +1085 -0
- package/dist/client/index.d.ts +802 -0
- package/dist/client/index.mjs +69 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/metafile-esm.json +1 -0
- package/dist/native/index.d.ts +29 -0
- package/dist/native/index.mjs +58 -0
- package/dist/native/index.mjs.map +1 -0
- package/dist/native/metafile-esm.json +1 -0
- package/dist/node/index.d.ts +845 -0
- package/dist/node/index.mjs +2487 -0
- package/dist/node/index.mjs.map +1 -0
- package/global.d.ts +1294 -0
- package/package.json +89 -0
@@ -0,0 +1,845 @@
|
|
1
|
+
import { Plugin } from 'vite';
|
2
|
+
import { InlinePreset } from 'unimport';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* format userscript comment
|
6
|
+
*/
|
7
|
+
type Format = {
|
8
|
+
/**
|
9
|
+
* @description note font_width/font_family, suggest fixed-width font
|
10
|
+
* @default 2, true
|
11
|
+
*/
|
12
|
+
align?: number | boolean | AlignFunc;
|
13
|
+
/**
|
14
|
+
* custom generate userscript comment
|
15
|
+
*
|
16
|
+
* if you want add other comments after userscript or modify userscript
|
17
|
+
*/
|
18
|
+
generate?: (uOptions: {
|
19
|
+
userscript: string;
|
20
|
+
mode: `serve` | `build` | `meta`;
|
21
|
+
}) => IPromise<string>;
|
22
|
+
};
|
23
|
+
/**
|
24
|
+
* @example
|
25
|
+
* // input/output
|
26
|
+
* [
|
27
|
+
* [ 'name', 'example' ],
|
28
|
+
* [ 'name:ja', 'hentai' ],
|
29
|
+
* [ 'name:zh', '测试_' ],
|
30
|
+
* [ 'namespace', 'https://github.com/lisonge' ],
|
31
|
+
* [ 'version', '1.0.1' ],
|
32
|
+
* [ 'author', 'lisonge' ],
|
33
|
+
* [ 'description', 'default description zh' ],
|
34
|
+
* [ 'description:zh', '描述' ],
|
35
|
+
* [ 'description:en', 'description' ],
|
36
|
+
* [ 'description:ja', '説明z' ],
|
37
|
+
* [ 'description:zh-CN', '描述' ],
|
38
|
+
* [ 'license', 'MIT' ],
|
39
|
+
* [ 'icon', 'https://vitejs.dev/logo.svg' ],
|
40
|
+
* [
|
41
|
+
* 'homepage',
|
42
|
+
* 'https://github.com/lisonge/vite-plugin-monkey#readme'
|
43
|
+
* ],
|
44
|
+
* [
|
45
|
+
* 'homepageURL',
|
46
|
+
* 'https://github.com/lisonge/vite-plugin-monkey#readme'
|
47
|
+
* ],
|
48
|
+
* [ 'source', 'https://github.com/lisonge/vite-plugin-monkey.git' ],
|
49
|
+
* [
|
50
|
+
* 'supportURL',
|
51
|
+
* 'https://github.com/lisonge/vite-plugin-monkey/issues'
|
52
|
+
* ],
|
53
|
+
* [ 'match', 'https://songe.li/' ],
|
54
|
+
* [ 'require', 'https://cdn.jsdelivr.net/npm/blueimp-md5@2.19.0' ],
|
55
|
+
* [
|
56
|
+
* 'require',
|
57
|
+
* 'https://cdn.jsdelivr.net/npm/prettier@2.7.1/standalone.js'
|
58
|
+
* ],
|
59
|
+
* [
|
60
|
+
* 'require',
|
61
|
+
* 'https://cdn.jsdelivr.net/npm/prettier@2.7.1/parser-babel.js'
|
62
|
+
* ],
|
63
|
+
* [ 'grant', 'GM_addElement' ],
|
64
|
+
* [ 'grant', 'GM_cookie' ],
|
65
|
+
* [ 'grant', 'unsafeWindow' ]
|
66
|
+
* ]
|
67
|
+
*/
|
68
|
+
type AlignFunc = (p0: [string, ...string[]][]) => IPromise<[string, ...string[]][]>;
|
69
|
+
|
70
|
+
type GreaseRunAt = 'document-start' | 'document-end' | 'document-idle';
|
71
|
+
type GreaseGrant = 'GM.info' | 'GM.deleteValue' | 'GM.getValue' | 'GM.listValues' | 'GM.setValue' | 'GM.getResourceUrl' | 'GM.notification' | 'GM.openInTab' | 'GM.registerMenuCommand' | 'GM.setClipboard' | 'GM.xmlHttpRequest' | 'unsafeWindow';
|
72
|
+
/**
|
73
|
+
* @see https://wiki.greasespot.net/Metadata_Block
|
74
|
+
*/
|
75
|
+
interface GreasemonkeyUserScript {
|
76
|
+
/**
|
77
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40name
|
78
|
+
*
|
79
|
+
*/
|
80
|
+
name?: string | LocaleType<string>;
|
81
|
+
/**
|
82
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40namespace
|
83
|
+
*/
|
84
|
+
namespace?: string;
|
85
|
+
/**
|
86
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40version
|
87
|
+
*
|
88
|
+
*/
|
89
|
+
version?: string;
|
90
|
+
/**
|
91
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40description
|
92
|
+
*
|
93
|
+
*/
|
94
|
+
description?: string | LocaleType<string>;
|
95
|
+
/**
|
96
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40icon
|
97
|
+
*/
|
98
|
+
icon?: string;
|
99
|
+
/**
|
100
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40include
|
101
|
+
*/
|
102
|
+
include?: IArray<string | RegExp>;
|
103
|
+
/**
|
104
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40match
|
105
|
+
*/
|
106
|
+
match?: IArray<string | RegExp>;
|
107
|
+
/**
|
108
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40exclude
|
109
|
+
*/
|
110
|
+
exclude?: IArray<string | RegExp>;
|
111
|
+
/**
|
112
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40require
|
113
|
+
*/
|
114
|
+
require?: IArray<string>;
|
115
|
+
/**
|
116
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40resource
|
117
|
+
*/
|
118
|
+
resource?: Record<string, string>;
|
119
|
+
/**
|
120
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40noframes
|
121
|
+
*/
|
122
|
+
noframes?: boolean;
|
123
|
+
}
|
124
|
+
|
125
|
+
type WebRequestRule = {
|
126
|
+
selector: string | {
|
127
|
+
include?: string | string[];
|
128
|
+
match?: string | string[];
|
129
|
+
exclude?: string | string[];
|
130
|
+
};
|
131
|
+
action: 'cancel' | {
|
132
|
+
cancel?: boolean;
|
133
|
+
redirect?: string | {
|
134
|
+
from: string;
|
135
|
+
to: string;
|
136
|
+
};
|
137
|
+
};
|
138
|
+
};
|
139
|
+
|
140
|
+
type TamperRunAt = 'document-start' | 'document-body' | 'document-end' | 'document-idle' | 'context-menu';
|
141
|
+
type TamperGrant = 'unsafeWindow' | 'window.close' | 'window.focus' | 'window.onurlchange' | 'GM_addStyle' | 'GM_addElement' | 'GM_deleteValue' | 'GM_listValues' | 'GM_addValueChangeListener' | 'GM_removeValueChangeListener' | 'GM_setValue' | 'GM_getValue' | 'GM_log' | 'GM_getResourceText' | 'GM_getResourceURL' | 'GM_registerMenuCommand' | 'GM_unregisterMenuCommand' | 'GM_openInTab' | 'GM_xmlhttpRequest' | 'GM_download' | 'GM_getTab' | 'GM_saveTab' | 'GM_getTabs' | 'GM_notification' | 'GM_setClipboard' | 'GM_info' | 'GM_cookie' | 'GM_webRequest';
|
142
|
+
type AntifeatureType = {
|
143
|
+
tag?: string;
|
144
|
+
type: 'ads' | 'tracking' | 'miner';
|
145
|
+
description: string;
|
146
|
+
};
|
147
|
+
/**
|
148
|
+
* @see https://www.tampermonkey.net/documentation.php
|
149
|
+
*/
|
150
|
+
interface TampermonkeyUserScript {
|
151
|
+
/**
|
152
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:name
|
153
|
+
*
|
154
|
+
*/
|
155
|
+
name?: string | LocaleType<string>;
|
156
|
+
/**
|
157
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:namespace
|
158
|
+
*/
|
159
|
+
namespace?: string;
|
160
|
+
/**
|
161
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:copyright
|
162
|
+
*/
|
163
|
+
copyright?: string;
|
164
|
+
/**
|
165
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:version
|
166
|
+
*
|
167
|
+
*/
|
168
|
+
version?: string;
|
169
|
+
/**
|
170
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:author
|
171
|
+
*
|
172
|
+
*/
|
173
|
+
author?: string;
|
174
|
+
/**
|
175
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:description
|
176
|
+
*
|
177
|
+
*/
|
178
|
+
description?: string | LocaleType<string>;
|
179
|
+
/**
|
180
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
181
|
+
*
|
182
|
+
*/
|
183
|
+
homepage?: string;
|
184
|
+
/**
|
185
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
186
|
+
*
|
187
|
+
*/
|
188
|
+
homepageURL?: string;
|
189
|
+
/**
|
190
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
191
|
+
*/
|
192
|
+
website?: string;
|
193
|
+
/**
|
194
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:homepage
|
195
|
+
*/
|
196
|
+
source?: string;
|
197
|
+
/**
|
198
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
199
|
+
*/
|
200
|
+
icon?: string;
|
201
|
+
/**
|
202
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
203
|
+
*/
|
204
|
+
iconURL?: string;
|
205
|
+
/**
|
206
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon
|
207
|
+
*/
|
208
|
+
defaulticon?: string;
|
209
|
+
/**
|
210
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon64
|
211
|
+
*/
|
212
|
+
icon64?: string;
|
213
|
+
/**
|
214
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:icon64
|
215
|
+
*/
|
216
|
+
icon64URL?: string;
|
217
|
+
/**
|
218
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:updateURL
|
219
|
+
*/
|
220
|
+
updateURL?: string;
|
221
|
+
/**
|
222
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:downloadURL
|
223
|
+
*/
|
224
|
+
downloadURL?: string;
|
225
|
+
/**
|
226
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:supportURL
|
227
|
+
*/
|
228
|
+
supportURL?: string;
|
229
|
+
/**
|
230
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:include
|
231
|
+
*/
|
232
|
+
include?: IArray<string | RegExp>;
|
233
|
+
/**
|
234
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:match
|
235
|
+
*/
|
236
|
+
match?: IArray<string | RegExp>;
|
237
|
+
/**
|
238
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:exclude
|
239
|
+
*/
|
240
|
+
exclude?: IArray<string | RegExp>;
|
241
|
+
/**
|
242
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:require
|
243
|
+
*/
|
244
|
+
require?: IArray<string>;
|
245
|
+
/**
|
246
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:resource
|
247
|
+
*/
|
248
|
+
resource?: Record<string, string>;
|
249
|
+
/**
|
250
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:connect
|
251
|
+
*/
|
252
|
+
connect?: IArray<string>;
|
253
|
+
/**
|
254
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:sandbox
|
255
|
+
*/
|
256
|
+
sandbox?: 'raw' | 'JavaScript' | 'DOM';
|
257
|
+
/**
|
258
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:antifeature
|
259
|
+
*/
|
260
|
+
antifeature?: IArray<AntifeatureType>;
|
261
|
+
/**
|
262
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:noframes
|
263
|
+
*/
|
264
|
+
noframes?: boolean;
|
265
|
+
/**
|
266
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:webRequest
|
267
|
+
*/
|
268
|
+
webRequest?: IArray<WebRequestRule>;
|
269
|
+
/**
|
270
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:unwrap
|
271
|
+
*/
|
272
|
+
unwrap?: boolean;
|
273
|
+
}
|
274
|
+
|
275
|
+
type ViolentRunAt = 'document-end' | 'document-start' | 'document-idle';
|
276
|
+
type ViolentInjectInto = 'page' | 'content' | 'auto';
|
277
|
+
type ViolentGrant = 'window.close' | 'window.focus' | 'GM_info' | 'GM_getValue' | 'GM_setValue' | 'GM_deleteValue' | 'GM_listValues' | 'GM_addValueChangeListener' | 'GM_removeValueChangeListener' | 'GM_getResourceText' | 'GM_getResourceURL' | 'GM_addElement' | 'GM_addStyle' | 'GM_openInTab' | 'GM_registerMenuCommand' | 'GM_unregisterMenuCommand' | 'GM_notification' | 'GM_setClipboard' | 'GM_xmlhttpRequest' | 'GM_download' | 'GM.addStyle' | 'GM.addElement' | 'GM.registerMenuCommand' | 'GM.deleteValue' | 'GM.getResourceUrl' | 'GM.getValue' | 'GM.info' | 'GM.listValues' | 'GM.notification' | 'GM.openInTab' | 'GM.setClipboard' | 'GM.setValue' | 'GM.xmlHttpRequest';
|
278
|
+
/**
|
279
|
+
* @see https://violentmonkey.github.io/api/metadata-block/
|
280
|
+
*/
|
281
|
+
interface ViolentmonkeyUserScript {
|
282
|
+
/**
|
283
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#name
|
284
|
+
*
|
285
|
+
*/
|
286
|
+
name?: string | LocaleType<string>;
|
287
|
+
/**
|
288
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#namespace
|
289
|
+
*/
|
290
|
+
namespace?: string;
|
291
|
+
/**
|
292
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#version
|
293
|
+
*
|
294
|
+
*/
|
295
|
+
version?: string;
|
296
|
+
/**
|
297
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#description
|
298
|
+
*
|
299
|
+
*/
|
300
|
+
description?: string | LocaleType<string>;
|
301
|
+
/**
|
302
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#icon
|
303
|
+
*/
|
304
|
+
icon?: string;
|
305
|
+
/**
|
306
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#downloadurl
|
307
|
+
*/
|
308
|
+
downloadURL?: string;
|
309
|
+
/**
|
310
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#supporturl
|
311
|
+
*/
|
312
|
+
supportURL?: string;
|
313
|
+
/**
|
314
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#homepageurl
|
315
|
+
*
|
316
|
+
*/
|
317
|
+
homepageURL?: string;
|
318
|
+
/**
|
319
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#include--exclude
|
320
|
+
* @see https://violentmonkey.github.io/api/matching/#include--exclude
|
321
|
+
*/
|
322
|
+
include?: IArray<string | RegExp>;
|
323
|
+
/**
|
324
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
|
325
|
+
* @see https://violentmonkey.github.io/api/matching/#match--exclude-match
|
326
|
+
*/
|
327
|
+
match?: IArray<string | RegExp>;
|
328
|
+
/**
|
329
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#match--exclude-match
|
330
|
+
* @see https://violentmonkey.github.io/api/matching/#match--exclude-match
|
331
|
+
*/
|
332
|
+
'exclude-match'?: IArray<string | RegExp>;
|
333
|
+
/**
|
334
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#include--exclude
|
335
|
+
* @see https://violentmonkey.github.io/api/matching/#include--exclude
|
336
|
+
*/
|
337
|
+
exclude?: IArray<string | RegExp>;
|
338
|
+
/**
|
339
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#require
|
340
|
+
*/
|
341
|
+
require?: IArray<string>;
|
342
|
+
/**
|
343
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#resource
|
344
|
+
*/
|
345
|
+
resource?: Record<string, string>;
|
346
|
+
/**
|
347
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#noframes
|
348
|
+
*/
|
349
|
+
noframes?: boolean;
|
350
|
+
/**
|
351
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#inject-into
|
352
|
+
*/
|
353
|
+
'inject-into'?: ViolentInjectInto;
|
354
|
+
/**
|
355
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#unwrap
|
356
|
+
*/
|
357
|
+
unwrap?: boolean;
|
358
|
+
}
|
359
|
+
|
360
|
+
/**
|
361
|
+
* @see https://greasyfork.org/help/meta-keys
|
362
|
+
*/
|
363
|
+
type GreasyforkUserScript = {
|
364
|
+
/**
|
365
|
+
* @see https://greasyfork.org/help/meta-keys
|
366
|
+
* @default package.json.license
|
367
|
+
*/
|
368
|
+
license?: string;
|
369
|
+
/**
|
370
|
+
* @see https://greasyfork.org/help/meta-keys
|
371
|
+
*/
|
372
|
+
contributionURL?: string;
|
373
|
+
/**
|
374
|
+
* @see https://greasyfork.org/help/meta-keys
|
375
|
+
*/
|
376
|
+
contributionAmount?: string;
|
377
|
+
/**
|
378
|
+
* @see https://greasyfork.org/help/meta-keys
|
379
|
+
*/
|
380
|
+
compatible?: string;
|
381
|
+
/**
|
382
|
+
* @see https://greasyfork.org/help/meta-keys
|
383
|
+
*/
|
384
|
+
incompatible?: string;
|
385
|
+
};
|
386
|
+
type MergemonkeyUserScript = {
|
387
|
+
/**
|
388
|
+
* @default package.json.name??'monkey'
|
389
|
+
* @default {...{'':package.json.name??'monkey'},...name} // if name is object
|
390
|
+
*/
|
391
|
+
name?: string | LocaleType<string>;
|
392
|
+
/**
|
393
|
+
* @default 'vite-plugin-monkey'
|
394
|
+
*/
|
395
|
+
namespace?: string;
|
396
|
+
/**
|
397
|
+
* @default package.json.version??'1.0.0'
|
398
|
+
*/
|
399
|
+
version?: string;
|
400
|
+
/**
|
401
|
+
* @default package.json.description
|
402
|
+
* @default {...{'':package.json.description},...description} // if description is object
|
403
|
+
*/
|
404
|
+
description?: string | LocaleType<string>;
|
405
|
+
/**
|
406
|
+
* @default package.json.author??'monkey'
|
407
|
+
*/
|
408
|
+
author?: string;
|
409
|
+
/**
|
410
|
+
* @default package.json.homepage
|
411
|
+
*/
|
412
|
+
homepage?: string;
|
413
|
+
/**
|
414
|
+
* @default package.json.homepage
|
415
|
+
*/
|
416
|
+
homepageURL?: string;
|
417
|
+
/**
|
418
|
+
* @default package.json.repository
|
419
|
+
*/
|
420
|
+
source?: string;
|
421
|
+
/**
|
422
|
+
* @default package.json.bugs
|
423
|
+
*/
|
424
|
+
supportURL?: string;
|
425
|
+
/**
|
426
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40run-at
|
427
|
+
*
|
428
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:run_at
|
429
|
+
*
|
430
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#run-at
|
431
|
+
*
|
432
|
+
*/
|
433
|
+
'run-at'?: GreaseRunAt | TamperRunAt | ViolentRunAt;
|
434
|
+
/**
|
435
|
+
* @see https://wiki.greasespot.net/Metadata_Block#.40grant
|
436
|
+
*
|
437
|
+
* @see https://www.tampermonkey.net/documentation.php#meta:grant
|
438
|
+
*
|
439
|
+
* @see https://violentmonkey.github.io/api/metadata-block/#grant
|
440
|
+
*
|
441
|
+
* if set '\*', will add all GM_* to UserScript
|
442
|
+
*/
|
443
|
+
grant?: IArray<GreaseGrant | TamperGrant | ViolentGrant> | 'none' | '*';
|
444
|
+
/**
|
445
|
+
* custom extra meta
|
446
|
+
* @example
|
447
|
+
* [['antifeature', ['miner', 'hello233']]]
|
448
|
+
* // -->
|
449
|
+
* // \@antifeature miner hello233
|
450
|
+
*/
|
451
|
+
$extra?: [string, IArray<string>][] | Record<string, IArray<string>>;
|
452
|
+
};
|
453
|
+
/**
|
454
|
+
* UserScript, merge metadata from Greasemonkey, Tampermonkey, Violentmonkey, Greasyfork
|
455
|
+
*/
|
456
|
+
type MonkeyUserScript = GreasemonkeyUserScript & TampermonkeyUserScript & ViolentmonkeyUserScript & GreasyforkUserScript & MergemonkeyUserScript;
|
457
|
+
|
458
|
+
type IPromise<T> = T | Promise<T>;
|
459
|
+
type IArray<T = unknown> = T | T[];
|
460
|
+
/**
|
461
|
+
* key is language code or ''
|
462
|
+
* @see https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
|
463
|
+
* @example
|
464
|
+
* {
|
465
|
+
* '':'default_name',
|
466
|
+
* 'zh-CN':'名字',
|
467
|
+
* ja: '名前'
|
468
|
+
* }
|
469
|
+
*/
|
470
|
+
type LocaleType<T = unknown> = Record<string, T>;
|
471
|
+
type PkgOptions = {
|
472
|
+
name: string;
|
473
|
+
version: string;
|
474
|
+
importName: string;
|
475
|
+
resolveName: string;
|
476
|
+
resourceUrl: string;
|
477
|
+
resourceName: string;
|
478
|
+
};
|
479
|
+
type Pkg2UrlFn = (pkg: {
|
480
|
+
name: string;
|
481
|
+
version: string;
|
482
|
+
importName: string;
|
483
|
+
resolveName: string;
|
484
|
+
}) => IPromise<string>;
|
485
|
+
/**
|
486
|
+
* @param importName 'name/subname' in example
|
487
|
+
* @returns url or exportVarName
|
488
|
+
* @example
|
489
|
+
* const mod = await import('name/subname')
|
490
|
+
*/
|
491
|
+
type Mod2UrlFn = (version: string, name: string, importName: string) => IPromise<string>;
|
492
|
+
type ModuleToUrlFc = (version: string, name: string, importName?: string, resolveName?: string) => string;
|
493
|
+
type ExternalGlobals = Record<string, IArray<string | Mod2UrlFn>> | [string, IArray<string | Mod2UrlFn>][];
|
494
|
+
type ExternalResource = Record<string, string | Pkg2UrlFn | {
|
495
|
+
resourceUrl: Pkg2UrlFn | string;
|
496
|
+
/**
|
497
|
+
* @default importName
|
498
|
+
*/
|
499
|
+
resourceName?: Pkg2UrlFn | string;
|
500
|
+
loader?: (pkgOptions: PkgOptions) => unknown;
|
501
|
+
nodeLoader?: string | ((pkgOptions: PkgOptions) => IPromise<string>);
|
502
|
+
} | Array<string | ((version: string, name: string, importName: string, resolveName: string) => IPromise<string>)>>;
|
503
|
+
type MonkeyOption = {
|
504
|
+
/**
|
505
|
+
* userscript entry file path
|
506
|
+
*/
|
507
|
+
entry: string;
|
508
|
+
userscript?: MonkeyUserScript;
|
509
|
+
format?: Format;
|
510
|
+
/**
|
511
|
+
* alias of vite-plugin-monkey/dist/client
|
512
|
+
* @default '$'
|
513
|
+
* @example
|
514
|
+
* // vite-env.d.ts for type hint
|
515
|
+
*
|
516
|
+
* // if you use default value `$`
|
517
|
+
* /// <reference types="vite-plugin-monkey/client" />
|
518
|
+
*
|
519
|
+
* // if you use other_alias
|
520
|
+
* declare module other_alias {
|
521
|
+
* export * from 'vite-plugin-monkey/dist/client';
|
522
|
+
* }
|
523
|
+
*/
|
524
|
+
clientAlias?: string;
|
525
|
+
server?: {
|
526
|
+
/**
|
527
|
+
* auto open install url in default browser when userscript comment change
|
528
|
+
*
|
529
|
+
* and set `viteConfig.server.open ??= monkeyConfig.server.open`
|
530
|
+
* @default
|
531
|
+
* process.platform == 'win32' || process.platform == 'darwin' // if platform is Win/Mac
|
532
|
+
*/
|
533
|
+
open?: boolean;
|
534
|
+
/**
|
535
|
+
* name prefix, distinguish server.user.js and build.user.js in monkey extension install list, if you not want prefix, set false
|
536
|
+
* @default 'server:'
|
537
|
+
*/
|
538
|
+
prefix?: string | ((name: string) => string) | false;
|
539
|
+
/**
|
540
|
+
* close the preview server automatically after 3000ms
|
541
|
+
* @default false
|
542
|
+
*/
|
543
|
+
closePreviewAutomatically?: boolean;
|
544
|
+
/**
|
545
|
+
* mount GM_api to unsafeWindow, not recommend it, you should use GM_api by ESM import, or use [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
|
546
|
+
* @default false
|
547
|
+
* @example
|
548
|
+
* // if set true, you can use `vite-plugin-monkey/global` for type hint
|
549
|
+
* // vite-env.d.ts
|
550
|
+
* /// <reference types="vite-plugin-monkey/global" />
|
551
|
+
*/
|
552
|
+
mountGmApi?: boolean;
|
553
|
+
};
|
554
|
+
build?: {
|
555
|
+
/**
|
556
|
+
* build bundle userscript file name
|
557
|
+
*
|
558
|
+
* it should end with '.user.js'
|
559
|
+
* @default (package.json.name??'monkey')+'.user.js'
|
560
|
+
*/
|
561
|
+
fileName?: string;
|
562
|
+
/**
|
563
|
+
* build bundle userscript comment file name, this file is only include comment
|
564
|
+
*
|
565
|
+
* it can be used by userscript.updateURL, when checking for updates, just download this small file instead of downloading the entire script
|
566
|
+
*
|
567
|
+
* it should end with '.meta.js', if set false, will not generate this file
|
568
|
+
*
|
569
|
+
* if set true, will equal to fileName.replace(/\\.user\\.js$/,'.meta.js')
|
570
|
+
*
|
571
|
+
* @default false
|
572
|
+
*/
|
573
|
+
metaFileName?: string | boolean | ((fileName: string) => string);
|
574
|
+
/**
|
575
|
+
* this config can be array or object, array=Object.entries(object)
|
576
|
+
*
|
577
|
+
* if value is string or function, it or its return value is exportVarName
|
578
|
+
*
|
579
|
+
* if value is Array, the first [item or its return value] is exportVarName, the items after it all are url that is [require url]
|
580
|
+
*
|
581
|
+
* if module is unimported, plugin will not add require url to userscript
|
582
|
+
*
|
583
|
+
* @example
|
584
|
+
* { // map structure
|
585
|
+
* vue:'Vue',
|
586
|
+
* // if set this
|
587
|
+
* // you need manually set userscript.require = ['https://unpkg.com/vue@3.0.0/dist/vue.global.js'], when `vite build`
|
588
|
+
*
|
589
|
+
* vuex:['Vuex', (version, name)=>`https://unpkg.com/${name}@${version}/dist/vuex.global.js`],
|
590
|
+
* // plugin will auto add this url to userscript.require
|
591
|
+
*
|
592
|
+
* 'prettier/parser-babel': [
|
593
|
+
* 'prettierPlugins.babel',
|
594
|
+
* (version, name, importName) => {
|
595
|
+
* // name == `prettier`
|
596
|
+
* // importName == `prettier/parser-babel`
|
597
|
+
* const subpath = `${importName.split('/').at(-1)}.js`;
|
598
|
+
* return `https://cdn.jsdelivr.net/npm/${name}@${version}/${subpath}`;
|
599
|
+
* },
|
600
|
+
* ],
|
601
|
+
* // sometimes importName deffers from package name
|
602
|
+
* }
|
603
|
+
* @example
|
604
|
+
* [ // array structure, this example come from [playground/ex-vue-demi](https://github.com/lisonge/vite-plugin-monkey/tree/main/playground/ex-vue-demi)
|
605
|
+
* [
|
606
|
+
* 'vue',
|
607
|
+
* cdn
|
608
|
+
* .jsdelivr('Vue', 'dist/vue.global.prod.js')
|
609
|
+
* .concat('https://unpkg.com/vue-demi@latest/lib/index.iife.js')
|
610
|
+
* .concat(
|
611
|
+
* await util.fn2dataUrl(() => {
|
612
|
+
* window.Vue = Vue;
|
613
|
+
* }),
|
614
|
+
* ),
|
615
|
+
* ],
|
616
|
+
* ['pinia', cdn.jsdelivr('Pinia', 'dist/pinia.iife.prod.js')],
|
617
|
+
* [
|
618
|
+
* 'element-plus',
|
619
|
+
* cdn.jsdelivr('ElementPlus', 'dist/index.full.min.js'),
|
620
|
+
* ],
|
621
|
+
* ]
|
622
|
+
*/
|
623
|
+
externalGlobals?: ExternalGlobals;
|
624
|
+
/**
|
625
|
+
* according to final code bundle, auto inject GM_* or GM.* to userscript comment grant
|
626
|
+
*
|
627
|
+
* tree shaking code, then if code.includes('GM_xxx'), add \@grant GM_xxx to userscript
|
628
|
+
* @default true
|
629
|
+
*/
|
630
|
+
autoGrant?: boolean;
|
631
|
+
/**
|
632
|
+
* @deprecated use [viteConfig.build.cssMinify](https://vitejs.dev/config/build-options.html#build-cssminify) in vite>=4.2.0
|
633
|
+
*
|
634
|
+
* now minifyCss will not work
|
635
|
+
*/
|
636
|
+
minifyCss?: boolean;
|
637
|
+
/**
|
638
|
+
* @example
|
639
|
+
* { // resourceName default value is pkg.importName
|
640
|
+
* 'element-plus/dist/index.css': pkg=>`https://unpkg.com/${pkg.name}@${pkg.version}/${pkg.resolveName}`,
|
641
|
+
* 'element-plus/dist/index.css': {
|
642
|
+
* resourceName: pkg=>pkg.importName,
|
643
|
+
* resourceUrl: pkg=>`https://unpkg.com/${pkg.name}@${pkg.version}/${pkg.resolveName}`,
|
644
|
+
* loader: pkg=>{ // there are default loaders that support [css, json, the assets that vite support, ?url, ?raw] file/name suffix
|
645
|
+
* const css = GM_getResourceText(pkg.resourceName);
|
646
|
+
* GM_addStyle(css);
|
647
|
+
* return css;
|
648
|
+
* },
|
649
|
+
* nodeLoader: pkg=>{
|
650
|
+
* return [
|
651
|
+
* `export default (()=>{`,
|
652
|
+
* `const css = GM_getResourceText(${JSON.stringify(pkg.resourceName)});`,
|
653
|
+
* `GM_addStyle(css);`,
|
654
|
+
* `return css;`,
|
655
|
+
* `})();`
|
656
|
+
* ].join('');
|
657
|
+
* },
|
658
|
+
* },
|
659
|
+
* 'element-plus/dist/index.css': [
|
660
|
+
* (version, name, importName, resolveName)=>importName,
|
661
|
+
* (version, name, importName, resolveName)=>`https://unpkg.com/${name}@${version}/${resolveName}`,
|
662
|
+
* // for compat externalGlobals cdn function, if (version/name/importName/resolveName) == '', plugin will use their own default values
|
663
|
+
* ],
|
664
|
+
* 'element-plus/dist/index.css': cdn.jsdelivr(),
|
665
|
+
* }
|
666
|
+
*/
|
667
|
+
externalResource?: ExternalResource;
|
668
|
+
/**
|
669
|
+
* when use dynamic-import, plugin will use systemjs build your code
|
670
|
+
*
|
671
|
+
* `cdn.jsdelivr()[1]` example -> [dynamic-import.user.js](https://github.com/lisonge/vite-plugin-monkey/blob/7645b185605faf9b48c43116db5ea01726188e03/playground/dynamic-import/dist/dynamic-import.user.js)
|
672
|
+
*
|
673
|
+
* `'inline'` exmple -> [test-v3.user.js](https://github.com/lisonge/vite-plugin-monkey/blob/7645b185605faf9b48c43116db5ea01726188e03/playground/test-v3/dist/test-v3.user.js)
|
674
|
+
*
|
675
|
+
* @default
|
676
|
+
* cdn.jsdelivr()[1]
|
677
|
+
*/
|
678
|
+
systemjs?: 'inline' | ModuleToUrlFc;
|
679
|
+
/**
|
680
|
+
* @default
|
681
|
+
* const defaultFc = () => {
|
682
|
+
* return (e: string) => {
|
683
|
+
* if (typeof GM_addStyle == 'function') {
|
684
|
+
* GM_addStyle(e);
|
685
|
+
* return;
|
686
|
+
* }
|
687
|
+
* const o = document.createElement('style');
|
688
|
+
* o.textContent = e;
|
689
|
+
* document.head.append(o);
|
690
|
+
* };
|
691
|
+
* };
|
692
|
+
* @example
|
693
|
+
* const defaultFc1 = () => {
|
694
|
+
* return (e: string) => {
|
695
|
+
* const o = document.createElement('style');
|
696
|
+
* o.textContent = e;
|
697
|
+
* document.head.append(o);
|
698
|
+
* };
|
699
|
+
* };
|
700
|
+
* const defaultFc2 = (css:string)=>{
|
701
|
+
* const t = JSON.stringify(css)
|
702
|
+
* return `(e=>{const o=document.createElement("style");o.textContent=e,document.head.append(o)})(${t})`
|
703
|
+
* }
|
704
|
+
*/
|
705
|
+
cssSideEffects?: (css: string) => IPromise<string | ((css: string) => void)>;
|
706
|
+
};
|
707
|
+
};
|
708
|
+
|
709
|
+
/**
|
710
|
+
* `https://cdn.jsdelivr.net/npm/${name}@${version}/${pathname}`
|
711
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
712
|
+
* @param pathname jsdelivr support file combine, normally you don't need set pathname
|
713
|
+
* @see https://www.jsdelivr.com/features
|
714
|
+
*/
|
715
|
+
declare const jsdelivr: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
716
|
+
/**
|
717
|
+
* `https://fastly.jsdelivr.net/npm/${name}@${version}/${pathname}`
|
718
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
719
|
+
* @param pathname jsdelivr support file combine, normally you don't need set pathname
|
720
|
+
* @see https://www.jsdelivr.com/features
|
721
|
+
*/
|
722
|
+
declare const jsdelivrFastly: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
723
|
+
/**
|
724
|
+
* `https://unpkg.com/${name}@${version}/${pathname}`
|
725
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
726
|
+
* @see https://unpkg.com/
|
727
|
+
*/
|
728
|
+
declare const unpkg: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
729
|
+
/**
|
730
|
+
* `https://lf9-cdn-tos.bytecdntp.com/cdn/expire-10-y/${name}/${version}/${pathname}`
|
731
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
732
|
+
* @see https://cdn.bytedance.com/
|
733
|
+
*/
|
734
|
+
declare const bytecdntp: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
735
|
+
/**
|
736
|
+
* `https://cdn.jsdelivr.net/npm/${name}@${version}/${pathname}`
|
737
|
+
* @deprecated bootcdn will return virus-infected code. Please stop using it and switch to other sources
|
738
|
+
*/
|
739
|
+
declare const bootcdn: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
740
|
+
/**
|
741
|
+
* `https://lib.baomitu.com/${name}/${version}/${pathname}`
|
742
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
743
|
+
* @see https://cdn.baomitu.com/
|
744
|
+
*/
|
745
|
+
declare const baomitu: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
746
|
+
/**
|
747
|
+
* `https://cdn.staticfile.org/${name}/${version}/${pathname}`
|
748
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
749
|
+
* @see https://staticfile.org/
|
750
|
+
*/
|
751
|
+
declare const staticfile: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
752
|
+
/**
|
753
|
+
* `https://cdnjs.cloudflare.com/ajax/libs/${name}/${version}/${pathname}`
|
754
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
755
|
+
* @see https://cdnjs.com/libraries
|
756
|
+
*/
|
757
|
+
declare const cdnjs: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
758
|
+
/**
|
759
|
+
* `https://unpkg.zhimg.com/${name}/${version}/${pathname}`
|
760
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
761
|
+
* @link https://unpkg.zhimg.com/
|
762
|
+
*/
|
763
|
+
declare const zhimg: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
764
|
+
/**
|
765
|
+
* `https://npm.elemecdn.com/${name}@${version}/${pathname}`
|
766
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
767
|
+
*/
|
768
|
+
declare const elemecdn: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
769
|
+
/**
|
770
|
+
* `https://code.bdstatic.com/npm/${name}@${version}/${pathname}`
|
771
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
772
|
+
*/
|
773
|
+
declare const bdstatic: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
774
|
+
/**
|
775
|
+
* `https://registry.npmmirror.com/${name}/${version}/files/${pathname}`
|
776
|
+
* @param exportVarName cdn-exportVarName or resourceName
|
777
|
+
*/
|
778
|
+
declare const npmmirror: (exportVarName?: string, pathname?: string) => [string, ModuleToUrlFc];
|
779
|
+
|
780
|
+
declare const cdn_baomitu: typeof baomitu;
|
781
|
+
declare const cdn_bdstatic: typeof bdstatic;
|
782
|
+
declare const cdn_bootcdn: typeof bootcdn;
|
783
|
+
declare const cdn_bytecdntp: typeof bytecdntp;
|
784
|
+
declare const cdn_cdnjs: typeof cdnjs;
|
785
|
+
declare const cdn_elemecdn: typeof elemecdn;
|
786
|
+
declare const cdn_jsdelivr: typeof jsdelivr;
|
787
|
+
declare const cdn_jsdelivrFastly: typeof jsdelivrFastly;
|
788
|
+
declare const cdn_npmmirror: typeof npmmirror;
|
789
|
+
declare const cdn_staticfile: typeof staticfile;
|
790
|
+
declare const cdn_unpkg: typeof unpkg;
|
791
|
+
declare const cdn_zhimg: typeof zhimg;
|
792
|
+
declare namespace cdn {
|
793
|
+
export { cdn_baomitu as baomitu, cdn_bdstatic as bdstatic, cdn_bootcdn as bootcdn, cdn_bytecdntp as bytecdntp, cdn_cdnjs as cdnjs, cdn_elemecdn as elemecdn, cdn_jsdelivr as jsdelivr, cdn_jsdelivrFastly as jsdelivrFastly, cdn_npmmirror as npmmirror, cdn_staticfile as staticfile, cdn_unpkg as unpkg, cdn_zhimg as zhimg };
|
794
|
+
}
|
795
|
+
|
796
|
+
/**
|
797
|
+
* transform function and parameter to iife code then mini code then transform code to data url string
|
798
|
+
*
|
799
|
+
* this tool function is used to make umd-cdn and iife-cdn work normally, such as element-plus and vue
|
800
|
+
*
|
801
|
+
* @example
|
802
|
+
* // this example comes form https://github.com/lisonge/vite-plugin-monkey/blob/main/playground/ex-vue-demi/vite.config.ts
|
803
|
+
* const externalGlobals = [
|
804
|
+
* [
|
805
|
+
* 'vue',
|
806
|
+
* cdn
|
807
|
+
* .jsdelivr('Vue', 'dist/vue.global.prod.js')
|
808
|
+
* .concat('https://unpkg.com/vue-demi@latest/lib/index.iife.js')
|
809
|
+
* .concat(
|
810
|
+
* await util.fn2dataUrl(() => {
|
811
|
+
* // \@ts-ignore
|
812
|
+
* window.Vue = Vue; // work with element-plus
|
813
|
+
* }),
|
814
|
+
* ),
|
815
|
+
* ],
|
816
|
+
* ['pinia', cdn.jsdelivr('Pinia', 'dist/pinia.iife.prod.js')],
|
817
|
+
* ['element-plus', cdn.jsdelivr('ElementPlus', 'dist/index.full.min.js')],
|
818
|
+
* ];
|
819
|
+
*/
|
820
|
+
declare const fn2dataUrl: <T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>) => Promise<string>;
|
821
|
+
/**
|
822
|
+
* string -> javascript data url
|
823
|
+
*/
|
824
|
+
declare function dataUrl(code: string): string;
|
825
|
+
/**
|
826
|
+
* function and it parameters -> iife -> mini_iife -> javascript data url
|
827
|
+
*/
|
828
|
+
declare function dataUrl<T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>): Promise<string>;
|
829
|
+
/**
|
830
|
+
* GM api preset when you use unimport/unplugin-auto-import
|
831
|
+
*
|
832
|
+
* Note, there is not comment in unimport.d.ts/auto-imports.d.ts file
|
833
|
+
*/
|
834
|
+
declare const unimportPreset: InlinePreset;
|
835
|
+
|
836
|
+
declare const util_dataUrl: typeof dataUrl;
|
837
|
+
declare const util_fn2dataUrl: typeof fn2dataUrl;
|
838
|
+
declare const util_unimportPreset: typeof unimportPreset;
|
839
|
+
declare namespace util {
|
840
|
+
export { util_dataUrl as dataUrl, util_fn2dataUrl as fn2dataUrl, util_unimportPreset as unimportPreset };
|
841
|
+
}
|
842
|
+
|
843
|
+
declare const _default: (pluginOption: MonkeyOption) => Plugin[];
|
844
|
+
|
845
|
+
export { type Format, type GreasemonkeyUserScript, type MonkeyOption, type MonkeyUserScript, type TampermonkeyUserScript, type ViolentmonkeyUserScript, cdn, _default as default, util };
|