Skip to content

Commit 5939ded

Browse files
committed
doc: sync with official docs
1 parent cdaf256 commit 5939ded

File tree

1 file changed

+110
-58
lines changed

1 file changed

+110
-58
lines changed

index.d.ts

Lines changed: 110 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
11
declare const unsafeWindow: Window;
22

3-
declare type VMScriptRunAt = 'document-start' | 'document-body' | 'document-end' | 'document-idle';
3+
declare type VMScriptRunAt =
4+
| 'document-start'
5+
| 'document-body'
6+
| 'document-end'
7+
| 'document-idle';
48

59
/** Injection mode of a script. */
610
declare type VMScriptInjectInto = 'auto' | 'page' | 'content';
711

812
declare type GenericObject = Record<string, unknown>;
913

1014
declare interface VMScriptGMInfoPlatform {
11-
arch: 'aarch64' | 'arm' | 'arm64' | 'mips' | 'mips64' | 'ppc64' | 's390x' | 'sparc64' | 'x86-32' | 'x86-64';
15+
arch:
16+
| 'aarch64'
17+
| 'arm'
18+
| 'arm64'
19+
| 'mips'
20+
| 'mips64'
21+
| 'ppc64'
22+
| 's390x'
23+
| 'sparc64'
24+
| 'x86-32'
25+
| 'x86-64';
1226
browserName: 'chrome' | 'firefox' | string;
1327
browserVersion: string;
1428
/**
1529
* A copy of `navigator.userAgentData.getHighEntropyValues()` from the background script
1630
* of the extension, so it's not affected by devtools of the web page tab.
17-
* Not present in browsers that don't implement this API.
18-
* @since VM2.27.0 */
19-
fullVersionList?: {brand: string, version: string}[];
31+
* Only present in browsers that implement this API (Chromium >= 90).
32+
* @since VM2.27.0
33+
*/
34+
fullVersionList?: { brand: string; version: string }[];
2035
/**
2136
* A copy of `navigator.userAgentData.mobile` from the background script of the extension,
2237
* so it's not affected by devtools of the web page tab.
23-
* Not present in browsers that don't implement this API.
24-
* @since VM2.27.0 */
38+
* Only present in browsers that implement this API (Chromium >= 90).
39+
* @since VM2.27.0
40+
*/
2541
mobile?: boolean;
2642
os: 'mac' | 'win' | 'android' | 'cros' | 'linux' | 'openbsd' | 'fuchsia';
2743
}
@@ -60,11 +76,11 @@ declare interface VMScriptGMInfoScriptMeta {
6076
}
6177

