forked from jae-jae/Userscript-Plus
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathUserJS.d.ts
More file actions
323 lines (291 loc) · 10.3 KB
/
Copy pathUserJS.d.ts
File metadata and controls
323 lines (291 loc) · 10.3 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// import GM from '@types/greasemonkey';
// import '@types/tampermonkey';
import '@violentmonkey/types';
/**
* Some sites will alter or remove document functions
* To get around this we bind them to the `userjs` object
*
* This method is based on uBlock Origin `scriptlets.js` file
*
* [Source Code](https://github.com/gorhill/uBlock/blob/master/assets/resources/scriptlets.js)
*/
export declare function safeSelf(): {
XMLHttpRequest: typeof XMLHttpRequest;
createElement: typeof document.createElement;
createElementNS: typeof document.createElementNS;
createTextNode: typeof document.createTextNode;
setTimeout: typeof setTimeout;
clearTimeout: typeof clearTimeout;
};
export declare function hasOwn(obj: object, prop: string): boolean;
export declare function objToStr<O>(obj: O): string;
export declare function strToURL<S extends string | URL>(str: S): URL;
/**
* Object is typeof `RegExp`
*/
export declare function isRegExp<O>(obj: O): boolean;
/**
* Object is typeof `Element`
*/
export declare function isElem<O>(obj: O): boolean;
/**
* Object is typeof `object` / JSON Object
*/
export declare function isObj<O>(obj: O): boolean;
/**
* Object is typeof `Function`
*/
export declare function isFN<O>(obj: O): boolean;
/**
* Object is `null` or `undefined`
*/
export declare function isNull<O>(obj: O): boolean;
/**
* Object is Blank
*/
export declare function isBlank<O>(obj: O): boolean;
/**
* Object is Empty
*/
export declare function isEmpty<O>(obj: O): boolean;
/**
* Type is not 100% accurate
*/
export declare function normalizeTarget<T>(
target: T,
toQuery: boolean,
root: Element | Document
): T[];
export declare function halt(evt: Event): void;
interface UserJSTagNameMap extends HTMLElementTagNameMap {
'count-frame': HTMLElement;
'mu-js': HTMLElement;
'mu-jsbtn': HTMLElement; // wtf y did I do this to myself
'mujs-a': HTMLElement;
'mujs-addtab': HTMLElement;
'mujs-body': HTMLElement;
'mujs-btn': HTMLElement; // wtf y did I do this to myself
'mujs-column': HTMLElement;
'mujs-elem': HTMLElement;
'mujs-header': HTMLElement;
'mujs-host': HTMLElement;
'mujs-main': HTMLElement;
'mujs-root': HTMLElement;
'mujs-row': HTMLElement;
'mujs-section': HTMLElement;
'mujs-tabs': HTMLElement;
'mujs-tab': HTMLElement;
'mujs-toolbar': HTMLElement;
'mujs-url': HTMLElement;
}
/**
* Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
*
* The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
*
* When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
*
* When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
*
* When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
*
* If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
*
* The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
*/
export declare function ael<E extends HTMLElement, K extends keyof HTMLElementEventMap>(
el: E,
type: K,
listener: (this: E, ev: HTMLElementEventMap[K]) => any,
options?: AddEventListenerOptions | boolean
): void;
/**
* Returns the first element that is a descendant of node that matches selectors.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/querySelector)
*/
export declare function qs<E extends HTMLElement, S extends string>(selector: S, root: E): E | null;
// ReturnType<E['querySelector']>;
// export declare function qs<E extends HTMLElement, S extends string>(selector: S, root: E): E | null;
/**
* Returns all element descendants of node that match selectors.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/querySelectorAll)
*/
export declare function qsA<E extends HTMLElement, S extends string>(
selectors: S,
root: E
): ReturnType<E['querySelectorAll']>;
// export declare function qsA<E extends HTMLElement, S extends string>(selectors: S, root: E): NodeListOf<E>;
/**
* Set attributes for an element.
*/
export declare function formAttrs<E extends HTMLElement>(elem: E, attr: keyof E): E;
/**
* Creates an instance of the element for the specified tag.
* @param tagName The name of an element.
* @param cname A className for the element.
* @param attrs Set attributes for the element.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createElement)
*/
// T[keyof T]
export declare function make<K extends keyof UserJSTagNameMap, A extends keyof UserJSTagNameMap[K]>(
tagName: K,
cname?: string,
attrs?: {
[key in A]: unknown;
}
): UserJSTagNameMap[K];
export declare function loadCSS(css: string, name: string): HTMLStyleElement | undefined;
export declare function observe<E extends Node>(
element: E,
listener: MutationCallback,
options: MutationObserverInit
): MutationObserver;
/**
* Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method.
* @param url Specifies a MIME type for the document.
*
* [Violentmonkey Reference](https://violentmonkey.github.io/api/gm/#gm_openintab)
*
* [Greasespot Reference](https://wiki.greasespot.net/GM.openInTab)
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/open)
*/
export declare function openTab(url: string | URL): WindowProxy | null;
/**
* Get information about the current userscript.
*
* [ViolentMonkey Reference](https://violentmonkey.github.io/api/gm/#gm_info)
*/
export declare function getGMInfo(): typeof GM_info;
export interface StorageSystem {
/**
* Alias of `window.localStorage.getItem`
*/
getItem<K extends string>(key: K): string | null;
has<K extends string>(key: K): boolean;
/**
* Alias of `window.localStorage.setItem`
*/
setItem<K extends string, V extends string>(key: K, value: V): void;
/**
* Alias of `window.localStorage.removeItem`
*/
remove<K extends string>(key: K): void;
/**
* Set value - Saves key to either GM managed storage or `window.localStorage`
*
* [ViolentMonkey Reference](https://violentmonkey.github.io/api/gm/#gm_setvalue)
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API)
*/
setValue<K extends string, V>(key: K, v: V): Promise<void>;
/**
* Get value
*
* [ViolentMonkey Reference](https://violentmonkey.github.io/api/gm/#gm_getvalue)
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API)
*/
getValue<K extends string, D>(key: K, def?: D): Promise<D>;
}
export interface Network {
/**
* Fetch a URL with fetch API as fallback
*
* When GM is supported, makes a request like XMLHttpRequest, with some special capabilities, not restricted by same-origin policy
*
* [ViolentMonkey Reference](https://violentmonkey.github.io/api/gm/#gm_xmlhttprequest)
*
* [XMLHttpRequest MDN Reference](https://developer.mozilla.org/docs/Web/API/XMLHttpRequest)
*
* [Fetch MDN Reference](https://developer.mozilla.org/docs/Web/API/Fetch_API)
*/
req<T = string | Blob | ArrayBuffer | Document | object | Response>(
url: RequestInfo | URL,
method: Request['method'],
responseType: VMScriptResponseType,
data: VMScriptGMXHRDetails<T> | RequestInit,
useFetch: boolean
): Promise<T>;
format(bytes: number, decimals: number): string;
xmlRequest<T = string | Blob | ArrayBuffer | Document | object | Response>(
details: VMScriptGMXHRDetails<T> | RequestInit
): Promise<T | typeof GM_xmlhttpRequest<T>>;
bscStr<S extends string>(str: S, lowerCase: boolean): S;
}
/**
* Based on uBlock Origin by Raymond Hill (https://github.com/gorhill/uBlock)
*
* [uBlock Origin Reference](https://github.com/gorhill/uBlock/blob/master/src/js/dom.js)
*/
export interface dom {
attr<T extends HTMLElement, A extends string, V extends unknown>(
target: T,
attr: A,
value?: V
): V extends ReturnType<T['getAttribute']> ? V : void;
prop<T extends HTMLElement, P extends keyof T, V extends T[keyof T]>(
target: T,
prop: P,
value?: V
): V | undefined;
text<T extends HTMLElement, V extends unknown>(target: T, text?: V): string | null | undefined;
cl: {
add<T extends HTMLElement>(target: T, token: string | string[]): void;
remove<T extends HTMLElement>(target: T, token: string | string[]): void;
toggle<T extends HTMLElement>(target: T, token: string | string[], force?: boolean): boolean;
has<T extends HTMLElement>(target: T, token: string | string[]): boolean;
};
}
export type GSForkQuery = {
id: number;
created_at: string;
daily_installs: number;
total_installs: number;
code_updated_at: string;
support_url: string;
fan_score: string;
namespace: string;
contribution_url: any;
contribution_amount: any;
good_ratings: number;
ok_ratings: number;
bad_ratings: number;
users: {
id: number;
name: string;
url: string;
}[];
name: string;
description: string;
url: string;
code_url: string;
license: string;
version: string;
locale: string;
deleted: boolean;
};
export type GSFork = {
model: 'Script';
term: string;
options: {
fields: string[];
boost_by: string[];
where: {
script_type: number;
locale: number;
site_application_id: number;
available_as_js: boolean;
};
order: { daily_installs: string; };
page: number;
per_page: number;
includes: string[];
};
query: GSForkQuery[];
};