vite-userscript-plugin 1.10.0 → 2.0.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/README.md +156 -82
- package/dist/index.d.ts +254 -180
- package/dist/index.js +902 -4
- package/package.json +55 -49
- package/types/greasemonkey.d.ts +277 -218
- package/types/tampermonkey.d.ts +1273 -658
- package/types/violentmonkey-ambient.d.ts +149 -0
- package/types/violentmonkey.d.ts +362 -154
- package/virtual.d.ts +7 -0
- package/dist/index.cjs +0 -5
- package/dist/index.d.cts +0 -187
- package/dist/ws.js +0 -1
- package/types/README.md +0 -21
package/types/violentmonkey.d.ts
CHANGED
|
@@ -1,20 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
// synced from @violentmonkey/types@0.3.4
|
|
2
|
+
// do not edit; run pnpm sync-types
|
|
3
|
+
|
|
4
|
+
/// <reference path="./violentmonkey-ambient.d.ts" />
|
|
5
|
+
declare const unsafeWindow: Window;
|
|
2
6
|
|
|
3
7
|
declare type VMScriptRunAt =
|
|
4
8
|
| 'document-start'
|
|
5
9
|
| 'document-body'
|
|
6
10
|
| 'document-end'
|
|
7
|
-
| 'document-idle'
|
|
11
|
+
| 'document-idle';
|
|
8
12
|
|
|
9
13
|
/** Injection mode of a script. */
|
|
10
|
-
declare type VMScriptInjectInto = 'auto' | 'page' | 'content'
|
|
14
|
+
declare type VMScriptInjectInto = 'auto' | 'page' | 'content';
|
|
15
|
+
|
|
16
|
+
declare type GenericObject = Record<string, unknown>;
|
|
11
17
|
|
|
12
18
|
declare interface VMScriptGMInfoPlatform {
|
|
13
|
-
arch:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
arch:
|
|
20
|
+
| 'aarch64'
|
|
21
|
+
| 'arm'
|
|
22
|
+
| 'arm64'
|
|
23
|
+
| 'mips'
|
|
24
|
+
| 'mips64'
|
|
25
|
+
| 'ppc64'
|
|
26
|
+
| 's390x'
|
|
27
|
+
| 'sparc64'
|
|
28
|
+
| 'x86-32'
|
|
29
|
+
| 'x86-64';
|
|
30
|
+
browserName: 'chrome' | 'firefox' | string;
|
|
31
|
+
browserVersion: string;
|
|
32
|
+
/**
|
|
33
|
+
* A copy of `navigator.userAgentData.getHighEntropyValues()` from the background script
|
|
34
|
+
* of the extension, so it's not affected by devtools of the web page tab.
|
|
35
|
+
* Only present in browsers that implement this API (Chromium >= 90).
|
|
36
|
+
* @since VM2.27.0
|
|
37
|
+
*/
|
|
38
|
+
fullVersionList?: { brand: string; version: string }[] | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* A copy of `navigator.userAgentData.mobile` from the background script of the extension,
|
|
41
|
+
* so it's not affected by devtools of the web page tab.
|
|
42
|
+
* Only present in browsers that implement this API (Chromium >= 90).
|
|
43
|
+
* @since VM2.27.0
|
|
44
|
+
*/
|
|
45
|
+
mobile?: boolean | undefined;
|
|
46
|
+
os: 'mac' | 'win' | 'android' | 'cros' | 'linux' | 'openbsd' | 'fuchsia';
|
|
18
47
|
}
|
|
19
48
|
|
|
20
49
|
/**
|
|
@@ -22,74 +51,180 @@ declare interface VMScriptGMInfoPlatform {
|
|
|
22
51
|
* Non-optional string property will be an empty string '' if omitted.
|
|
23
52
|
*/
|
|
24
53
|
declare interface VMScriptGMInfoScriptMeta {
|
|
25
|
-
antifeature?: string[]
|
|
26
|
-
author?: string
|
|
27
|
-
compatible?: string[]
|
|
28
|
-
connect?: string[]
|
|
29
|
-
description: string
|
|
30
|
-
downloadURL?: string
|
|
31
|
-
excludeMatches: string[]
|
|
32
|
-
excludes: string[]
|
|
54
|
+
antifeature?: string[] | undefined;
|
|
55
|
+
author?: string | undefined;
|
|
56
|
+
compatible?: string[] | undefined;
|
|
57
|
+
connect?: string[] | undefined;
|
|
58
|
+
description: string;
|
|
59
|
+
downloadURL?: string | undefined;
|
|
60
|
+
excludeMatches: string[];
|
|
61
|
+
excludes: string[];
|
|
33
62
|
/** Empty is the same as `@grant none` */
|
|
34
|
-
grant: string[]
|
|
63
|
+
grant: string[];
|
|
35
64
|
/** Use homepageURL instead */
|
|
36
|
-
homepage?: string
|
|
37
|
-
homepageURL?: string
|
|
38
|
-
icon?: string
|
|
39
|
-
includes: string[]
|
|
40
|
-
matches: string[]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
65
|
+
homepage?: string | undefined;
|
|
66
|
+
homepageURL?: string | undefined;
|
|
67
|
+
icon?: string | undefined;
|
|
68
|
+
includes: string[];
|
|
69
|
+
matches: string[];
|
|
70
|
+
/** User options and overrides for the script
|
|
71
|
+
* @since VM2.31.1 */
|
|
72
|
+
options: {
|
|
73
|
+
check_for_updates: boolean,
|
|
74
|
+
inject_into: VMScriptInjectInto | null,
|
|
75
|
+
noframes: boolean | null,
|
|
76
|
+
override: {
|
|
77
|
+
/** Keep the script's `@exclude` */
|
|
78
|
+
merge_excludes: boolean,
|
|
79
|
+
/** Keep the script's `@include` */
|
|
80
|
+
merge_includes: boolean,
|
|
81
|
+
/** Keep the script's `@match` */
|
|
82
|
+
merge_matches: boolean,
|
|
83
|
+
/** Keep the script's `@exclude-match` */
|
|
84
|
+
merge_exclude_matches: boolean,
|
|
85
|
+
/** Keep the script's `@tag`
|
|
86
|
+
* @since VM2.35.2 */
|
|
87
|
+
merge_tags: boolean,
|
|
88
|
+
/** User overridden `@exclude` */
|
|
89
|
+
use_excludes: string[],
|
|
90
|
+
/** User overridden `@include` */
|
|
91
|
+
use_includes: string[],
|
|
92
|
+
/** User overridden `@match` */
|
|
93
|
+
use_matches: string[],
|
|
94
|
+
/** User overridden `@exclude-match` */
|
|
95
|
+
use_exclude_matches: string[],
|
|
96
|
+
},
|
|
97
|
+
run_at: VMScriptRunAt | null,
|
|
98
|
+
/** User overridden `@tag`
|
|
99
|
+
* @since VM2.35.2 */
|
|
100
|
+
tags: string[],
|
|
101
|
+
/** Last modification by the user; convertible as `new Date(user_modified)` */
|
|
102
|
+
user_modified: number,
|
|
103
|
+
},
|
|
104
|
+
name: string;
|
|
105
|
+
namespace: string;
|
|
106
|
+
noframes?: boolean | undefined;
|
|
107
|
+
require: string[];
|
|
108
|
+
resources: { name: string; url: string }[];
|
|
109
|
+
runAt: VMScriptRunAt | '';
|
|
110
|
+
supportURL?: string | undefined;
|
|
111
|
+
/** @since VM2.37.0 */
|
|
112
|
+
tags?: string[],
|
|
113
|
+
unwrap?: boolean | undefined;
|
|
114
|
+
updateURL?: string | undefined;
|
|
115
|
+
version: string;
|
|
51
116
|
}
|
|
52
117
|
|
|
53
118
|
declare interface VMScriptGMInfoObject {
|
|
54
|
-
/**
|
|
55
|
-
uuid: string
|
|
119
|
+
/** A unique ID of the script. */
|
|
120
|
+
uuid: string;
|
|
121
|
+
/** The injection mode of current script. See [`@inject-into`](https://violentmonkey.github.io/api/metadata-block/#inject-into) for more information. */
|
|
122
|
+
injectInto: VMScriptInjectInto;
|
|
123
|
+
/** Contains structured fields from the [Metadata Block](https://violentmonkey.github.io/api/metadata-block/). */
|
|
124
|
+
script: VMScriptGMInfoScriptMeta;
|
|
56
125
|
/** The meta block of the script. */
|
|
57
|
-
scriptMetaStr: string
|
|
126
|
+
scriptMetaStr: string;
|
|
58
127
|
/** Whether the script will be updated automatically. */
|
|
59
|
-
scriptWillUpdate: boolean
|
|
128
|
+
scriptWillUpdate: boolean;
|
|
60
129
|
/** The name of userscript manager, which should be the string `Violentmonkey`. */
|
|
61
|
-
scriptHandler: string
|
|
130
|
+
scriptHandler: string;
|
|
62
131
|
/** Version of Violentmonkey. */
|
|
63
|
-
version: string
|
|
132
|
+
version: string;
|
|
133
|
+
/**
|
|
134
|
+
* GM_download internal implementation:
|
|
135
|
+
* `native` - the classic `a` element's `download` attribute, used by default.
|
|
136
|
+
* `browser` - the browser API used if the user enabled it in the extension's options.
|
|
137
|
+
* @since VM2.45.2
|
|
138
|
+
*/
|
|
139
|
+
downloadMode: 'native' | 'browser';
|
|
140
|
+
/**
|
|
141
|
+
* True when this is an incognito profile (Chrome) or private mode (Firefox).
|
|
142
|
+
* @since VM2.15.4
|
|
143
|
+
*/
|
|
144
|
+
isIncognito: boolean;
|
|
64
145
|
/**
|
|
65
146
|
* Unlike `navigator.userAgent`, which can be overriden by other extensions/userscripts
|
|
66
147
|
* or by devtools in device-emulation mode, `GM_info.platform` is more reliable as the
|
|
67
148
|
* data is obtained in the background page of Violentmonkey using a specialized
|
|
68
149
|
* extension API (`browser.runtime.getPlatformInfo` and `getBrowserInfo`).
|
|
69
150
|
*/
|
|
70
|
-
platform: VMScriptGMInfoPlatform
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
151
|
+
platform: VMScriptGMInfoPlatform;
|
|
152
|
+
/**
|
|
153
|
+
* A safe copy of `navigator.userAgent` from the content script of the extension,
|
|
154
|
+
* so it cannot be overridden by other extensions/userscripts, but unlike
|
|
155
|
+
* `GM_info.platform` it can be customized in devtools “device emulation” or
|
|
156
|
+
* “network conditions” for this tab.
|
|
157
|
+
* @since VM2.20.2
|
|
158
|
+
*/
|
|
159
|
+
userAgent: string;
|
|
160
|
+
/**
|
|
161
|
+
* A safe copy of `navigator.userAgentData` from the content script of the extension,
|
|
162
|
+
* so it cannot be overridden by other extensions/userscripts, but unlike
|
|
163
|
+
* `GM_info.platform` it can be customized in devtools "device emulation" or
|
|
164
|
+
* "network conditions" for this tab.
|
|
165
|
+
*
|
|
166
|
+
* Only present if the browser actually implements it
|
|
167
|
+
* ([currently](https://caniuse.com/mdn-api_navigator_useragentdata) Chromium-based 90+),
|
|
168
|
+
* because there's no reliable/official polyfill.
|
|
169
|
+
*
|
|
170
|
+
* Violentmonkey implements the [official API](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData),
|
|
171
|
+
* including [getHighEntropyValues](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues)
|
|
172
|
+
* function to obtain the extra info asynchronously.
|
|
173
|
+
*
|
|
174
|
+
* @since VM2.20.2
|
|
175
|
+
*/
|
|
176
|
+
userAgentData?:
|
|
177
|
+
| {
|
|
178
|
+
brands: { brand: string; version: string }[];
|
|
179
|
+
mobile: boolean;
|
|
180
|
+
platform: string;
|
|
181
|
+
getHighEntropyValues(hints: string[]): Promise<UADataValues>;
|
|
182
|
+
}
|
|
183
|
+
| undefined;
|
|
75
184
|
}
|
|
76
185
|
|
|
77
186
|
/**
|
|
78
187
|
* An object that exposes information about the current userscript.
|
|
79
188
|
*/
|
|
80
|
-
declare const GM_info: VMScriptGMInfoObject
|
|
189
|
+
declare const GM_info: VMScriptGMInfoObject;
|
|
190
|
+
|
|
191
|
+
/** @since VM2.35.1 */
|
|
192
|
+
declare const GM_cookie: {
|
|
193
|
+
delete: (
|
|
194
|
+
opts: browser.cookies._RemoveDetails | chrome.cookies.CookieDetails,
|
|
195
|
+
callback?: (error?: string) => any,
|
|
196
|
+
) => void,
|
|
197
|
+
/** `httpOnly` cookies are listed only when the HTTP-only option is enabled for the script and globally in the extension */
|
|
198
|
+
list: (
|
|
199
|
+
opts: browser.cookies._GetAllDetails | Parameters<typeof chrome.cookies.getAll>[0],
|
|
200
|
+
callback?: (cookies?: browser.cookies.Cookie | chrome.cookies.Cookie, error?: string) => any,
|
|
201
|
+
) => void,
|
|
202
|
+
/** `httpOnly` cookies are allowed only when the HTTP-only option is enabled for the script and globally in the extension */
|
|
203
|
+
set: (
|
|
204
|
+
opts: browser.cookies._SetDetails | Parameters<typeof chrome.cookies.set>[0],
|
|
205
|
+
callback?: (error?: string) => any,
|
|
206
|
+
) => void,
|
|
207
|
+
};
|
|
81
208
|
|
|
82
209
|
/** The original console.log */
|
|
83
|
-
declare function GM_log(...args: any): void
|
|
210
|
+
declare function GM_log(...args: any): void;
|
|
84
211
|
|
|
85
212
|
/** Retrieves a value for current script from storage. */
|
|
86
|
-
declare function GM_getValue<T>(name: string, defaultValue?: T): T
|
|
213
|
+
declare function GM_getValue<T>(name: string, defaultValue?: T | undefined): T;
|
|
214
|
+
/** @since VM2.19.1 */
|
|
215
|
+
declare function GM_getValues(names: string[]): GenericObject;
|
|
216
|
+
/** @since VM2.19.1 */
|
|
217
|
+
declare function GM_getValues(namesWithDefaults: GenericObject): GenericObject;
|
|
87
218
|
/** Sets a key / value pair for current script to storage. */
|
|
88
|
-
declare function GM_setValue<T>(name: string, value: T): void
|
|
219
|
+
declare function GM_setValue<T>(name: string, value: T): void;
|
|
220
|
+
/** @since VM2.19.1 */
|
|
221
|
+
declare function GM_setValues(values: GenericObject): void;
|
|
89
222
|
/** Deletes an existing key / value pair for current script from storage. */
|
|
90
|
-
declare function GM_deleteValue(name: string): void
|
|
223
|
+
declare function GM_deleteValue(name: string): void;
|
|
224
|
+
/** @since VM2.19.1 */
|
|
225
|
+
declare function GM_deleteValues(names: string[]): void;
|
|
91
226
|
/** Returns an array of keys of all available values within this script. */
|
|
92
|
-
declare function GM_listValues(): string[]
|
|
227
|
+
declare function GM_listValues(): string[];
|
|
93
228
|
|
|
94
229
|
declare type VMScriptGMValueChangeCallback<T> = (
|
|
95
230
|
/** The name of the observed variable */
|
|
@@ -99,22 +234,22 @@ declare type VMScriptGMValueChangeCallback<T> = (
|
|
|
99
234
|
/** The new value of the observed variable (`undefined` if it was deleted) */
|
|
100
235
|
newValue: T,
|
|
101
236
|
/** `true` if modified by the userscript instance of another tab or `false` for this script instance. Can be used by scripts of different browser tabs to communicate with each other. */
|
|
102
|
-
remote: boolean
|
|
103
|
-
) => void
|
|
237
|
+
remote: boolean,
|
|
238
|
+
) => void;
|
|
104
239
|
|
|
105
240
|
/** Adds a change listener to the storage and returns the listener ID. */
|
|
106
241
|
declare function GM_addValueChangeListener<T>(
|
|
107
242
|
name: string,
|
|
108
|
-
callback: VMScriptGMValueChangeCallback<T
|
|
109
|
-
): string
|
|
243
|
+
callback: VMScriptGMValueChangeCallback<T>,
|
|
244
|
+
): string;
|
|
110
245
|
/** Removes a change listener by its ID. */
|
|
111
|
-
declare function GM_removeValueChangeListener(listenerId: string): void
|
|
246
|
+
declare function GM_removeValueChangeListener(listenerId: string): void;
|
|
112
247
|
|
|
113
248
|
/** Retrieves a text resource from the *Metadata Block*. */
|
|
114
249
|
declare function GM_getResourceText(
|
|
115
250
|
/** Name of a resource defined in the *Metadata Block*. */
|
|
116
|
-
name: string
|
|
117
|
-
): string
|
|
251
|
+
name: string,
|
|
252
|
+
): string;
|
|
118
253
|
/**
|
|
119
254
|
* Retrieves a `blob:` or `data:` URL of a resource from the *Metadata Block*.
|
|
120
255
|
*
|
|
@@ -127,8 +262,8 @@ declare function GM_getResourceURL(
|
|
|
127
262
|
* - If `true`, returns a `blob:` URL. It's short and cacheable, so it's good for reusing in multiple DOM elements.
|
|
128
263
|
* - If `false`, returns a `data:` URL. It's long so reusing it in DOM may be less performant due to the lack of caching, but it's particularly handy for direct synchronous decoding of the data on sites that forbid fetching `blob:` in their CSP.
|
|
129
264
|
*/
|
|
130
|
-
isBlobUrl?: boolean
|
|
131
|
-
): string
|
|
265
|
+
isBlobUrl?: boolean | undefined,
|
|
266
|
+
): string;
|
|
132
267
|
|
|
133
268
|
/**
|
|
134
269
|
* Appends and returns an element with the specified attributes.
|
|
@@ -151,8 +286,8 @@ declare function GM_addElement(
|
|
|
151
286
|
/** A tag name like `script`. Any valid HTML tag can be used, but the only motivation for this API was to add `script`, `link`, `style` elements when they are disallowed by a strict `Content-Security-Policy` of the site e.g. github.com, twitter.com. */
|
|
152
287
|
tagName: string,
|
|
153
288
|
/** The keys are HTML attributes, not DOM properties, except `textContent` which sets DOM property `textContent`. The values are strings so if you want to assign a private function to `onload` you can do it after the element is created. */
|
|
154
|
-
attributes?: Record<string, string>
|
|
155
|
-
): HTMLElement
|
|
289
|
+
attributes?: Record<string, string> | undefined,
|
|
290
|
+
): HTMLElement;
|
|
156
291
|
declare function GM_addElement(
|
|
157
292
|
/**
|
|
158
293
|
* The parent node to which the new node will be appended.
|
|
@@ -167,24 +302,24 @@ declare function GM_addElement(
|
|
|
167
302
|
/** A tag name like `script`. Any valid HTML tag can be used, but the only motivation for this API was to add `script`, `link`, `style` elements when they are disallowed by a strict `Content-Security-Policy` of the site e.g. github.com, twitter.com. */
|
|
168
303
|
tagName: string,
|
|
169
304
|
/** The keys are HTML attributes, not DOM properties, except `textContent` which sets DOM property `textContent`. The values are strings so if you want to assign a private function to `onload` you can do it after the element is created. */
|
|
170
|
-
attributes?: Record<string, string>
|
|
171
|
-
): HTMLElement
|
|
305
|
+
attributes?: Record<string, string> | undefined,
|
|
306
|
+
): HTMLElement;
|
|
172
307
|
|
|
173
308
|
/** Appends and returns a `<style>` element with the specified CSS. */
|
|
174
|
-
declare function GM_addStyle(css: string): HTMLStyleElement
|
|
309
|
+
declare function GM_addStyle(css: string): HTMLStyleElement;
|
|
175
310
|
|
|
176
311
|
declare interface VMScriptGMTabControl {
|
|
177
312
|
/** Сan be assigned to a function. If provided, it will be called when the opened tab is closed. */
|
|
178
|
-
onclose?: () => void
|
|
313
|
+
onclose?: (() => void) | undefined;
|
|
179
314
|
/** Whether the opened tab is closed. */
|
|
180
|
-
closed: boolean
|
|
315
|
+
closed: boolean;
|
|
181
316
|
/** A function to explicitly close the opened tab. */
|
|
182
|
-
close: () => void
|
|
317
|
+
close: () => void;
|
|
183
318
|
}
|
|
184
319
|
|
|
185
320
|
declare interface VMScriptGMTabOptions {
|
|
186
321
|
/** Make the new tab active (i.e. open in foreground). Default as `true`. */
|
|
187
|
-
active?: boolean
|
|
322
|
+
active?: boolean | undefined;
|
|
188
323
|
/**
|
|
189
324
|
* Firefox only.
|
|
190
325
|
*
|
|
@@ -192,41 +327,57 @@ declare interface VMScriptGMTabOptions {
|
|
|
192
327
|
* - `0` = default (main) container
|
|
193
328
|
* - `1`, `2`, etc. = internal container index
|
|
194
329
|
*/
|
|
195
|
-
container?: number
|
|
330
|
+
container?: number | undefined;
|
|
196
331
|
/** Insert the new tab next to the current tab and set its `openerTab` so when it's closed the original tab will be focused automatically. When `false` or not specified, the usual browser behavior is to open the tab at the end of the tab list. Default as `true`. */
|
|
197
|
-
insert?: boolean
|
|
332
|
+
insert?: boolean | undefined;
|
|
198
333
|
/** Pin the tab (i.e. show without a title at the beginning of the tab list). Default as `false`. */
|
|
199
|
-
pinned?: boolean
|
|
334
|
+
pinned?: boolean | undefined;
|
|
200
335
|
}
|
|
201
336
|
|
|
202
337
|
/** Opens URL in a new tab. */
|
|
203
338
|
declare function GM_openInTab(
|
|
204
339
|
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
|
|
205
340
|
url: string,
|
|
206
|
-
options?: VMScriptGMTabOptions
|
|
207
|
-
): VMScriptGMTabControl
|
|
341
|
+
options?: VMScriptGMTabOptions | undefined,
|
|
342
|
+
): VMScriptGMTabControl;
|
|
208
343
|
declare function GM_openInTab(
|
|
209
344
|
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
|
|
210
345
|
url: string,
|
|
211
346
|
/** Open the tab in background. Note, this is a reverse of the first usage method so for example `true` is the same as `{ active: false }`. */
|
|
212
|
-
openInBackground?: boolean
|
|
213
|
-
): VMScriptGMTabControl
|
|
347
|
+
openInBackground?: boolean | undefined,
|
|
348
|
+
): VMScriptGMTabControl;
|
|
214
349
|
|
|
215
350
|
/**
|
|
216
351
|
* Registers a command in Violentmonkey popup menu.
|
|
352
|
+
* Returns the command's id since VM2.12.5, see description of the `id` parameter.
|
|
217
353
|
* If you want to add a shortcut, please see `@violentmonkey/shortcut`.
|
|
218
354
|
*/
|
|
219
355
|
declare function GM_registerMenuCommand(
|
|
220
356
|
/** The name to show in the popup menu. */
|
|
221
357
|
caption: string,
|
|
222
358
|
/** Callback function when the command is clicked in the menu. */
|
|
223
|
-
onClick: (event: MouseEvent | KeyboardEvent) => void
|
|
224
|
-
|
|
359
|
+
onClick: (event: MouseEvent | KeyboardEvent) => void,
|
|
360
|
+
/** @since VM2.15.9 */
|
|
361
|
+
options?:
|
|
362
|
+
| {
|
|
363
|
+
/** Default: the `caption` parameter.
|
|
364
|
+
* In 2.15.9-2.16.1 the default was a randomly generated string. */
|
|
365
|
+
id?: string | undefined;
|
|
366
|
+
/** @since VM2.31.1 */
|
|
367
|
+
icon?: string | undefined;
|
|
368
|
+
/** A hint shown in the status bar when hovering the command. */
|
|
369
|
+
title?: string | undefined;
|
|
370
|
+
/** Default: `true`.
|
|
371
|
+
* Whether to auto-close the popup after the user invoked the command. */
|
|
372
|
+
autoClose?: boolean | undefined;
|
|
373
|
+
}
|
|
374
|
+
| undefined,
|
|
375
|
+
): string;
|
|
225
376
|
/** Unregisters a command which has been registered to Violentmonkey popup menu. */
|
|
226
377
|
declare function GM_unregisterMenuCommand(
|
|
227
378
|
/** The name of command to unregister. */
|
|
228
|
-
caption: string
|
|
229
|
-
): void
|
|
379
|
+
caption: string,
|
|
380
|
+
): void;
|
|
230
381
|
|
|
231
382
|
/**
|
|
232
383
|
* A control object returned by `GM_notification`.
|
|
@@ -234,51 +385,75 @@ declare function GM_unregisterMenuCommand(
|
|
|
234
385
|
*/
|
|
235
386
|
declare interface VMScriptGMNotificationControl {
|
|
236
387
|
/** Remove the notification immediately. */
|
|
237
|
-
remove: () => Promise<void
|
|
388
|
+
remove: () => Promise<void>;
|
|
238
389
|
}
|
|
239
390
|
|
|
240
391
|
declare interface VMScriptGMNotificationOptions {
|
|
241
392
|
/** Main text of the notification. */
|
|
242
|
-
text: string
|
|
393
|
+
text: string;
|
|
243
394
|
/** Title of the notification. */
|
|
244
|
-
title?: string
|
|
395
|
+
title?: string | undefined;
|
|
245
396
|
/** URL of an image to show in the notification. */
|
|
246
|
-
image?: string
|
|
397
|
+
image?: string | undefined;
|
|
398
|
+
/** No sounds/vibrations when showing the notification.
|
|
399
|
+
* @since VM2.15.2, Chrome 70. */
|
|
400
|
+
silent?: boolean | undefined;
|
|
401
|
+
/**
|
|
402
|
+
* Unique name of the notification, e.g. 'abc', same as the web Notification API.
|
|
403
|
+
* Names are scoped to each userscript i.e. your tag won't clash with another script's tag.
|
|
404
|
+
* The purpose of a tagged notification is to replace an older notification with the same tag,
|
|
405
|
+
* even if it was shown in another tab (or before this tab was navigated elsewhere
|
|
406
|
+
* and your notification had `zombieTimeout`).
|
|
407
|
+
* @since VM2.15.4
|
|
408
|
+
*/
|
|
409
|
+
tag?: string | undefined;
|
|
410
|
+
/**
|
|
411
|
+
* Number of milliseconds to keep the notification after the userscript "dies",
|
|
412
|
+
* i.e. when its tab or frame is reloaded/closed/navigated. If not specified or invalid,
|
|
413
|
+
* the default behavior is to immediately remove the notifications.
|
|
414
|
+
* @since VM2.15.4
|
|
415
|
+
*/
|
|
416
|
+
zombieTimeout?: number | undefined;
|
|
417
|
+
/**
|
|
418
|
+
* URL to open when a zombie notification is clicked, see `zombieTimeout` for more info.
|
|
419
|
+
* @since VM2.16.1
|
|
420
|
+
*/
|
|
421
|
+
zombieUrl?: string | undefined;
|
|
247
422
|
/** Callback when the notification is clicked by user. */
|
|
248
|
-
onclick?: () => void
|
|
423
|
+
onclick?: (() => void) | undefined;
|
|
249
424
|
/** Callback when the notification is closed, either by user or by system. */
|
|
250
|
-
ondone?: () => void
|
|
425
|
+
ondone?: (() => void) | undefined;
|
|
251
426
|
}
|
|
252
427
|
|
|
253
428
|
/** Shows an HTML5 desktop notification. */
|
|
254
429
|
declare function GM_notification(
|
|
255
|
-
options: VMScriptGMNotificationOptions
|
|
256
|
-
): VMScriptGMNotificationControl
|
|
430
|
+
options: VMScriptGMNotificationOptions,
|
|
431
|
+
): VMScriptGMNotificationControl;
|
|
257
432
|
declare function GM_notification(
|
|
258
433
|
/** Main text of the notification. */
|
|
259
434
|
text: string,
|
|
260
435
|
/** Title of the notification. */
|
|
261
|
-
title?: string,
|
|
436
|
+
title?: string | undefined,
|
|
262
437
|
/** URL of an image to show in the notification. */
|
|
263
|
-
image?: string,
|
|
438
|
+
image?: string | undefined,
|
|
264
439
|
/** Callback when the notification is clicked by user. */
|
|
265
|
-
onclick?: () => void
|
|
266
|
-
): VMScriptGMNotificationControl
|
|
440
|
+
onclick?: (() => void) | undefined,
|
|
441
|
+
): VMScriptGMNotificationControl;
|
|
267
442
|
|
|
268
443
|
/** Sets data to system clipboard. */
|
|
269
444
|
declare function GM_setClipboard(
|
|
270
445
|
/** The data to be copied to system clipboard. */
|
|
271
446
|
data: string,
|
|
272
447
|
/** The MIME type of data to copy. Default as `text/plain`. */
|
|
273
|
-
type?: string
|
|
274
|
-
): void
|
|
448
|
+
type?: string | undefined,
|
|
449
|
+
): void;
|
|
275
450
|
|
|
276
451
|
/**
|
|
277
452
|
* A control object returned by `GM_xmlhttpRequest`.
|
|
278
453
|
* `control.abort()` can be used to abort the request.
|
|
279
454
|
*/
|
|
280
455
|
declare interface VMScriptXHRControl {
|
|
281
|
-
abort: () => void
|
|
456
|
+
abort: () => void;
|
|
282
457
|
}
|
|
283
458
|
|
|
284
459
|
declare type VMScriptResponseType =
|
|
@@ -286,27 +461,27 @@ declare type VMScriptResponseType =
|
|
|
286
461
|
| 'json'
|
|
287
462
|
| 'blob'
|
|
288
463
|
| 'arraybuffer'
|
|
289
|
-
| 'document'
|
|
464
|
+
| 'document';
|
|
290
465
|
|
|
291
466
|
/**
|
|
292
467
|
* https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#properties
|
|
293
468
|
* https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent#properties
|
|
294
469
|
*/
|
|
295
470
|
declare interface VMScriptResponseObject<T> {
|
|
296
|
-
status: number
|
|
297
|
-
statusText: string
|
|
298
|
-
readyState: number
|
|
299
|
-
responseHeaders: string
|
|
300
|
-
response: T | null
|
|
301
|
-
responseText: string | undefined
|
|
302
|
-
responseXML: Document | null
|
|
471
|
+
status: number;
|
|
472
|
+
statusText: string;
|
|
473
|
+
readyState: number;
|
|
474
|
+
responseHeaders: string;
|
|
475
|
+
response: T | null;
|
|
476
|
+
responseText: string | undefined;
|
|
477
|
+
responseXML: Document | null;
|
|
303
478
|
/** The final URL after redirection. */
|
|
304
|
-
finalUrl: string
|
|
305
|
-
lengthComputable?: boolean
|
|
306
|
-
loaded?: number
|
|
307
|
-
total?: number
|
|
479
|
+
finalUrl: string;
|
|
480
|
+
lengthComputable?: boolean | undefined;
|
|
481
|
+
loaded?: number | undefined;
|
|
482
|
+
total?: number | undefined;
|
|
308
483
|
/** The same `context` object you specified in `details`. */
|
|
309
|
-
context?: unknown
|
|
484
|
+
context?: unknown | undefined;
|
|
310
485
|
}
|
|
311
486
|
|
|
312
487
|
type TypedArray =
|
|
@@ -320,15 +495,15 @@ type TypedArray =
|
|
|
320
495
|
| BigUint64Array
|
|
321
496
|
| BigInt64Array
|
|
322
497
|
| Float32Array
|
|
323
|
-
| Float64Array
|
|
498
|
+
| Float64Array;
|
|
324
499
|
|
|
325
|
-
interface GMRequestBase<T> {
|
|
500
|
+
interface GMRequestBase<T> extends GMRequestBaseEvents<T> {
|
|
326
501
|
/** URL relative to current page is also allowed. */
|
|
327
|
-
url: string
|
|
502
|
+
url: string;
|
|
328
503
|
/** User for authentication. */
|
|
329
|
-
user?: string
|
|
504
|
+
user?: string | undefined;
|
|
330
505
|
/** Password for authentication. */
|
|
331
|
-
password?: string
|
|
506
|
+
password?: string | undefined;
|
|
332
507
|
/**
|
|
333
508
|
* Some special headers are also allowed:
|
|
334
509
|
*
|
|
@@ -338,28 +513,31 @@ interface GMRequestBase<T> {
|
|
|
338
513
|
* - `Referer`
|
|
339
514
|
* - `User-Agent`
|
|
340
515
|
*/
|
|
341
|
-
headers?: Record<string, string>
|
|
516
|
+
headers?: Record<string, string> | undefined;
|
|
342
517
|
/** Time to wait for the request, none by default. */
|
|
343
|
-
timeout?: number
|
|
518
|
+
timeout?: number | undefined;
|
|
344
519
|
/** Can be an object and will be assigned to context of the response object. */
|
|
345
|
-
context?: unknown
|
|
520
|
+
context?: unknown | undefined;
|
|
346
521
|
/** When set to `true`, no cookie will be sent with the request and the response cookies will be ignored. The default value is `false`. */
|
|
347
|
-
anonymous?: boolean
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
522
|
+
anonymous?: boolean | undefined;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
interface GMRequestBaseEvents<T> {
|
|
526
|
+
onabort?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
527
|
+
onerror?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
528
|
+
onload?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
529
|
+
onloadend?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
530
|
+
onloadstart?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
531
|
+
onprogress?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
532
|
+
onreadystatechange?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
533
|
+
ontimeout?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
|
|
356
534
|
}
|
|
357
535
|
|
|
358
536
|
declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
|
|
359
537
|
/** HTTP method, default as `GET`. */
|
|
360
|
-
method?: string
|
|
538
|
+
method?: string | undefined;
|
|
361
539
|
/** A MIME type to specify with the request. */
|
|
362
|
-
overrideMimeType?: string
|
|
540
|
+
overrideMimeType?: string | undefined;
|
|
363
541
|
/**
|
|
364
542
|
* One of the following:
|
|
365
543
|
*
|
|
@@ -369,7 +547,7 @@ declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
|
|
|
369
547
|
* - `arraybuffer`
|
|
370
548
|
* - `document`
|
|
371
549
|
*/
|
|
372
|
-
responseType?: VMScriptResponseType
|
|
550
|
+
responseType?: VMScriptResponseType | undefined;
|
|
373
551
|
/** Data to send with the request, usually for `POST` and `PUT` requests. */
|
|
374
552
|
data?:
|
|
375
553
|
| string
|
|
@@ -380,55 +558,85 @@ declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
|
|
|
380
558
|
| ReadableStream
|
|
381
559
|
| TypedArray
|
|
382
560
|
| URLSearchParams
|
|
561
|
+
| undefined;
|
|
383
562
|
/** Send the `data` string as a `blob`. This is for compatibility with Tampermonkey/Greasemonkey, where only `string` type is allowed in `data`. */
|
|
384
|
-
binary?: boolean
|
|
563
|
+
binary?: boolean | undefined;
|
|
564
|
+
/** @since VM2.32.0 */
|
|
565
|
+
upload?: GMRequestBaseEvents<T>;
|
|
385
566
|
}
|
|
386
567
|
|
|
387
568
|
/** Makes a request like XMLHttpRequest, with some special capabilities, not restricted by same-origin policy. */
|
|
388
569
|
declare function GM_xmlhttpRequest<
|
|
389
|
-
T = string | Blob | ArrayBuffer | Document | object
|
|
390
|
-
>(details: VMScriptGMXHRDetails<T>): VMScriptXHRControl
|
|
570
|
+
T = string | Blob | ArrayBuffer | Document | object,
|
|
571
|
+
>(details: VMScriptGMXHRDetails<T>): VMScriptXHRControl;
|
|
391
572
|
|
|
392
573
|
declare interface VMScriptGMDownloadOptions extends GMRequestBase<Blob> {
|
|
393
574
|
/** The filename to save as. */
|
|
394
|
-
name: string
|
|
575
|
+
name: string;
|
|
576
|
+
/** Used only when GM_info.downloadMode === 'browser' */
|
|
577
|
+
conflictAction?: browser.downloads.FilenameConflictAction;
|
|
578
|
+
/** Shows the dialog. Used only when GM_info.downloadMode === 'browser' */
|
|
579
|
+
saveAs?: boolean;
|
|
395
580
|
}
|
|
396
581
|
|
|
397
582
|
/** Downloads a URL to a local file. */
|
|
398
|
-
declare function GM_download(options: VMScriptGMDownloadOptions): void
|
|
583
|
+
declare function GM_download(options: VMScriptGMDownloadOptions): void;
|
|
399
584
|
declare function GM_download(
|
|
400
585
|
/** The URL to download. */
|
|
401
586
|
url: string,
|
|
402
587
|
/** The filename to save as. */
|
|
403
|
-
name: string
|
|
404
|
-
): void
|
|
588
|
+
name: string,
|
|
589
|
+
): void;
|
|
405
590
|
|
|
406
591
|
/** Aliases for GM_ methods that are not included in Greasemonkey4 API */
|
|
407
592
|
declare interface VMScriptGMObjectVMExtensions {
|
|
408
|
-
addElement: typeof GM_addElement
|
|
409
|
-
addStyle: typeof GM_addStyle
|
|
410
|
-
addValueChangeListener: typeof GM_addValueChangeListener
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
593
|
+
addElement: typeof GM_addElement;
|
|
594
|
+
addStyle: typeof GM_addStyle;
|
|
595
|
+
addValueChangeListener: typeof GM_addValueChangeListener;
|
|
596
|
+
/** @since VM2.35.1 */
|
|
597
|
+
cookie: {
|
|
598
|
+
delete: (opts: browser.cookies._RemoveDetails | chrome.cookies.CookieDetails) => Promise<void>,
|
|
599
|
+
/** `httpOnly` cookies are listed only when the HTTP-only option is enabled for the script and globally in the extension */
|
|
600
|
+
list: (opts: browser.cookies._GetAllDetails | Parameters<typeof chrome.cookies.getAll>[0]) =>
|
|
601
|
+
Promise<browser.cookies.Cookie | chrome.cookies.Cookie>,
|
|
602
|
+
/** `httpOnly` cookies are allowed only when the HTTP-only option is enabled for the script and globally in the extension */
|
|
603
|
+
set: (opts: browser.cookies._SetDetails | Parameters<typeof chrome.cookies.set>[0]) => Promise<void>,
|
|
604
|
+
};
|
|
605
|
+
/** @since VM2.19.1 */
|
|
606
|
+
deleteValues: (names: string[]) => Promise<void>;
|
|
607
|
+
download(options: VMScriptGMDownloadOptions): Promise<Blob> | void;
|
|
608
|
+
download(url: string, name: string): Promise<Blob> | void;
|
|
609
|
+
getResourceText: typeof GM_getResourceText;
|
|
610
|
+
/** @since VM2.19.1 */
|
|
611
|
+
getValues(names: string[]): Promise<GenericObject>;
|
|
612
|
+
/** @since VM2.19.1 */
|
|
613
|
+
getValues(namesWithDefaults: GenericObject): Promise<GenericObject>;
|
|
614
|
+
log: typeof GM_log;
|
|
615
|
+
removeValueChangeListener: typeof GM_removeValueChangeListener;
|
|
616
|
+
/** @since VM2.19.1 */
|
|
617
|
+
setValues: (values: GenericObject) => Promise<void>;
|
|
618
|
+
unregisterMenuCommand: typeof GM_unregisterMenuCommand;
|
|
416
619
|
}
|
|
417
620
|
|
|
418
621
|
/** The Greasemonkey4 API, https://wiki.greasespot.net/Greasemonkey_Manual:API */
|
|
419
622
|
declare interface VMScriptGMObject extends VMScriptGMObjectVMExtensions {
|
|
420
|
-
unsafeWindow: Window
|
|
421
|
-
info: typeof GM_info
|
|
422
|
-
getValue: <T>(name: string, defaultValue?: T) => Promise<T
|
|
423
|
-
setValue: <T>(name: string, value: T) => Promise<void
|
|
424
|
-
deleteValue: (name: string) => Promise<void
|
|
425
|
-
listValues: () => Promise<string[]
|
|
426
|
-
registerMenuCommand: typeof GM_registerMenuCommand
|
|
427
|
-
getResourceUrl: (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
623
|
+
unsafeWindow: Window;
|
|
624
|
+
info: typeof GM_info;
|
|
625
|
+
getValue: <T>(name: string, defaultValue?: T | undefined) => Promise<T>;
|
|
626
|
+
setValue: <T>(name: string, value: T) => Promise<void>;
|
|
627
|
+
deleteValue: (name: string) => Promise<void>;
|
|
628
|
+
listValues: () => Promise<string[]>;
|
|
629
|
+
registerMenuCommand: typeof GM_registerMenuCommand;
|
|
630
|
+
getResourceUrl: (
|
|
631
|
+
name: string,
|
|
632
|
+
isBlobUrl?: boolean | undefined,
|
|
633
|
+
) => Promise<string>;
|
|
634
|
+
notification: typeof GM_notification;
|
|
635
|
+
openInTab: typeof GM_openInTab;
|
|
636
|
+
setClipboard: typeof GM_setClipboard;
|
|
637
|
+
xmlHttpRequest: <T = string | Blob | ArrayBuffer | Document | object>(
|
|
638
|
+
details: VMScriptGMXHRDetails<T>,
|
|
639
|
+
) => Promise<T> & VMScriptXHRControl;
|
|
432
640
|
}
|
|
433
641
|
|
|
434
|
-
declare const GM: VMScriptGMObject
|
|
642
|
+
declare const GM: VMScriptGMObject;
|