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