forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
greasemonkey.d.ts
235 lines (209 loc) · 7.41 KB
/
greasemonkey.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Type definitions for Greasemonkey
// Project: http://www.greasespot.net/
// Definitions by: Kota Saito <https://github.com/kotas>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// This definition is based on the API reference of Greasemonkey.
// http://wiki.greasespot.net/Greasemonkey_Manual:API
////////////////
// Global variable
////////////////
/**
* Window object of the content page where the user script is running on.
* @see {@link http://wiki.greasespot.net/UnsafeWindow}
*/
declare var unsafeWindow: Window;
/**
* Meta data about the running user script.
* @see {@link http://wiki.greasespot.net/GM_info}
*/
declare var GM_info: {
script: {
description: string;
excludes: string[];
includes: string[];
matches: string[];
name: string;
namespace: string;
resources: Object;
"run-at": string;
unwrap: boolean;
version: string;
};
scriptMetaStr: string;
scriptWillUpdate: boolean;
version: string;
};
////////////////
// Values
////////////////
/**
* Deletes an existing name / value pair from the script storage.
* @param name a name of the pair to delete.
* @see {@link http://wiki.greasespot.net/GM_deleteValue}
*/
declare function GM_deleteValue(name: string): void;
/**
* Retrieves a value from the script storage.
* @param name a name to retrieve.
* @param defaultValue a value to be returned when the name does not exist.
* @returns a retrieved value, or passed default value, or undefined.
* @see {@link http://wiki.greasespot.net/GM_getValue}
*/
declare function GM_getValue(name: string, defaultValue?: any): any;
declare function GM_getValue(name: string, defaultValue?: string): string;
declare function GM_getValue(name: string, defaultValue?: number): number;
declare function GM_getValue(name: string, defaultValue?: boolean): boolean;
/**
* Retrieves an array of names stored in the script storage.
* @returns an array of names in the storage.
* @see {@link http://wiki.greasespot.net/GM_listValues}
*/
declare function GM_listValues(): string[];
/**
* Stores a name / value pair to the script storage.
* @param name a name of the pair.
* @param value a value to be stored.
* @see {@link http://wiki.greasespot.net/GM_setValue}
*/
declare function GM_setValue(name: string, value: string): void;
declare function GM_setValue(name: string, value: boolean): void;
declare function GM_setValue(name: string, value: number): void;
////////////////
// Resources
////////////////
/**
* Gets a content of a resouce defined by {@link http://wiki.greasespot.net/Metadata_Block#.40resource|@resource}.
* @param resourceName a name of the resource to get.
* @returns the content of the resource.
* @see {@link http://wiki.greasespot.net/GM_getResourceText}
*/
declare function GM_getResourceText(resourceName: string): string;
/**
* Gets a URL of a resource defined by {@link http://wiki.greasespot.net/Metadata_Block#.40resource|@resource}.
* @param resourceName a name of the resource.
* @returns a URL that returns the content of the resource.
* @see {@link http://wiki.greasespot.net/GM_getResourceURL}
*/
declare function GM_getResourceURL(resourceName: string): string;
////////////////
// Utilities
////////////////
/**
* Adds CSS to the content page.
* @param css a CSS string. It can have multiple style definitions.
* @see {@link http://wiki.greasespot.net/GM_addStyle}
*/
declare function GM_addStyle(css: string): void;
/**
* Writes a message as a log to the console with the script identifier.
* @param message a message to be written.
* @see {@link http://wiki.greasespot.net/GM_log}
*/
declare function GM_log(message: any): void;
/**
* Opens a URL in a new tab.
* @param url a URL to open.
* @returns window object of the opened tab.
* @see {@link http://wiki.greasespot.net/GM_openInTab}
*/
declare function GM_openInTab(url: string): Window;
/**
* Registers an item as a submenu of User Script Commands.
* @param caption a caption of the menu item.
* @param commandFunc a function to be invoked when the item has been selected.
* @param accessKey a single character that can be used to select the item by keyboard.
* It should be a letter in the caption.
* @see {@link http://wiki.greasespot.net/GM_registerMenuCommand}
*/
declare function GM_registerMenuCommand(caption: string, commandFunc: Function, accessKey?: string): void;
/**
* Sets a text to the clipboard of the opeating system.
* @param text a text to be set to the clipboard.
* @see {@link http://wiki.greasespot.net/GM_setClipboard}
*/
declare function GM_setClipboard(text: string): void;
////////////////
// XMLHttpRequest
////////////////
/**
* Request options for {@link GM_xmlhttpRequest}.
* @see {@link http://wiki.greasespot.net/GM_xmlhttpRequest#Arguments}
*/
interface GMXMLHttpRequestOptions {
binary?: boolean;
context?: any;
data?: string;
headers?: Object;
method: string;
onabort?: (response: GMXMLHttpRequestResponse) => any;
onerror?: (response: GMXMLHttpRequestResponse) => any;
onload?: (response: GMXMLHttpRequestResponse) => any;
onprogress?: (response: GMXMLHttpRequestProgressResponse) => any;
onreadystatechange?: (response: GMXMLHttpRequestResponse) => any;
ontimeout?: (response: GMXMLHttpRequestResponse) => any;
overrideMimeType?: string;
password?: string;
synchronous?: boolean;
timeout?: number;
upload?: {
onabort?: (response: GMXMLHttpRequestResponse) => any;
onerror?: (response: GMXMLHttpRequestResponse) => any;
onload?: (response: GMXMLHttpRequestResponse) => any;
onprogress?: (response: GMXMLHttpRequestProgressResponse) => any;
};
url: string;
user?: string;
}
/**
* Response object for general events of {@link GM_xmlhttpRequest}.
* @see {@link http://wiki.greasespot.net/GM_xmlhttpRequest#Response_Object}
*/
interface GMXMLHttpRequestResponse {
readyState: number;
responseHeaders: string;
responseText: string;
status: number;
statusText: string;
context: any;
finalUrl: string;
}
/**
* Response object for onprogress event of {@link GM_xmlhttpRequest}.
*/
interface GMXMLHttpRequestProgressResponse extends GMXMLHttpRequestResponse {
lengthComputable: boolean;
loaded: number;
total: number;
}
/**
* Returned object by {@link GM_xmlhttpRequest} in asynchronous mode.
*/
interface GMXMLHttpRequestAsyncResult {
abort(): void;
}
/**
* Returned object by {@link GM_xmlhttpRequest} in synchronouse mode.
*/
interface GMXMLHttpRequestSyncResult {
abort(): void;
finalUrl: string;
readyState: number;
responseHeaders: string;
responseText: string;
status: number;
statusText: string;
}
/**
* Returned object by {@link GM_xmlhttpRequest}.
* @see {@link http://wiki.greasespot.net/GM_xmlhttpRequest#Returns}
*/
interface GMXMLHttpRequestResult extends GMXMLHttpRequestAsyncResult, GMXMLHttpRequestSyncResult {
}
/**
* Sends a HTTP request to a URL.
* @param options options and callbacks for HTTP request.
* @returns an object which can abort the request.
* If the request is sent in the synchronous mode, it also contains the response information.
* @see {@link http://wiki.greasespot.net/GM_setClipboard}
*/
declare function GM_xmlhttpRequest(options: GMXMLHttpRequestOptions): GMXMLHttpRequestResult;