vite-userscript-plugin 1.11.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 +152 -98
- package/dist/index.d.ts +254 -180
- package/dist/index.js +890 -282
- package/package.json +51 -44
- package/types/greasemonkey.d.ts +267 -270
- package/types/tampermonkey.d.ts +1096 -954
- package/types/violentmonkey-ambient.d.ts +149 -0
- package/types/violentmonkey.d.ts +319 -186
- package/virtual.d.ts +7 -0
- package/dist/ws.js +0 -14
- package/types/README.md +0 -21
package/types/violentmonkey.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
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';
|
|
11
15
|
|
|
12
|
-
declare type GenericObject = Record<string, unknown
|
|
16
|
+
declare type GenericObject = Record<string, unknown>;
|
|
13
17
|
|
|
14
18
|
declare interface VMScriptGMInfoPlatform {
|
|
15
19
|
arch:
|
|
@@ -22,10 +26,24 @@ declare interface VMScriptGMInfoPlatform {
|
|
|
22
26
|
| 's390x'
|
|
23
27
|
| 'sparc64'
|
|
24
28
|
| 'x86-32'
|
|
25
|
-
| 'x86-64'
|
|
26
|
-
browserName: 'chrome' | 'firefox' | string
|
|
27
|
-
browserVersion: string
|
|
28
|
-
|
|
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';
|
|
29
47
|
}
|
|
30
48
|
|
|
31
49
|
/**
|
|
@@ -33,90 +51,180 @@ declare interface VMScriptGMInfoPlatform {
|
|
|
33
51
|
* Non-optional string property will be an empty string '' if omitted.
|
|
34
52
|
*/
|
|
35
53
|
declare interface VMScriptGMInfoScriptMeta {
|
|
36
|
-
antifeature?: string[]
|
|
37
|
-
author?: string
|
|
38
|
-
compatible?: string[]
|
|
39
|
-
connect?: string[]
|
|
40
|
-
description: string
|
|
41
|
-
downloadURL?: string
|
|
42
|
-
excludeMatches: string[]
|
|
43
|
-
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[];
|
|
44
62
|
/** Empty is the same as `@grant none` */
|
|
45
|
-
grant: string[]
|
|
63
|
+
grant: string[];
|
|
46
64
|
/** Use homepageURL instead */
|
|
47
|
-
homepage?: string
|
|
48
|
-
homepageURL?: string
|
|
49
|
-
icon?: string
|
|
50
|
-
includes: string[]
|
|
51
|
-
matches: string[]
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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;
|
|
62
116
|
}
|
|
63
117
|
|
|
64
118
|
declare interface VMScriptGMInfoObject {
|
|
65
|
-
/**
|
|
66
|
-
uuid: string
|
|
67
|
-
/** The injection mode of current script. */
|
|
68
|
-
injectInto: VMScriptInjectInto
|
|
69
|
-
/** Contains structured fields from the
|
|
70
|
-
script: VMScriptGMInfoScriptMeta
|
|
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;
|
|
71
125
|
/** The meta block of the script. */
|
|
72
|
-
scriptMetaStr: string
|
|
126
|
+
scriptMetaStr: string;
|
|
73
127
|
/** Whether the script will be updated automatically. */
|
|
74
|
-
scriptWillUpdate: boolean
|
|
128
|
+
scriptWillUpdate: boolean;
|
|
75
129
|
/** The name of userscript manager, which should be the string `Violentmonkey`. */
|
|
76
|
-
scriptHandler: string
|
|
130
|
+
scriptHandler: string;
|
|
77
131
|
/** Version of Violentmonkey. */
|
|
78
|
-
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;
|
|
79
145
|
/**
|
|
80
146
|
* Unlike `navigator.userAgent`, which can be overriden by other extensions/userscripts
|
|
81
147
|
* or by devtools in device-emulation mode, `GM_info.platform` is more reliable as the
|
|
82
148
|
* data is obtained in the background page of Violentmonkey using a specialized
|
|
83
149
|
* extension API (`browser.runtime.getPlatformInfo` and `getBrowserInfo`).
|
|
84
150
|
*/
|
|
85
|
-
platform: VMScriptGMInfoPlatform
|
|
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;
|
|
86
160
|
/**
|
|
87
|
-
* A copy of navigator.userAgentData from the content script of the extension
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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;
|
|
94
184
|
}
|
|
95
185
|
|
|
96
186
|
/**
|
|
97
187
|
* An object that exposes information about the current userscript.
|
|
98
188
|
*/
|
|
99
|
-
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
|
+
};
|
|
100
208
|
|
|
101
209
|
/** The original console.log */
|
|
102
|
-
declare function GM_log(...args: any): void
|
|
210
|
+
declare function GM_log(...args: any): void;
|
|
103
211
|
|
|
104
212
|
/** Retrieves a value for current script from storage. */
|
|
105
|
-
declare function GM_getValue<T>(name: string, defaultValue?: T): T
|
|
213
|
+
declare function GM_getValue<T>(name: string, defaultValue?: T | undefined): T;
|
|
106
214
|
/** @since VM2.19.1 */
|
|
107
|
-
declare function GM_getValues(names: string[]): GenericObject
|
|
215
|
+
declare function GM_getValues(names: string[]): GenericObject;
|
|
108
216
|
/** @since VM2.19.1 */
|
|
109
|
-
declare function GM_getValues(namesWithDefaults: GenericObject): GenericObject
|
|
217
|
+
declare function GM_getValues(namesWithDefaults: GenericObject): GenericObject;
|
|
110
218
|
/** Sets a key / value pair for current script to storage. */
|
|
111
|
-
declare function GM_setValue<T>(name: string, value: T): void
|
|
219
|
+
declare function GM_setValue<T>(name: string, value: T): void;
|
|
112
220
|
/** @since VM2.19.1 */
|
|
113
|
-
declare function GM_setValues(values: GenericObject): void
|
|
221
|
+
declare function GM_setValues(values: GenericObject): void;
|
|
114
222
|
/** Deletes an existing key / value pair for current script from storage. */
|
|
115
|
-
declare function GM_deleteValue(name: string): void
|
|
223
|
+
declare function GM_deleteValue(name: string): void;
|
|
116
224
|
/** @since VM2.19.1 */
|
|
117
|
-
declare function GM_deleteValues(names: string[]): void
|
|
225
|
+
declare function GM_deleteValues(names: string[]): void;
|
|
118
226
|
/** Returns an array of keys of all available values within this script. */
|
|
119
|
-
declare function GM_listValues(): string[]
|
|
227
|
+
declare function GM_listValues(): string[];
|
|
120
228
|
|
|
121
229
|
declare type VMScriptGMValueChangeCallback<T> = (
|
|
122
230
|
/** The name of the observed variable */
|
|
@@ -126,22 +234,22 @@ declare type VMScriptGMValueChangeCallback<T> = (
|
|
|
126
234
|
/** The new value of the observed variable (`undefined` if it was deleted) */
|
|
127
235
|
newValue: T,
|
|
128
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. */
|
|
129
|
-
remote: boolean
|
|
130
|
-
) => void
|
|
237
|
+
remote: boolean,
|
|
238
|
+
) => void;
|
|
131
239
|
|
|
132
240
|
/** Adds a change listener to the storage and returns the listener ID. */
|
|
133
241
|
declare function GM_addValueChangeListener<T>(
|
|
134
242
|
name: string,
|
|
135
|
-
callback: VMScriptGMValueChangeCallback<T
|
|
136
|
-
): string
|
|
243
|
+
callback: VMScriptGMValueChangeCallback<T>,
|
|
244
|
+
): string;
|
|
137
245
|
/** Removes a change listener by its ID. */
|
|
138
|
-
declare function GM_removeValueChangeListener(listenerId: string): void
|
|
246
|
+
declare function GM_removeValueChangeListener(listenerId: string): void;
|
|
139
247
|
|
|
140
248
|
/** Retrieves a text resource from the *Metadata Block*. */
|
|
141
249
|
declare function GM_getResourceText(
|
|
142
250
|
/** Name of a resource defined in the *Metadata Block*. */
|
|
143
|
-
name: string
|
|
144
|
-
): string
|
|
251
|
+
name: string,
|
|
252
|
+
): string;
|
|
145
253
|
/**
|
|
146
254
|
* Retrieves a `blob:` or `data:` URL of a resource from the *Metadata Block*.
|
|
147
255
|
*
|
|
@@ -154,8 +262,8 @@ declare function GM_getResourceURL(
|
|
|
154
262
|
* - If `true`, returns a `blob:` URL. It's short and cacheable, so it's good for reusing in multiple DOM elements.
|
|
155
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.
|
|
156
264
|
*/
|
|
157
|
-
isBlobUrl?: boolean
|
|
158
|
-
): string
|
|
265
|
+
isBlobUrl?: boolean | undefined,
|
|
266
|
+
): string;
|
|
159
267
|
|
|
160
268
|
/**
|
|
161
269
|
* Appends and returns an element with the specified attributes.
|
|
@@ -178,8 +286,8 @@ declare function GM_addElement(
|
|
|
178
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. */
|
|
179
287
|
tagName: string,
|
|
180
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. */
|
|
181
|
-
attributes?: Record<string, string>
|
|
182
|
-
): HTMLElement
|
|
289
|
+
attributes?: Record<string, string> | undefined,
|
|
290
|
+
): HTMLElement;
|
|
183
291
|
declare function GM_addElement(
|
|
184
292
|
/**
|
|
185
293
|
* The parent node to which the new node will be appended.
|
|
@@ -194,24 +302,24 @@ declare function GM_addElement(
|
|
|
194
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. */
|
|
195
303
|
tagName: string,
|
|
196
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. */
|
|
197
|
-
attributes?: Record<string, string>
|
|
198
|
-
): HTMLElement
|
|
305
|
+
attributes?: Record<string, string> | undefined,
|
|
306
|
+
): HTMLElement;
|
|
199
307
|
|
|
200
308
|
/** Appends and returns a `<style>` element with the specified CSS. */
|
|
201
|
-
declare function GM_addStyle(css: string): HTMLStyleElement
|
|
309
|
+
declare function GM_addStyle(css: string): HTMLStyleElement;
|
|
202
310
|
|
|
203
311
|
declare interface VMScriptGMTabControl {
|
|
204
312
|
/** Сan be assigned to a function. If provided, it will be called when the opened tab is closed. */
|
|
205
|
-
onclose?: () => void
|
|
313
|
+
onclose?: (() => void) | undefined;
|
|
206
314
|
/** Whether the opened tab is closed. */
|
|
207
|
-
closed: boolean
|
|
315
|
+
closed: boolean;
|
|
208
316
|
/** A function to explicitly close the opened tab. */
|
|
209
|
-
close: () => void
|
|
317
|
+
close: () => void;
|
|
210
318
|
}
|
|
211
319
|
|
|
212
320
|
declare interface VMScriptGMTabOptions {
|
|
213
321
|
/** Make the new tab active (i.e. open in foreground). Default as `true`. */
|
|
214
|
-
active?: boolean
|
|
322
|
+
active?: boolean | undefined;
|
|
215
323
|
/**
|
|
216
324
|
* Firefox only.
|
|
217
325
|
*
|
|
@@ -219,25 +327,25 @@ declare interface VMScriptGMTabOptions {
|
|
|
219
327
|
* - `0` = default (main) container
|
|
220
328
|
* - `1`, `2`, etc. = internal container index
|
|
221
329
|
*/
|
|
222
|
-
container?: number
|
|
330
|
+
container?: number | undefined;
|
|
223
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`. */
|
|
224
|
-
insert?: boolean
|
|
332
|
+
insert?: boolean | undefined;
|
|
225
333
|
/** Pin the tab (i.e. show without a title at the beginning of the tab list). Default as `false`. */
|
|
226
|
-
pinned?: boolean
|
|
334
|
+
pinned?: boolean | undefined;
|
|
227
335
|
}
|
|
228
336
|
|
|
229
337
|
/** Opens URL in a new tab. */
|
|
230
338
|
declare function GM_openInTab(
|
|
231
339
|
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
|
|
232
340
|
url: string,
|
|
233
|
-
options?: VMScriptGMTabOptions
|
|
234
|
-
): VMScriptGMTabControl
|
|
341
|
+
options?: VMScriptGMTabOptions | undefined,
|
|
342
|
+
): VMScriptGMTabControl;
|
|
235
343
|
declare function GM_openInTab(
|
|
236
344
|
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
|
|
237
345
|
url: string,
|
|
238
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 }`. */
|
|
239
|
-
openInBackground?: boolean
|
|
240
|
-
): VMScriptGMTabControl
|
|
347
|
+
openInBackground?: boolean | undefined,
|
|
348
|
+
): VMScriptGMTabControl;
|
|
241
349
|
|
|
242
350
|
/**
|
|
243
351
|
* Registers a command in Violentmonkey popup menu.
|
|
@@ -250,22 +358,26 @@ declare function GM_registerMenuCommand(
|
|
|
250
358
|
/** Callback function when the command is clicked in the menu. */
|
|
251
359
|
onClick: (event: MouseEvent | KeyboardEvent) => void,
|
|
252
360
|
/** @since VM2.15.9 */
|
|
253
|
-
options?:
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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;
|
|
264
376
|
/** Unregisters a command which has been registered to Violentmonkey popup menu. */
|
|
265
377
|
declare function GM_unregisterMenuCommand(
|
|
266
378
|
/** The name of command to unregister. */
|
|
267
|
-
caption: string
|
|
268
|
-
): void
|
|
379
|
+
caption: string,
|
|
380
|
+
): void;
|
|
269
381
|
|
|
270
382
|
/**
|
|
271
383
|
* A control object returned by `GM_notification`.
|
|
@@ -273,19 +385,19 @@ declare function GM_unregisterMenuCommand(
|
|
|
273
385
|
*/
|
|
274
386
|
declare interface VMScriptGMNotificationControl {
|
|
275
387
|
/** Remove the notification immediately. */
|
|
276
|
-
remove: () => Promise<void
|
|
388
|
+
remove: () => Promise<void>;
|
|
277
389
|
}
|
|
278
390
|
|
|
279
391
|
declare interface VMScriptGMNotificationOptions {
|
|
280
392
|
/** Main text of the notification. */
|
|
281
|
-
text: string
|
|
393
|
+
text: string;
|
|
282
394
|
/** Title of the notification. */
|
|
283
|
-
title?: string
|
|
395
|
+
title?: string | undefined;
|
|
284
396
|
/** URL of an image to show in the notification. */
|
|
285
|
-
image?: string
|
|
397
|
+
image?: string | undefined;
|
|
286
398
|
/** No sounds/vibrations when showing the notification.
|
|
287
399
|
* @since VM2.15.2, Chrome 70. */
|
|
288
|
-
silent?: boolean
|
|
400
|
+
silent?: boolean | undefined;
|
|
289
401
|
/**
|
|
290
402
|
* Unique name of the notification, e.g. 'abc', same as the web Notification API.
|
|
291
403
|
* Names are scoped to each userscript i.e. your tag won't clash with another script's tag.
|
|
@@ -294,54 +406,54 @@ declare interface VMScriptGMNotificationOptions {
|
|
|
294
406
|
* and your notification had `zombieTimeout`).
|
|
295
407
|
* @since VM2.15.4
|
|
296
408
|
*/
|
|
297
|
-
tag?: string
|
|
409
|
+
tag?: string | undefined;
|
|
298
410
|
/**
|
|
299
411
|
* Number of milliseconds to keep the notification after the userscript "dies",
|
|
300
412
|
* i.e. when its tab or frame is reloaded/closed/navigated. If not specified or invalid,
|
|
301
413
|
* the default behavior is to immediately remove the notifications.
|
|
302
414
|
* @since VM2.15.4
|
|
303
415
|
*/
|
|
304
|
-
zombieTimeout?: number
|
|
416
|
+
zombieTimeout?: number | undefined;
|
|
305
417
|
/**
|
|
306
418
|
* URL to open when a zombie notification is clicked, see `zombieTimeout` for more info.
|
|
307
419
|
* @since VM2.16.1
|
|
308
420
|
*/
|
|
309
|
-
zombieUrl?: string
|
|
421
|
+
zombieUrl?: string | undefined;
|
|
310
422
|
/** Callback when the notification is clicked by user. */
|
|
311
|
-
onclick?: () => void
|
|
423
|
+
onclick?: (() => void) | undefined;
|
|
312
424
|
/** Callback when the notification is closed, either by user or by system. */
|
|
313
|
-
ondone?: () => void
|
|
425
|
+
ondone?: (() => void) | undefined;
|
|
314
426
|
}
|
|
315
427
|
|
|
316
428
|
/** Shows an HTML5 desktop notification. */
|
|
317
429
|
declare function GM_notification(
|
|
318
|
-
options: VMScriptGMNotificationOptions
|
|
319
|
-
): VMScriptGMNotificationControl
|
|
430
|
+
options: VMScriptGMNotificationOptions,
|
|
431
|
+
): VMScriptGMNotificationControl;
|
|
320
432
|
declare function GM_notification(
|
|
321
433
|
/** Main text of the notification. */
|
|
322
434
|
text: string,
|
|
323
435
|
/** Title of the notification. */
|
|
324
|
-
title?: string,
|
|
436
|
+
title?: string | undefined,
|
|
325
437
|
/** URL of an image to show in the notification. */
|
|
326
|
-
image?: string,
|
|
438
|
+
image?: string | undefined,
|
|
327
439
|
/** Callback when the notification is clicked by user. */
|
|
328
|
-
onclick?: () => void
|
|
329
|
-
): VMScriptGMNotificationControl
|
|
440
|
+
onclick?: (() => void) | undefined,
|
|
441
|
+
): VMScriptGMNotificationControl;
|
|
330
442
|
|
|
331
443
|
/** Sets data to system clipboard. */
|
|
332
444
|
declare function GM_setClipboard(
|
|
333
445
|
/** The data to be copied to system clipboard. */
|
|
334
446
|
data: string,
|
|
335
447
|
/** The MIME type of data to copy. Default as `text/plain`. */
|
|
336
|
-
type?: string
|
|
337
|
-
): void
|
|
448
|
+
type?: string | undefined,
|
|
449
|
+
): void;
|
|
338
450
|
|
|
339
451
|
/**
|
|
340
452
|
* A control object returned by `GM_xmlhttpRequest`.
|
|
341
453
|
* `control.abort()` can be used to abort the request.
|
|
342
454
|
*/
|
|
343
455
|
declare interface VMScriptXHRControl {
|
|
344
|
-
abort: () => void
|
|
456
|
+
abort: () => void;
|
|
345
457
|
}
|
|
346
458
|
|
|
347
459
|
declare type VMScriptResponseType =
|
|
@@ -349,27 +461,27 @@ declare type VMScriptResponseType =
|
|
|
349
461
|
| 'json'
|
|
350
462
|
| 'blob'
|
|
351
463
|
| 'arraybuffer'
|
|
352
|
-
| 'document'
|
|
464
|
+
| 'document';
|
|
353
465
|
|
|
354
466
|
/**
|
|
355
467
|
* https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#properties
|
|
356
468
|
* https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent#properties
|
|
357
469
|
*/
|
|
358
470
|
declare interface VMScriptResponseObject<T> {
|
|
359
|
-
status: number
|
|
360
|
-
statusText: string
|
|
361
|
-
readyState: number
|
|
362
|
-
responseHeaders: string
|
|
363
|
-
response: T | null
|
|
364
|
-
responseText: string | undefined
|
|
365
|
-
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;
|
|
366
478
|
/** The final URL after redirection. */
|
|
367
|
-
finalUrl: string
|
|
368
|
-
lengthComputable?: boolean
|
|
369
|
-
loaded?: number
|
|
370
|
-
total?: number
|
|
479
|
+
finalUrl: string;
|
|
480
|
+
lengthComputable?: boolean | undefined;
|
|
481
|
+
loaded?: number | undefined;
|
|
482
|
+
total?: number | undefined;
|
|
371
483
|
/** The same `context` object you specified in `details`. */
|
|
372
|
-
context?: unknown
|
|
484
|
+
context?: unknown | undefined;
|
|
373
485
|
}
|
|
374
486
|
|
|
375
487
|
type TypedArray =
|
|
@@ -383,15 +495,15 @@ type TypedArray =
|
|
|
383
495
|
| BigUint64Array
|
|
384
496
|
| BigInt64Array
|
|
385
497
|
| Float32Array
|
|
386
|
-
| Float64Array
|
|
498
|
+
| Float64Array;
|
|
387
499
|
|
|
388
|
-
interface GMRequestBase<T> {
|
|
500
|
+
interface GMRequestBase<T> extends GMRequestBaseEvents<T> {
|
|
389
501
|
/** URL relative to current page is also allowed. */
|
|
390
|
-
url: string
|
|
502
|
+
url: string;
|
|
391
503
|
/** User for authentication. */
|
|
392
|
-
user?: string
|
|
504
|
+
user?: string | undefined;
|
|
393
505
|
/** Password for authentication. */
|
|
394
|
-
password?: string
|
|
506
|
+
password?: string | undefined;
|
|
395
507
|
/**
|
|
396
508
|
* Some special headers are also allowed:
|
|
397
509
|
*
|
|
@@ -401,28 +513,31 @@ interface GMRequestBase<T> {
|
|
|
401
513
|
* - `Referer`
|
|
402
514
|
* - `User-Agent`
|
|
403
515
|
*/
|
|
404
|
-
headers?: Record<string, string>
|
|
516
|
+
headers?: Record<string, string> | undefined;
|
|
405
517
|
/** Time to wait for the request, none by default. */
|
|
406
|
-
timeout?: number
|
|
518
|
+
timeout?: number | undefined;
|
|
407
519
|
/** Can be an object and will be assigned to context of the response object. */
|
|
408
|
-
context?: unknown
|
|
520
|
+
context?: unknown | undefined;
|
|
409
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`. */
|
|
410
|
-
anonymous?: boolean
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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;
|
|
419
534
|
}
|
|
420
535
|
|
|
421
536
|
declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
|
|
422
537
|
/** HTTP method, default as `GET`. */
|
|
423
|
-
method?: string
|
|
538
|
+
method?: string | undefined;
|
|
424
539
|
/** A MIME type to specify with the request. */
|
|
425
|
-
overrideMimeType?: string
|
|
540
|
+
overrideMimeType?: string | undefined;
|
|
426
541
|
/**
|
|
427
542
|
* One of the following:
|
|
428
543
|
*
|
|
@@ -432,7 +547,7 @@ declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
|
|
|
432
547
|
* - `arraybuffer`
|
|
433
548
|
* - `document`
|
|
434
549
|
*/
|
|
435
|
-
responseType?: VMScriptResponseType
|
|
550
|
+
responseType?: VMScriptResponseType | undefined;
|
|
436
551
|
/** Data to send with the request, usually for `POST` and `PUT` requests. */
|
|
437
552
|
data?:
|
|
438
553
|
| string
|
|
@@ -443,67 +558,85 @@ declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
|
|
|
443
558
|
| ReadableStream
|
|
444
559
|
| TypedArray
|
|
445
560
|
| URLSearchParams
|
|
561
|
+
| undefined;
|
|
446
562
|
/** Send the `data` string as a `blob`. This is for compatibility with Tampermonkey/Greasemonkey, where only `string` type is allowed in `data`. */
|
|
447
|
-
binary?: boolean
|
|
563
|
+
binary?: boolean | undefined;
|
|
564
|
+
/** @since VM2.32.0 */
|
|
565
|
+
upload?: GMRequestBaseEvents<T>;
|
|
448
566
|
}
|
|
449
567
|
|
|
450
568
|
/** Makes a request like XMLHttpRequest, with some special capabilities, not restricted by same-origin policy. */
|
|
451
569
|
declare function GM_xmlhttpRequest<
|
|
452
|
-
T = string | Blob | ArrayBuffer | Document | object
|
|
453
|
-
>(details: VMScriptGMXHRDetails<T>): VMScriptXHRControl
|
|
570
|
+
T = string | Blob | ArrayBuffer | Document | object,
|
|
571
|
+
>(details: VMScriptGMXHRDetails<T>): VMScriptXHRControl;
|
|
454
572
|
|
|
455
573
|
declare interface VMScriptGMDownloadOptions extends GMRequestBase<Blob> {
|
|
456
574
|
/** The filename to save as. */
|
|
457
|
-
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;
|
|
458
580
|
}
|
|
459
581
|
|
|
460
582
|
/** Downloads a URL to a local file. */
|
|
461
|
-
declare function GM_download(options: VMScriptGMDownloadOptions): void
|
|
583
|
+
declare function GM_download(options: VMScriptGMDownloadOptions): void;
|
|
462
584
|
declare function GM_download(
|
|
463
585
|
/** The URL to download. */
|
|
464
586
|
url: string,
|
|
465
587
|
/** The filename to save as. */
|
|
466
|
-
name: string
|
|
467
|
-
): void
|
|
588
|
+
name: string,
|
|
589
|
+
): void;
|
|
468
590
|
|
|
469
591
|
/** Aliases for GM_ methods that are not included in Greasemonkey4 API */
|
|
470
592
|
declare interface VMScriptGMObjectVMExtensions {
|
|
471
|
-
addElement: typeof GM_addElement
|
|
472
|
-
addStyle: typeof GM_addStyle
|
|
473
|
-
addValueChangeListener: typeof GM_addValueChangeListener
|
|
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;
|
|
474
610
|
/** @since VM2.19.1 */
|
|
475
|
-
|
|
476
|
-
download:
|
|
477
|
-
| ((options: VMScriptGMDownloadOptions) => Promise<Blob> | void)
|
|
478
|
-
| ((url: string, name: string) => Promise<Blob> | void)
|
|
479
|
-
getResourceText: typeof GM_getResourceText
|
|
611
|
+
getValues(names: string[]): Promise<GenericObject>;
|
|
480
612
|
/** @since VM2.19.1 */
|
|
481
|
-
getValues:
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
log: typeof GM_log
|
|
485
|
-
removeValueChangeListener: typeof GM_removeValueChangeListener
|
|
613
|
+
getValues(namesWithDefaults: GenericObject): Promise<GenericObject>;
|
|
614
|
+
log: typeof GM_log;
|
|
615
|
+
removeValueChangeListener: typeof GM_removeValueChangeListener;
|
|
486
616
|
/** @since VM2.19.1 */
|
|
487
|
-
setValues: (values: GenericObject) => Promise<void
|
|
488
|
-
unregisterMenuCommand: typeof GM_unregisterMenuCommand
|
|
617
|
+
setValues: (values: GenericObject) => Promise<void>;
|
|
618
|
+
unregisterMenuCommand: typeof GM_unregisterMenuCommand;
|
|
489
619
|
}
|
|
490
620
|
|
|
491
621
|
/** The Greasemonkey4 API, https://wiki.greasespot.net/Greasemonkey_Manual:API */
|
|
492
622
|
declare interface VMScriptGMObject extends VMScriptGMObjectVMExtensions {
|
|
493
|
-
unsafeWindow: Window
|
|
494
|
-
info: typeof GM_info
|
|
495
|
-
getValue: <T>(name: string, defaultValue?: T) => Promise<T
|
|
496
|
-
setValue: <T>(name: string, value: T) => Promise<void
|
|
497
|
-
deleteValue: (name: string) => Promise<void
|
|
498
|
-
listValues: () => Promise<string[]
|
|
499
|
-
registerMenuCommand: typeof GM_registerMenuCommand
|
|
500
|
-
getResourceUrl: (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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;
|
|
504
637
|
xmlHttpRequest: <T = string | Blob | ArrayBuffer | Document | object>(
|
|
505
|
-
details: VMScriptGMXHRDetails<T
|
|
506
|
-
) => Promise<T> & VMScriptXHRControl
|
|
638
|
+
details: VMScriptGMXHRDetails<T>,
|
|
639
|
+
) => Promise<T> & VMScriptXHRControl;
|
|
507
640
|
}
|
|
508
641
|
|
|
509
|
-
declare const GM: VMScriptGMObject
|
|
642
|
+
declare const GM: VMScriptGMObject;
|