vite-userscript-plugin 1.11.0 → 2.1.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 +161 -98
- package/dist/index.d.ts +264 -180
- package/dist/index.js +1032 -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/greasemonkey.d.ts
CHANGED
|
@@ -1,308 +1,305 @@
|
|
|
1
|
+
// synced from @types/greasemonkey@4.0.7
|
|
2
|
+
// do not edit; run pnpm sync-types
|
|
3
|
+
|
|
1
4
|
// This definition is based on the API reference of Greasemonkey
|
|
2
5
|
// https://wiki.greasespot.net/Greasemonkey_Manual:API
|
|
3
6
|
// TypeScript Version: 3.2
|
|
4
7
|
|
|
5
8
|
declare namespace GM {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
interface ScriptInfo {
|
|
10
|
+
/** Possibly empty string. */
|
|
11
|
+
description: string;
|
|
12
|
+
excludes: string[];
|
|
13
|
+
includes: string[];
|
|
14
|
+
matches: string[];
|
|
15
|
+
name: string;
|
|
16
|
+
/** Possibly empty string. */
|
|
17
|
+
namespace: string;
|
|
18
|
+
/**
|
|
19
|
+
* An object keyed by resource name.
|
|
20
|
+
* Each value is an object with keys `name` and `mimetype` and `url`
|
|
21
|
+
* with string values.
|
|
22
|
+
*/
|
|
23
|
+
resources: {
|
|
24
|
+
[resourceName: string]: {
|
|
25
|
+
name: string;
|
|
26
|
+
mimetype: string;
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/** @default 'end' */
|
|
31
|
+
runAt: "start" | "end" | "idle";
|
|
32
|
+
uuid: string;
|
|
33
|
+
/** Possibly empty string. */
|
|
34
|
+
version: string;
|
|
26
35
|
}
|
|
27
|
-
/** @default 'end' */
|
|
28
|
-
runAt: 'start' | 'end' | 'idle'
|
|
29
|
-
uuid: string
|
|
30
|
-
/** Possibly empty string. */
|
|
31
|
-
version: string
|
|
32
|
-
}
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
type Value = string | boolean | number;
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
interface Response<TContext> {
|
|
40
|
+
readonly responseHeaders: string;
|
|
41
|
+
readonly finalUrl: string;
|
|
42
|
+
/** The same object passed into the original request */
|
|
43
|
+
readonly context?: TContext | undefined;
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
readonly readyState: 1 | 2 | 3 | 4;
|
|
46
|
+
readonly response: any;
|
|
47
|
+
readonly responseText: string;
|
|
48
|
+
readonly responseXML: Document | false;
|
|
49
|
+
readonly status: number;
|
|
50
|
+
readonly statusText: string;
|
|
51
|
+
}
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
interface ProgressResponse<TContext> extends Response<TContext> {
|
|
54
|
+
lengthComputable: boolean;
|
|
55
|
+
loaded: number;
|
|
56
|
+
total: number;
|
|
57
|
+
}
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
interface Request<TContext = any> {
|
|
60
|
+
// Fields
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
onload?(response: Response<TContext>): void
|
|
130
|
-
onprogress?(response: ProgressResponse<TContext>): void
|
|
131
|
-
}
|
|
132
|
-
| undefined
|
|
62
|
+
/**
|
|
63
|
+
* The URL to make the request to. Must be an absolute URL, beginning
|
|
64
|
+
* with the scheme. May be relative to the current page.
|
|
65
|
+
*/
|
|
66
|
+
url: string;
|
|
67
|
+
/** String type of HTTP request to make (E.G. "GET", "POST") */
|
|
68
|
+
method:
|
|
69
|
+
| "GET"
|
|
70
|
+
| "POST"
|
|
71
|
+
| "PUT"
|
|
72
|
+
| "DELETE"
|
|
73
|
+
| "PATCH"
|
|
74
|
+
| "HEAD"
|
|
75
|
+
| "TRACE"
|
|
76
|
+
| "OPTIONS"
|
|
77
|
+
| "CONNECT";
|
|
78
|
+
/**
|
|
79
|
+
* When true, the data is sent as a Blob
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
binary?: boolean | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Any object (Compatibility: 1.10+). This object will also be the
|
|
85
|
+
* context property of the Response Object.
|
|
86
|
+
*/
|
|
87
|
+
context?: TContext | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Data to send in the request body. Usually for POST method requests.
|
|
90
|
+
* If the data field contains form-encoded data, you usually must also
|
|
91
|
+
* set the header `'Content-Type': 'application/x-www-form-urlencoded'`
|
|
92
|
+
* in the `headers` field.
|
|
93
|
+
*/
|
|
94
|
+
data?: string | undefined;
|
|
95
|
+
/** A set of headers to include in the request */
|
|
96
|
+
headers?: {
|
|
97
|
+
[header: string]: string;
|
|
98
|
+
} | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* A MIME type to specify with the request (e.g.
|
|
101
|
+
* "text/html; charset=ISO-8859-1")
|
|
102
|
+
*/
|
|
103
|
+
overrideMimeType?: string | undefined;
|
|
104
|
+
/** User name to use for authentication purposes. */
|
|
105
|
+
user?: string | undefined;
|
|
106
|
+
/** Password to use for authentication purposes */
|
|
107
|
+
password?: string | undefined;
|
|
108
|
+
/** Decode the response as specified type. Default value is "text" */
|
|
109
|
+
responseType?: XMLHttpRequestResponseType | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* When `true`, this is a synchronous request.
|
|
112
|
+
* Be careful: The entire Firefox UI will be locked and frozen until the
|
|
113
|
+
* request completes.In this mode, more data will be available in the
|
|
114
|
+
* return value.
|
|
115
|
+
*/
|
|
116
|
+
synchronous?: boolean | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The number of milliseconds to wait before terminating the call. Zero
|
|
119
|
+
* (the default) means wait forever.
|
|
120
|
+
*/
|
|
121
|
+
timeout?: number | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Object containing optional function callbacks to monitor the upload
|
|
124
|
+
* of data.
|
|
125
|
+
*/
|
|
126
|
+
upload?: {
|
|
127
|
+
onabort?(response: Response<TContext>): void;
|
|
128
|
+
onerror?(response: Response<TContext>): void;
|
|
129
|
+
onload?(response: Response<TContext>): void;
|
|
130
|
+
onprogress?(response: ProgressResponse<TContext>): void;
|
|
131
|
+
} | undefined;
|
|
133
132
|
|
|
134
|
-
|
|
133
|
+
// Event handlers
|
|
135
134
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
135
|
+
/** Will be called when the request is aborted */
|
|
136
|
+
onabort?(response: Response<TContext>): void;
|
|
137
|
+
/** Will be called if an error occurs while processing the request */
|
|
138
|
+
onerror?(response: Response<TContext>): void;
|
|
139
|
+
/** Will be called when the request has completed successfully */
|
|
140
|
+
onload?(response: Response<TContext>): void;
|
|
141
|
+
/** Will be called when the request progress changes */
|
|
142
|
+
onprogress?(response: ProgressResponse<TContext>): void;
|
|
143
|
+
/** Will be called repeatedly while the request is in progress */
|
|
144
|
+
onreadystatechange?(response: Response<TContext>): void;
|
|
145
|
+
/** Will be called if/when the request times out */
|
|
146
|
+
ontimeout?(response: Response<TContext>): void;
|
|
147
|
+
}
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
/**
|
|
152
151
|
* Window object of the content page where the user script is running on.
|
|
153
152
|
* @see {@link http://wiki.greasespot.net/UnsafeWindow}
|
|
154
153
|
*/
|
|
155
|
-
declare var unsafeWindow: Window
|
|
154
|
+
declare var unsafeWindow: Window;
|
|
156
155
|
|
|
157
156
|
declare var GM: {
|
|
158
|
-
|
|
157
|
+
// Headers
|
|
159
158
|
|
|
160
|
-
/**
|
|
161
|
-
* Meta data about the running user script.
|
|
162
|
-
* @see {@link https://wiki.greasespot.net/GM.info}
|
|
163
|
-
*/
|
|
164
|
-
info: {
|
|
165
|
-
/** An object containing data about the currently running script */
|
|
166
|
-
script: GM.ScriptInfo
|
|
167
159
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
160
|
+
* Meta data about the running user script.
|
|
161
|
+
* @see {@link https://wiki.greasespot.net/GM.info}
|
|
170
162
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
163
|
+
info: {
|
|
164
|
+
/** An object containing data about the currently running script */
|
|
165
|
+
script: GM.ScriptInfo;
|
|
166
|
+
/**
|
|
167
|
+
* A string, the entire literal Metadata Block (without the delimiters)
|
|
168
|
+
* for the currently running script
|
|
169
|
+
*/
|
|
170
|
+
scriptMetaStr: string;
|
|
171
|
+
/**
|
|
172
|
+
* The name of the user script engine handling this script's execution.
|
|
173
|
+
* The string `Greasemonkey`
|
|
174
|
+
*/
|
|
175
|
+
scriptHandler: string;
|
|
176
|
+
/** The version of Greasemonkey, a string e.g. `4.0` */
|
|
177
|
+
version: string;
|
|
178
|
+
};
|
|
180
179
|
|
|
181
|
-
|
|
180
|
+
// Values
|
|
182
181
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Allows user script authors to persist simple values across page loads and
|
|
184
|
+
* across origins.
|
|
185
|
+
* Strings, booleans, and integers are currently the only allowed data types.
|
|
186
|
+
* @see {@link https://wiki.greasespot.net/GM.setValue}
|
|
187
|
+
* @param name The unique (within this script) name for this value.
|
|
188
|
+
* Should be restricted to valid Javascript identifier characters.
|
|
189
|
+
* @param value Any valid value of these types. Any other type may cause
|
|
190
|
+
* undefined behavior, including crashes
|
|
191
|
+
* @returns A Promise, resolved successfully with no value on success,
|
|
192
|
+
* rejected with no value on failure
|
|
193
|
+
*/
|
|
194
|
+
setValue(name: string, value: GM.Value): Promise<void>;
|
|
196
195
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves a value that was set with `GM.setValue`
|
|
198
|
+
* @see {@link https://wiki.greasespot.net/GM.getValue}
|
|
199
|
+
* @param name The property name to get
|
|
200
|
+
* @param defaultValue The default value to be returned when none has
|
|
201
|
+
* previously been set
|
|
202
|
+
* @returns A Promise, rejected in case of error and otherwise resolved with:
|
|
203
|
+
* - When this name has been set - `string`, `integer` or `boolean` as
|
|
204
|
+
* previously set
|
|
205
|
+
* - When this name has not been set, and default is provided - The value
|
|
206
|
+
* passed as default
|
|
207
|
+
* - When this name has not been set, and default is not provided -
|
|
208
|
+
* `undefined`
|
|
209
|
+
* @example
|
|
210
|
+
* // Retrieving the value associated with the name 'timezoneOffset' with a default value defined:
|
|
211
|
+
* const timezoneOffset = await GM.getValue("timezoneOffset", -5)
|
|
212
|
+
* @example
|
|
213
|
+
* // For structured data used `JSON.stringify()` to place an object into storage and then `JSON.parse()` to convert it back
|
|
214
|
+
* const storedObject = JSON.parse(await GM.getValue('foo', '{}'));
|
|
215
|
+
*/
|
|
216
|
+
getValue(
|
|
217
|
+
name: string,
|
|
218
|
+
): Promise<GM.Value | undefined>;
|
|
219
|
+
getValue<TValue = GM.Value>(
|
|
220
|
+
name: string,
|
|
221
|
+
defaultValue: TValue,
|
|
222
|
+
): Promise<TValue>;
|
|
222
223
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Deletes an existing name / value pair from storage.
|
|
226
|
+
* @see {@link https://wiki.greasespot.net/GM.deleteValue}
|
|
227
|
+
* @param name Property name to delete
|
|
228
|
+
* @returns A Promise, resolved successfully with no value on success,
|
|
229
|
+
* rejected with no value on failure.
|
|
230
|
+
*/
|
|
231
|
+
deleteValue(name: string): Promise<void>;
|
|
231
232
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Retrieves an array of preference names that this script has stored
|
|
235
|
+
* @see {@link https://wiki.greasespot.net/GM.listValues}
|
|
236
|
+
* @returns A Promise, rejected in case of error and otherwise resolved with
|
|
237
|
+
* an string[] for previously set values
|
|
238
|
+
*/
|
|
239
|
+
listValues(): Promise<string[]>;
|
|
239
240
|
|
|
240
|
-
|
|
241
|
+
// Resources
|
|
241
242
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Given a defined `@resource`, this method returns it as a URL
|
|
245
|
+
* @see {@link https://wiki.greasespot.net/GM.getResourceUrl}
|
|
246
|
+
* @param resourceName The name provided when the `@resource` was defined
|
|
247
|
+
* @returns A Promise, rejected on failure and resolved with a string URL on
|
|
248
|
+
* success.
|
|
249
|
+
* Treat the result as opaque string. It will work where you need a URL
|
|
250
|
+
* (for a `<link>` or `<style>` for CSS, for an `<img>` tag, or similar).
|
|
251
|
+
*/
|
|
252
|
+
getResourceUrl(resourceName: string): Promise<string>;
|
|
252
253
|
|
|
253
|
-
|
|
254
|
+
// Other
|
|
254
255
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
256
|
+
/**
|
|
257
|
+
* Displays a notification to the user, using the underlying operating
|
|
258
|
+
* system's notification mechanism
|
|
259
|
+
* @see {@link https://wiki.greasespot.net/GM.notification}
|
|
260
|
+
* @param text The main notification text
|
|
261
|
+
* @param title The title of the notification
|
|
262
|
+
* @param image The URL for an image to display in the dialog. If not
|
|
263
|
+
* provided, the Greasemonkey logo by default.
|
|
264
|
+
* @param onClick Callback, triggered when the notification's button is
|
|
265
|
+
* clicked.
|
|
266
|
+
*/
|
|
267
|
+
notification(
|
|
268
|
+
text: string,
|
|
269
|
+
title: string,
|
|
270
|
+
image?: string,
|
|
271
|
+
onClick?: () => void,
|
|
272
|
+
): void;
|
|
272
273
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Opens the specified URL in a new tab.
|
|
276
|
+
* @see {@link https://wiki.greasespot.net/GM.openInTab}
|
|
277
|
+
* @param url The URL to navigate the new tab to
|
|
278
|
+
* @param openInBackground Force tab to/to not open in a background tab.
|
|
279
|
+
* Default (unspecified) behavior honors Firefox configuration.
|
|
280
|
+
*/
|
|
281
|
+
openInTab(url: string, openInBackground?: boolean): void;
|
|
281
282
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
caption: string,
|
|
292
|
-
commandFunc: () => void,
|
|
293
|
-
accessKey?: string
|
|
294
|
-
): void
|
|
283
|
+
/**
|
|
284
|
+
* Adds an item to the User Script Commands menu.
|
|
285
|
+
* @param caption The caption to display on the menu item.
|
|
286
|
+
* @param commandFunc The function to call when the menu item is selected.
|
|
287
|
+
* @param accessKey A single character that can be used to select the
|
|
288
|
+
* item when the menu is open. It should be a letter in the caption.
|
|
289
|
+
* @see {@link https://wiki.greasespot.net/GM.registerMenuCommand}
|
|
290
|
+
*/
|
|
291
|
+
registerMenuCommand(caption: string, commandFunc: () => void, accessKey?: string): void;
|
|
295
292
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Sets the current contents of the operating system's clipboard
|
|
295
|
+
* @see {@link https://wiki.greasespot.net/GM.setClipboard}
|
|
296
|
+
*/
|
|
297
|
+
setClipboard(text: string): void;
|
|
301
298
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
299
|
+
/**
|
|
300
|
+
* Performs a similar function to the standard XMLHttpRequest object, but
|
|
301
|
+
* allows these requests to cross the [same origin policy]{@link https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy} boundaries.
|
|
302
|
+
* @see {@link https://wiki.greasespot.net/GM.xmlHttpRequest}
|
|
303
|
+
*/
|
|
304
|
+
xmlHttpRequest(details: GM.Request): void;
|
|
305
|
+
};
|