6278
declare interface VMScriptGMInfoObject {
63-
/** Unique ID of the script. */
79+
/** A unique ID of the script. */
6480
uuid: string;
65-
/** The injection mode of current script. */
81+
/** The injection mode of current script. See [`@inject-into`](https://violentmonkey.github.io/api/metadata-block/#inject-into) for more information. */
6682
injectInto: VMScriptInjectInto;
67-
/** Contains structured fields from the *Metadata Block*. */
83+
/** Contains structured fields from the [Metadata Block](https://violentmonkey.github.io/api/metadata-block/). */
6884
script: VMScriptGMInfoScriptMeta;
6985
/** The meta block of the script. */
7086
scriptMetaStr: string;
@@ -74,6 +90,11 @@ declare interface VMScriptGMInfoObject {
7490
scriptHandler: string;
7591
/** Version of Violentmonkey. */
7692
version: string;
93+
/**
94+
* True when this is an incognito profile (Chrome) or private mode (Firefox).
95+
* @since VM2.15.4
96+
*/
97+
isIncognito: boolean;
7798
/**
7899
* Unlike `navigator.userAgent`, which can be overriden by other extensions/userscripts
79100
* or by devtools in device-emulation mode, `GM_info.platform` is more reliable as the
@@ -82,18 +103,34 @@ declare interface VMScriptGMInfoObject {
82103
*/
83104
platform: VMScriptGMInfoPlatform;
84105
/**
85-
* A copy of navigator.userAgent from the content script of the extension.
86-
* @since VM2.20.2 */
106+
* A safe copy of `navigator.userAgent` from the content script of the extension,
107+
* so it cannot be overridden by other extensions/userscripts, but unlike
108+
* `GM_info.platform` it can be customized in devtools “device emulation” or
109+
* “network conditions” for this tab.
110+
* @since VM2.20.2
111+
*/
87112
userAgent: string;
88113
/**
89-
* A copy of navigator.userAgentData from the content script of the extension.
90-
* Not present in browsers that don't implement this API.
91-
* @since VM2.20.2 */
114+
* A safe copy of `navigator.userAgentData` from the content script of the extension,
115+
* so it cannot be overridden by other extensions/userscripts, but unlike
116+
* `GM_info.platform` it can be customized in devtools "device emulation" or
117+
* "network conditions" for this tab.
118+
*
119+
* Only present if the browser actually implements it
120+
* ([currently](https://caniuse.com/mdn-api_navigator_useragentdata) Chromium-based 90+),
121+
* because there's no reliable/official polyfill.
122+
*
123+
* Violentmonkey implements the [official API](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData),
124+
* including [getHighEntropyValues](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues)
125+
* function to obtain the extra info asynchronously.
126+
*
127+
* @since VM2.20.2
128+
*/
92129
userAgentData?: {
93-
brands: {brand: string, version: string}[],
94-
mobile: boolean,
95-
platform: string,
96-
getHighEntropyValues(hints: string[]): Promise<UADataValues>,
130+
brands: { brand: string; version: string }[];
131+
mobile: boolean;
132+
platform: string;
133+
getHighEntropyValues(hints: string[]): Promise<UADataValues>;
97134
};
98135
}
99136

@@ -130,21 +167,21 @@ declare type VMScriptGMValueChangeCallback<T> = (
130167
/** The new value of the observed variable (`undefined` if it was deleted) */
131168
newValue: T,
132169
/** `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. */
133-
remote: boolean
170+
remote: boolean,
134171
) => void;
135172

136173
/** Adds a change listener to the storage and returns the listener ID. */
137174
declare function GM_addValueChangeListener<T>(
138175
name: string,
139-
callback: VMScriptGMValueChangeCallback<T>
176+
callback: VMScriptGMValueChangeCallback<T>,
140177
): string;
141178
/** Removes a change listener by its ID. */
142179
declare function GM_removeValueChangeListener(listenerId: string): void;
143180

144181
/** Retrieves a text resource from the *Metadata Block*. */
145182
declare function GM_getResourceText(
146183
/** Name of a resource defined in the *Metadata Block*. */
147-
name: string
184+
name: string,
148185
): string;
149186
/**
150187
* Retrieves a `blob:` or `data:` URL of a resource from the *Metadata Block*.
@@ -158,7 +195,7 @@ declare function GM_getResourceURL(
158195
* - If `true`, returns a `blob:` URL. It's short and cacheable, so it's good for reusing in multiple DOM elements.
159196
* - 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.
160197
*/
161-
isBlobUrl?: boolean
198+
isBlobUrl?: boolean,
162199
): string;
163200

164201
/**
@@ -182,7 +219,7 @@ declare function GM_addElement(
182219
/** 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. */
183220
tagName: string,
184221
/** 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. */
185-
attributes?: Record<string, string>
222+
attributes?: Record<string, string>,
186223
): HTMLElement;
187224
declare function GM_addElement(
188225
/**
@@ -198,7 +235,7 @@ declare function GM_addElement(
198235
/** 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. */
199236
tagName: string,
200237
/** 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. */
201-
attributes?: Record<string, string>
238+
attributes?: Record<string, string>,
202239
): HTMLElement;
203240

204241
/** Appends and returns a `<style>` element with the specified CSS. */
@@ -234,13 +271,13 @@ declare interface VMScriptGMTabOptions {
234271
declare function GM_openInTab(
235272
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
236273
url: string,
237-
options?: VMScriptGMTabOptions
274+
options?: VMScriptGMTabOptions,
238275
): VMScriptGMTabControl;
239276
declare function GM_openInTab(
240277
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
241278
url: string,
242279
/** 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 }`. */
243-
openInBackground?: boolean
280+
openInBackground?: boolean,
244281
): VMScriptGMTabControl;
245282

246283
/**
@@ -257,18 +294,18 @@ declare function GM_registerMenuCommand(
257294
options?: {
258295
/** Default: the `caption` parameter.
259296
* In 2.15.9-2.16.1 the default was a randomly generated string. */
260-
id?: string,
297+
id?: string;
261298
/** A hint shown in the status bar when hovering the command. */
262-
title?: string,
299+
title?: string;
263300
/** Default: `true`.
264301
* Whether to auto-close the popup after the user invoked the command. */
265-
autoClose?: boolean,
266-
}
302+
autoClose?: boolean;
303+
},
267304
): string;
268305
/** Unregisters a command which has been registered to Violentmonkey popup menu. */
269306
declare function GM_unregisterMenuCommand(
270307
/** The name of command to unregister. */
271-
caption: string
308+
caption: string,
272309
): void;
273310

