@@ -17,15 +17,36 @@ declare interface VMScriptGMInfoPlatform {
1717 os : 'mac' | 'win' | 'android' | 'cros' | 'linux' | 'openbsd' | 'fuchsia'
1818}
1919
20+ /**
21+ * GM_info.script and GM.info.script
22+ * Non-optional string property will be an empty string '' if omitted.
23+ */
2024declare interface VMScriptGMInfoScriptMeta {
25+ antifeature ?: string [ ]
26+ author ?: string
27+ compatible ?: string [ ]
28+ connect ?: string [ ]
2129 description : string
30+ downloadURL ?: string
31+ excludeMatches : string [ ]
2232 excludes : string [ ]
33+ /** Empty is the same as `@grant none` */
34+ grant : string [ ]
35+ /** Use homepageURL instead */
36+ homepage ?: string
37+ homepageURL ?: string
38+ icon ?: string
2339 includes : string [ ]
2440 matches : string [ ]
2541 name : string
2642 namespace : string
27- resources : Array < { name : string ; url : string } >
28- runAt : VMScriptRunAt
43+ noframes ?: boolean
44+ require : string [ ]
45+ resources : { name : string ; url : string } [ ]
46+ runAt : VMScriptRunAt | ''
47+ supportURL ?: string
48+ unwrap ?: boolean
49+ updateURL ?: string
2950 version : string
3051}
3152
@@ -58,6 +79,9 @@ declare interface VMScriptGMInfoObject {
5879 */
5980declare const GM_info : VMScriptGMInfoObject
6081
82+ /** The original console.log */
83+ declare function GM_log ( ...args : any ) : void
84+
6185/** Retrieves a value for current script from storage. */
6286declare function GM_getValue < T > ( name : string , defaultValue ?: T ) : T
6387/** Sets a key / value pair for current script to storage. */
@@ -196,7 +220,7 @@ declare function GM_registerMenuCommand(
196220 /** The name to show in the popup menu. */
197221 caption : string ,
198222 /** Callback function when the command is clicked in the menu. */
199- onClick : ( event : MouseEvent ) => void
223+ onClick : ( event : MouseEvent | KeyboardEvent ) => void
200224) : string
201225/** Unregisters a command which has been registered to Violentmonkey popup menu. */
202226declare function GM_unregisterMenuCommand (
@@ -264,30 +288,47 @@ declare type VMScriptResponseType =
264288 | 'arraybuffer'
265289 | 'document'
266290
291+ /**
292+ * https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#properties
293+ * https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent#properties
294+ */
267295declare interface VMScriptResponseObject < T > {
268296 status : number
269297 statusText : string
270298 readyState : number
271299 responseHeaders : string
272- response : T
273- responseText : string | null
300+ response : T | null
301+ responseText : string | undefined
302+ responseXML : Document | null
274303 /** The final URL after redirection. */
275304 finalUrl : string
305+ lengthComputable ?: boolean
306+ loaded ?: number
307+ total ?: number
276308 /** The same `context` object you specified in `details`. */
277309 context ?: unknown
278310}
279311
280- declare interface VMScriptGMXHRDetails < T > {
312+ type TypedArray =
313+ | Uint8Array
314+ | Uint8ClampedArray
315+ | Uint16Array
316+ | Uint32Array
317+ | Int8Array
318+ | Int16Array
319+ | Int32Array
320+ | BigUint64Array
321+ | BigInt64Array
322+ | Float32Array
323+ | Float64Array
324+
325+ interface GMRequestBase < T > {
281326 /** URL relative to current page is also allowed. */
282327 url : string
283- /** HTTP method, default as `GET`. */
284- method ?: string
285328 /** User for authentication. */
286329 user ?: string
287330 /** Password for authentication. */
288331 password ?: string
289- /** A MIME type to specify with the request. */
290- overrideMimeType ?: string
291332 /**
292333 * Some special headers are also allowed:
293334 *
@@ -298,22 +339,8 @@ declare interface VMScriptGMXHRDetails<T> {
298339 * - `User-Agent`
299340 */
300341 headers ?: Record < string , string >
301- /**
302- * One of the following:
303- *
304- * - `text` (default value)
305- * - `json`
306- * - `blob`
307- * - `arraybuffer`
308- * - `document`
309- */
310- responseType ?: VMScriptResponseType
311342 /** Time to wait for the request, none by default. */
312343 timeout ?: number
313- /** Data to send with the request, usually for `POST` and `PUT` requests. */
314- data ?: string | FormData | Blob
315- /** Send the `data` string as a `blob`. This is for compatibility with Tampermonkey/Greasemonkey, where only `string` type is allowed in `data`. */
316- binary ?: boolean
317344 /** Can be an object and will be assigned to context of the response object. */
318345 context ?: unknown
319346 /** When set to `true`, no cookie will be sent with the request and the response cookies will be ignored. The default value is `false`. */
@@ -328,23 +355,43 @@ declare interface VMScriptGMXHRDetails<T> {
328355 ontimeout ?: ( resp : VMScriptResponseObject < T > ) => void
329356}
330357
358+ declare interface VMScriptGMXHRDetails < T > extends GMRequestBase < T > {
359+ /** HTTP method, default as `GET`. */
360+ method ?: string
361+ /** A MIME type to specify with the request. */
362+ overrideMimeType ?: string
363+ /**
364+ * One of the following:
365+ *
366+ * - `text` (default value)
367+ * - `json`
368+ * - `blob`
369+ * - `arraybuffer`
370+ * - `document`
371+ */
372+ responseType ?: VMScriptResponseType
373+ /** Data to send with the request, usually for `POST` and `PUT` requests. */
374+ data ?:
375+ | string
376+ | ArrayBuffer
377+ | Blob
378+ | DataView
379+ | FormData
380+ | ReadableStream
381+ | TypedArray
382+ | URLSearchParams
383+ /** 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
385+ }
386+
331387/** Makes a request like XMLHttpRequest, with some special capabilities, not restricted by same-origin policy. */
332- declare function GM_xmlhttpRequest < T > (
333- details : VMScriptGMXHRDetails < T >
334- ) : VMScriptXHRControl
388+ declare function GM_xmlhttpRequest <
389+ T = string | Blob | ArrayBuffer | Document | object
390+ > ( details : VMScriptGMXHRDetails < T > ) : VMScriptXHRControl
335391
336- declare interface VMScriptGMDownloadOptions {
337- /** The URL to download. */
338- url : string
392+ declare interface VMScriptGMDownloadOptions extends GMRequestBase < Blob > {
339393 /** The filename to save as. */
340- name ?: string
341- /** The function to call when download starts successfully. */
342- onload ?: ( ) => void
343- headers ?: Record < string , string >
344- timeout ?: number
345- onerror ?: ( resp : VMScriptResponseObject < Blob > ) => void
346- onprogress ?: ( resp : VMScriptResponseObject < Blob > ) => void
347- ontimeout ?: ( resp : VMScriptResponseObject < Blob > ) => void
394+ name : string
348395}
349396
350397/** Downloads a URL to a local file. */
@@ -353,18 +400,29 @@ declare function GM_download(
353400 /** The URL to download. */
354401 url : string ,
355402 /** The filename to save as. */
356- name ? : string
403+ name : string
357404) : void
358405
359- declare interface VMScriptGMObject {
406+ /** Aliases for GM_ methods that are not included in Greasemonkey4 API */
407+ declare interface VMScriptGMObjectVMExtensions {
408+ addElement : typeof GM_addElement
409+ addStyle : typeof GM_addStyle
410+ addValueChangeListener : typeof GM_addValueChangeListener
411+ download : typeof GM_download
412+ getResourceText : typeof GM_getResourceText
413+ log : typeof GM_log
414+ removeValueChangeListener : typeof GM_removeValueChangeListener
415+ unregisterMenuCommand : typeof GM_unregisterMenuCommand
416+ }
417+
418+ /** The Greasemonkey4 API, https://wiki.greasespot.net/Greasemonkey_Manual:API */
419+ declare interface VMScriptGMObject extends VMScriptGMObjectVMExtensions {
360420 unsafeWindow : Window
361421 info : typeof GM_info
362422 getValue : < T > ( name : string , defaultValue ?: T ) => Promise < T >
363423 setValue : < T > ( name : string , value : T ) => Promise < void >
364424 deleteValue : ( name : string ) => Promise < void >
365425 listValues : ( ) => Promise < string [ ] >
366- addStyle : typeof GM_addStyle
367- addElement : typeof GM_addElement
368426 registerMenuCommand : typeof GM_registerMenuCommand
369427 getResourceUrl : ( name : string , isBlobUrl ?: boolean ) => Promise < string >
370428 notification : typeof GM_notification
0 commit comments