274311
/**
@@ -318,7 +355,9 @@ declare interface VMScriptGMNotificationOptions {
318355
}
319356

320357
/** Shows an HTML5 desktop notification. */
321-
declare function GM_notification(options: VMScriptGMNotificationOptions): VMScriptGMNotificationControl;
358+
declare function GM_notification(
359+
options: VMScriptGMNotificationOptions,
360+
): VMScriptGMNotificationControl;
322361
declare function GM_notification(
323362
/** Main text of the notification. */
324363
text: string,
@@ -327,15 +366,15 @@ declare function GM_notification(
327366
/** URL of an image to show in the notification. */
328367
image?: string,
329368
/** Callback when the notification is clicked by user. */
330-
onclick?: () => void
369+
onclick?: () => void,
331370
): VMScriptGMNotificationControl;
332371

333372
/** Sets data to system clipboard. */
334373
declare function GM_setClipboard(
335374
/** The data to be copied to system clipboard. */
336375
data: string,
337376
/** The MIME type of data to copy. Default as `text/plain`. */
338-
type?: string
377+
type?: string,
339378
): void;
340379

341380
/**
@@ -346,7 +385,12 @@ declare interface VMScriptXHRControl {
346385
abort: () => void;
347386
}
348387

349-
declare type VMScriptResponseType = 'text' | 'json' | 'blob' | 'arraybuffer' | 'document';
388+
declare type VMScriptResponseType =
389+
| 'text'
390+
| 'json'
391+
| 'blob'
392+
| 'arraybuffer'
393+
| 'document';
350394

351395
/**
352396
* https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#properties
@@ -370,17 +414,17 @@ declare interface VMScriptResponseObject<T> {
370414
}
371415

372416
type TypedArray =
373-
| Uint8Array
374-
| Uint8ClampedArray
375-
| Uint16Array
376-
| Uint32Array
377-
| Int8Array
378-
| Int16Array
379-
| Int32Array
380-
| BigUint64Array
381-
| BigInt64Array
382-
| Float32Array
383-
| Float64Array;
417+
| Uint8Array
418+
| Uint8ClampedArray
419+
| Uint16Array
420+
| Uint32Array
421+
| Int8Array
422+
| Int16Array
423+
| Int32Array
424+
| BigUint64Array
425+
| BigInt64Array
426+
| Float32Array
427+
| Float64Array;
384428

385429
interface GMRequestBase<T> {
386430
/** URL relative to current page is also allowed. */
@@ -431,15 +475,23 @@ declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
431475
*/
432476
responseType?: VMScriptResponseType;
433477
/** Data to send with the request, usually for `POST` and `PUT` requests. */
434-
data?: string | ArrayBuffer | Blob | DataView | FormData | ReadableStream | TypedArray | URLSearchParams;
478+
data?:
479+
| string
480+
| ArrayBuffer
481+
| Blob
482+
| DataView
483+
| FormData
484+
| ReadableStream
485+
| TypedArray
486+
| URLSearchParams;
435487
/** Send the `data` string as a `blob`. This is for compatibility with Tampermonkey/Greasemonkey, where only `string` type is allowed in `data`. */
436488
binary?: boolean;
437489
}
438490

439491
/** Makes a request like XMLHttpRequest, with some special capabilities, not restricted by same-origin policy. */
440-
declare function GM_xmlhttpRequest<T = string | Blob | ArrayBuffer | Document | object>(
441-
details: VMScriptGMXHRDetails<T>
442-
): VMScriptXHRControl;
492+
declare function GM_xmlhttpRequest<
493+
T = string | Blob | ArrayBuffer | Document | object,
494+
>(details: VMScriptGMXHRDetails<T>): VMScriptXHRControl;
443495

444496
declare interface VMScriptGMDownloadOptions extends GMRequestBase<Blob> {
445497
/** The filename to save as. */
@@ -452,7 +504,7 @@ declare function GM_download(
452504
/** The URL to download. */
453505
url: string,
454506
/** The filename to save as. */
455-
name: string
507+
name: string,
456508
): void;
457509

458510
/** Aliases for GM_ methods that are not included in Greasemonkey4 API */
@@ -463,13 +515,13 @@ declare interface VMScriptGMObjectVMExtensions {
463515
/** @since VM2.19.1 */
464516
deleteValues: (names: string[]) => Promise<void>;
465517
download:
466-
((options: VMScriptGMDownloadOptions) => (Promise<Blob> | void)) |
467-
((url: string, name: string) => (Promise<Blob> | void));
518+
| ((options: VMScriptGMDownloadOptions) => Promise<Blob> | void)
519+
| ((url: string, name: string) => Promise<Blob> | void);
468520
getResourceText: typeof GM_getResourceText;
469521
/** @since VM2.19.1 */
470522
getValues:
471-
((names: string[]) => Promise<GenericObject>) |
472-
((namesWithDefaults: GenericObject) => Promise<GenericObject>);
523+
| ((names: string[]) => Promise<GenericObject>)
524+
| ((namesWithDefaults: GenericObject) => Promise<GenericObject>);
473525
log: typeof GM_log;
474526
removeValueChangeListener: typeof GM_removeValueChangeListener;
475527
/** @since VM2.19.1 */
@@ -491,8 +543,8 @@ declare interface VMScriptGMObject extends VMScriptGMObjectVMExtensions {
491543
openInTab: typeof GM_openInTab;
492544
setClipboard: typeof GM_setClipboard;
493545
xmlHttpRequest: <T = string | Blob | ArrayBuffer | Document | object>(
494-
details: VMScriptGMXHRDetails<T>
495-
) => (Promise<T> & VMScriptXHRControl);
546+
details: VMScriptGMXHRDetails<T>,
547+
) => Promise<T> & VMScriptXHRControl;
496548
}
497549

498550
declare const GM: VMScriptGMObject;

0 commit comments

Comments
 (0)