@whitesev/utils 2.2.8 → 2.3.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,1747 +1,1752 @@
1
- import { ColorConversion } from "./ColorConversion";
2
- import { GBKEncoder } from "./GBKEncoder";
3
- import { UtilsGMCookie } from "./UtilsGMCookie";
4
- import { GMMenu } from "./UtilsGMMenu";
5
- import { Hooks } from "./Hooks";
6
- import { Httpx } from "./Httpx";
7
- import { indexedDB } from "./indexedDB";
8
- import { LockFunction } from "./LockFunction";
9
- import { Log } from "./Log";
10
- import { Progress } from "./Progress";
11
- import { UtilsDictionary } from "./Dictionary";
12
- import type { DOMUtils_EventType } from "./Event";
13
- import type { Vue2Object } from "./VueObject";
14
- import type { UtilsAjaxHookResult } from "./AjaxHookerType";
15
- import { type UtilsWindowApiOption } from "./WindowApi";
16
- export declare var unsafeWindow: Window & typeof globalThis;
17
- export type JSTypeMap = {
18
- string: string;
19
- number: number;
20
- boolean: boolean;
21
- object: object;
22
- symbol: symbol;
23
- bigint: bigint;
24
- undefined: undefined;
25
- null: null;
26
- };
27
- export type JSTypeNames = keyof JSTypeMap;
28
- export type ArgsType<T extends JSTypeNames[]> = {
29
- [I in keyof T]: JSTypeMap[T[I]];
30
- };
31
- export declare interface UtilsOwnObject<V extends any> {
32
- [key: string]: V | UtilsOwnObject<V>;
33
- }
34
- export declare interface AnyObject {
35
- [key: string]: any | AnyObject;
36
- toString(): string;
37
- }
38
- export declare interface Vue2Context extends Vue2Object {
39
- }
40
- declare class Utils {
41
- private windowApi;
42
- constructor(option?: UtilsWindowApiOption);
43
- /** 版本号 */
44
- version: string;
45
- /**
46
- * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
47
- * @param cssText css字符串
48
- * @returns 返回添加的CSS标签
49
- * @example
50
- * Utils.GM_addStyle("html{}");
51
- * > <style type="text/css">html{}</style>
52
- */
53
- addStyle(cssText: string): HTMLStyleElement;
54
- /**
55
- * JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
56
- * @param target 目标数据
57
- * @param source 源数据
58
- * @param isAdd 是否可以追加键,默认false
59
- * @example
60
- * Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
61
- * >
62
- * {
63
- "1": 1,
64
- "2": {
65
- "3": 4
66
- }
67
- }
68
- */
69
- assign<T1, T2 extends object, T3 extends boolean>(target: T1, source: T2, isAdd?: T3): T3 extends true ? T1 & T2 : T1;
70
- /**
71
- * 异步替换字符串
72
- * @param string 需要被替换的目标字符串
73
- * @param pattern 正则匹配模型
74
- * @param asyncFn 异步获取的函数
75
- */
76
- asyncReplaceAll(string: string, pattern: RegExp | string, asyncFn: (item: string) => Promise<string>): Promise<string>;
77
- /**
78
- * ajax劫持库,支持xhr和fetch劫持。
79
- * + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
80
- * + 作者:cxxjackie
81
- * + 版本:1.4.1
82
- * + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
83
- */
84
- ajaxHooker: () => UtilsAjaxHookResult;
85
- /**
86
- * 根据坐标点击canvas元素的内部位置
87
- * @param canvasElement 画布元素
88
- * @param clientX X坐标,默认值0
89
- * @param clientY Y坐标,默认值0
90
- * @param view 触发的事件目标
91
- */
92
- canvasClickByPosition(canvasElement: HTMLCanvasElement, clientX?: number | string, clientY?: number | string, view?: Window & typeof globalThis): void;
93
- /**
94
- * 【手机】检测点击的地方是否在该元素区域内
95
- * @param element 需要检测的元素
96
- * @returns
97
- * + true 点击在元素上
98
- * + false 未点击在元素上
99
- * @example
100
- * Utils.checkUserClickInNode(document.querySelector(".xxx"));
101
- * > false
102
- **/
103
- checkUserClickInNode(element: Element | Node | HTMLElement): boolean;
104
- /**
105
- * 复制formData数据
106
- * @param formData 需要clone的数据
107
- */
108
- cloneFormData<T extends FormData>(formData: T): T;
109
- /**
110
- * 函数重载实现
111
- * @example
112
- * let getUsers = Utils.createOverload();
113
- * getUsers.addImpl("",()=>{
114
- * console.log("无参数");
115
- * });
116
- *
117
- * getUsers.addImpl("boolean",()=>{
118
- * console.log("boolean");
119
- * });
120
- *
121
- * getUsers.addImpl("string",()=>{
122
- * console.log("string");
123
- * });
124
- *
125
- * getUsers.addImpl("number","string",()=>{
126
- * console.log("number string");
127
- * });
128
- */
129
- createOverload(): {
130
- /**
131
- * 前面的参数都是字符串,最后一个参数是函数
132
- */
133
- addImpl<T extends JSTypeNames[]>(...args: [...T, (...args: ArgsType<T>) => any]): void;
134
- };
135
- /**
136
- * 颜色转换
137
- * @returns
138
- */
139
- ColorConversion: typeof ColorConversion;
140
- /**
141
- * 深拷贝
142
- * @param obj 对象
143
- */
144
- deepClone<T extends object | undefined | null>(obj?: T): T;
145
- /**
146
- * 防抖函数
147
- * @param fn 需要触发的回调
148
- * @param delay 防抖判定时间(毫秒),默认是0ms
149
- */
150
- debounce<A extends any[], R>(fn: (...args: A) => R, delay?: number): (...args: A) => void;
151
- /**
152
- * 删除某个父元素,父元素可能在上层或上上层或上上上层...
153
- * @param element 当前元素
154
- * @param targetSelector 判断是否满足父元素,参数为当前处理的父元素,满足返回true,否则false
155
- * @returns
156
- * + true 已删除
157
- * + false 未删除
158
- * @example
159
- * Utils.deleteParentNode(document.querySelector("a"),".xxx");
160
- * > true
161
- **/
162
- deleteParentNode(element: Node | HTMLElement | Element | null, targetSelector: string): boolean;
163
- /**
164
- * 字典
165
- * @example
166
- * let dictionary = new Utils.Dictionary();
167
- * let dictionary2 = new Utils.Dictionary();
168
- * dictionary.set("test","111");
169
- * dictionary.get("test");
170
- * > '111'
171
- * dictionary.has("test");
172
- * > true
173
- * dictionary.concat(dictionary2);
174
- **/
175
- Dictionary: typeof UtilsDictionary;
176
- /**
177
- * 主动触发事件
178
- * @param element 元素
179
- * @param eventName 事件名称,可以是字符串,也可是字符串格式的列表
180
- * @param details (可选)赋予触发的Event的额外属性
181
- * + true 使用Proxy代理Event并设置获取isTrusted永远为True
182
- * + false (默认) 不对Event进行Proxy代理
183
- * @example
184
- * Utils.dispatchEvent(document.querySelector("input","input"))
185
- */
186
- dispatchEvent(element: HTMLElement | Document, eventName: DOMUtils_EventType | DOMUtils_EventType[], details?: UtilsOwnObject<any>): void;
187
- /**
188
- * 主动触发事件
189
- * @param element 元素
190
- * @param eventName 事件名称,可以是字符串,也可是字符串格式的列表
191
- * @param details (可选)赋予触发的Event的额外属性
192
- * + true 使用Proxy代理Event并设置获取isTrusted永远为True
193
- * + false (默认) 不对Event进行Proxy代理
194
- * @example
195
- * Utils.dispatchEvent(document.querySelector("input","input"))
196
- */
197
- dispatchEvent(element: HTMLElement | Document, eventName: string, details?: UtilsOwnObject<any>): void;
198
- /**
199
- * 下载base64格式的数据
200
- * @param base64Data 需要转换的base64数据
201
- * @param fileName 需要保存的文件名
202
- * @param isIFrame (可选)是否使用iframe进行下载
203
- * @example
204
- * Utils.downloadBase64("data:image/jpeg:base64/,xxxxxx");
205
- **/
206
- downloadBase64(base64Data: string, fileName: string, isIFrame?: boolean): void;
207
- /**
208
- * 选中页面中的文字,类似Ctrl+F的选中
209
- * @param str (可选)需要寻找的字符串,默认为空
210
- * @param caseSensitive(可选)默认false
211
- * + true 区分大小写
212
- * + false (默认) 不区分大小写
213
- * @returns
214
- * + true 找到
215
- * + false 未找到
216
- * + undefined 不可使用该Api
217
- * @example
218
- * Utils.findWebPageVisibleText("xxxxx");
219
- * > true
220
- **/
221
- findWebPageVisibleText(str?: string, caseSensitive?: boolean): boolean | void;
222
- /**
223
- * 定位元素上的字符串,返回一个迭代器
224
- * @param element 目标元素
225
- * @param text 需要定位的字符串
226
- * @param filter (可选)过滤器函数,返回值为true是排除该元素
227
- * @example
228
- * let textIterator = Utils.findElementsWithText(document.documentElement,"xxxx");
229
- * textIterator.next();
230
- * > {value: ?HTMLElement, done: boolean, next: Function}
231
- */
232
- findElementsWithText<T extends HTMLElement | Element | Node>(element: T, text: string, filter?: (element: T) => boolean): Generator<HTMLElement | ChildNode, void, any>;
233
- /**
234
- * 判断该元素是否可见,如果不可见,向上找它的父元素直至找到可见的元素
235
- * @param element
236
- * @example
237
- * let visibleElement = Utils.findVisibleElement(document.querySelector("a.xx"));
238
- * > <HTMLElement>
239
- */
240
- findVisibleElement(element: HTMLElement | Element | Node): HTMLElement | null;
241
- /**
242
- * 格式化byte为KB、MB、GB、TB、PB、EB、ZB、YB、BB、NB、DB
243
- * @param byteSize 字节
244
- * @param addType (可选)是否添加单位
245
- * + true (默认) 添加单位
246
- * + false 不添加单位
247
- * @returns
248
- * + {string} 当addType为true时,且保留小数点末尾2位
249
- * + {number} 当addType为false时,且保留小数点末尾2位
250
- * @example
251
- * Utils.formatByteToSize("812304");
252
- * > '793.27KB'
253
- * @example
254
- * Utils.formatByteToSize("812304",false);
255
- * > 793.27
256
- **/
257
- formatByteToSize(byteSize: number | string): number;
258
- formatByteToSize<T extends boolean>(byteSize: number | string, addType?: T): T extends true ? string : number;
259
- /**
260
- * 应用场景: 当你想要获取数组形式的元素时,它可能是其它的选择器,那么需要按照先后顺序填入参数
261
- * 第一个是优先级最高的,依次下降,如果都没有,返回空列表
262
- * 支持document.querySelectorAll、$("")、()=>{return document.querySelectorAll("")}
263
- * @param NodeList
264
- * @example
265
- * Utils.getNodeListValue(
266
- * document.querySelectorAll("div.xxx"),
267
- * document.querySelectorAll("a.xxx")
268
- * );
269
- * > [...div,div,div]
270
- * @example
271
- * Utils.getNodeListValue(divGetFunction,aGetFunction);
272
- * > [...div,div,div]
273
- */
274
- getNodeListValue(...args: (NodeList | (() => HTMLElement))[]): HTMLElement[];
275
- /**
276
- * 自动判断N个参数,获取非空的值,如果都是空,返回最后一个值
277
- */
278
- getNonNullValue(...args: any[]): any;
279
- /**
280
- * 获取格式化后的时间
281
- * @param text (可选)需要格式化的字符串或者时间戳,默认:new Date()
282
- * @param formatType (可选)格式化成的显示类型,默认:yyyy-MM-dd HH:mm:ss
283
- * + yyyy
284
- * + MM
285
- * + dd
286
- * + HH 时 (24小时制)
287
- * + hh 时 (12小时制)
288
- * + mm
289
- * + ss
290
- * @returns {string} 返回格式化后的时间
291
- * @example
292
- * Utils.formatTime("2022-08-21 23:59:00","HH:mm:ss");
293
- * > '23:59:00'
294
- * @example
295
- * Utils.formatTime(1899187424988,"HH:mm:ss");
296
- * > '15:10:13'
297
- * @example
298
- * Utils.formatTime()
299
- * > '2023-1-1 00:00:00'
300
- **/
301
- formatTime(text?: string | number | Date, formatType?: string): string;
302
- /**
303
- * 获取格式化后的时间
304
- * @param text (可选)需要格式化的字符串或者时间戳,默认:new Date()
305
- * @param formatType (可选)格式化成的显示类型,默认:yyyy-MM-dd HH:mm:ss
306
- * + yyyy
307
- * + MM
308
- * + dd
309
- * + HH 时 (24小时制)
310
- * + hh 时 (12小时制)
311
- * + mm
312
- * + ss
313
- * @returns {string} 返回格式化后的时间
314
- * @example
315
- * Utils.formatTime("2022-08-21 23:59:00","HH:mm:ss");
316
- * > '23:59:00'
317
- * @example
318
- * Utils.formatTime(1899187424988,"HH:mm:ss");
319
- * > '15:10:13'
320
- * @example
321
- * Utils.formatTime()
322
- * > '2023-1-1 00:00:00'
323
- **/
324
- formatTime(text?: string | number | Date, formatType?: "yyyy-MM-dd HH:mm:ss" | "yyyy/MM/dd HH:mm:ss" | "yyyy_MM_dd_HH_mm_ss" | "yyyy年MM月dd日 HH时mm分ss秒" | "yyyy年MM月dd日 hh:mm:ss" | "yyyy年MM月dd日 HH:mm:ss" | "yyyy-MM-dd" | "yyyyMMdd" | "HH:mm:ss" | "yyyy" | "MM" | "dd" | "HH" | "mm" | "ss"): string;
325
- /**
326
- * 字符串格式的时间转时间戳
327
- * @param text 字符串格式的时间,例如:
328
- * + 2022-11-21 00:00:00
329
- * + 00:00:00
330
- * @returns 返回时间戳
331
- * @example
332
- * Utils.formatToTimeStamp("2022-11-21 00:00:00");
333
- * > 1668960000000
334
- **/
335
- formatToTimeStamp(text: string): number;
336
- /**
337
- * gbk格式的url编码,来自https://greasyfork.org/zh-CN/scripts/427726-gbk-url-js
338
- * @example
339
- * let gbkEncoder = new Utils.GBKEncoder();
340
- * gbkEncoder.encode("测试");
341
- * > '%B2%E2%CA%D4'
342
- * gbkEncoder.decode("%B2%E2%CA%D4");
343
- * > 测试
344
- */
345
- GBKEncoder: typeof GBKEncoder;
346
- /**
347
- * 获取 transitionend 的在各个浏览器的兼容名
348
- */
349
- getTransitionEndNameList(): string[];
350
- /**
351
- * 获取 animationend 的在各个浏览器的兼容名
352
- */
353
- getAnimationEndNameList(): string[];
354
- /**
355
- * 获取NodeList或Array对象中的最后一个的值
356
- * @param targetObj
357
- * @returns
358
- * @example
359
- * Utils.getArrayLastValue(document.querySelectorAll("div"));
360
- * > div
361
- * @example
362
- * Utils.getArrayLastValue([1,2,3,4,5]);
363
- * > 5
364
- */
365
- getArrayLastValue<R extends any>(targetObj: NodeList | any[]): R;
366
- /**
367
- * 应用场景: 当想获取的元素可能是不同的选择器的时候,按顺序优先级获取
368
- * 参数类型可以是Element或者是Function
369
- * @returns 如果都没有的话,返回null
370
- * @example
371
- * // 如果a.aaa不存在的话,取a.bbb,这里假设a.aaa不存在
372
- * Utils.getArrayRealValue(document.querySelector("a.aaa"),document.querySelector("a.bbb"));
373
- * > a.bbb
374
- * @example
375
- * Utils.getArrayRealValue(()=>{return document.querySelector("a.aaa").href},()=>{document.querySelector("a.bbb").getAttribute("data-href")});
376
- * > javascript:;
377
- */
378
- getArrayRealValue(...args: (NodeList | (() => HTMLElement))[]): any;
379
- /**
380
- * 获取天数差异,如何获取某个时间与另一个时间相差的天数
381
- * @param timestamp1 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
382
- * @param timestamp2 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
383
- * @param type (可选)返回的数字的表达的类型,比如:年、月、天、时、分、秒、auto,默认天
384
- * @example
385
- * Utils.getDaysDifference(new Date().getTime());
386
- * > 0
387
- * @example
388
- * Utils.getDaysDifference(new Date().getTime(),undefined,"秒");
389
- * > 0
390
- */
391
- getDaysDifference(timestamp1?: number, timestamp2?: number, type?: "auto"): string;
392
- /**
393
- * 获取天数差异,如何获取某个时间与另一个时间相差的天数
394
- * @param timestamp1 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
395
- * @param timestamp2 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
396
- * @param type (可选)返回的数字的表达的类型,比如:年、月、天、时、分、秒、auto,默认天
397
- * @example
398
- * Utils.getDaysDifference(new Date().getTime());
399
- * > 0
400
- * @example
401
- * Utils.getDaysDifference(new Date().getTime(),undefined,"秒");
402
- * > 0
403
- */
404
- getDaysDifference(timestamp1?: number, timestamp2?: number, type?: "年" | "月" | "天" | "时" | "分" | "秒"): number;
405
- /**
406
- * 获取元素的选择器字符串
407
- * @param element
408
- * @example
409
- * Utils.getElementSelector(document.querySelector("a"))
410
- * > '.....'
411
- */
412
- getElementSelector(element: HTMLElement): string;
413
- /**
414
- * 获取最大值
415
- * @example
416
- * Utils.getMaxValue(1,3,5,7,9)
417
- * > 9
418
- */
419
- getMaxValue(...args: number[]): number;
420
- /**
421
- * 获取最大值
422
- * @example
423
- * Utils.getMaxValue([1,3,5])
424
- * > 5
425
- */
426
- getMaxValue(val: number[]): number;
427
- /**
428
- * 获取最大值
429
- * @example
430
- * Utils.getMaxValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
431
- * > 456
432
- */
433
- getMaxValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
434
- /**
435
- * 获取页面中最大的z-index的元素信息
436
- * @param deviation 获取最大的z-index值的偏移,默认是+1
437
- * @example
438
- * Utils.getMaxZIndexNodeInfo();
439
- * > {
440
- * node: ...,
441
- * zIndex: 1001
442
- * }
443
- **/
444
- getMaxZIndexNodeInfo(deviation?: number): {
445
- node: Element;
446
- zIndex: number;
447
- };
448
- /**
449
- * 获取页面中最大的z-index
450
- * @param deviation 获取最大的z-index值的偏移,默认是+1
451
- * @example
452
- * Utils.getMaxZIndex();
453
- * > 1001
454
- **/
455
- getMaxZIndex(deviation?: number): number;
456
- /**
457
- * 获取最小值
458
- * @example
459
- * Utils.getMinValue(1,3,5,7,9)
460
- * > 1
461
- */
462
- getMinValue(...args: number[]): number;
463
- /**
464
- * 获取最小值
465
- * @example
466
- * Utils.getMinValue([1,3,5])
467
- * > 1
468
- */
469
- getMinValue(val: number[]): number;
470
- /**
471
- * 获取最小值
472
- * @example
473
- * Utils.getMinValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
474
- * > 123
475
- */
476
- getMinValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
477
- /**
478
- * 获取最小值
479
- * @example
480
- * Utils.getMinValue([{1:123},{2:345},{3:456}],(index,value)=>{return parseInt(index)})
481
- * > 0
482
- */
483
- getMinValue(val: UtilsOwnObject<number>[], handler: (index: number, value: any) => number): number;
484
- /**
485
- * 获取随机的安卓手机User-Agent
486
- * @example
487
- * Utils.getRandomAndroidUA();
488
- * > 'Mozilla/5.0 (Linux; Android 10; MI 13 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.3490.40 Mobile Safari/537.36'
489
- **/
490
- getRandomAndroidUA(): string;
491
- /**
492
- * 获取随机值
493
- * @example
494
- * Utils.getRandomValue(1,9,6,99)
495
- * > 6
496
- */
497
- getRandomValue<T extends any>(...args: T[]): T;
498
- /**
499
- * 获取随机值
500
- * @example
501
- * Utils.getRandomValue([1,2,3])
502
- * > 3
503
- * @example
504
- * Utils.getRandomValue({1:"结果1",2:"结果2",3:"结果3"}})
505
- * > 结果2
506
- */
507
- getRandomValue<T extends any>(val: T[] | UtilsOwnObject<T>): T;
508
- /**
509
- * 获取两个数之间随机值
510
- * @example
511
- * Utils.getRandomValue(1,9)
512
- * > 6
513
- */
514
- getRandomValue(val_1: number, val_2: number): number;
515
- /**
516
- * 获取随机值
517
- * @example
518
- * Utils.getRandomValue({1:1},{2:2})
519
- * > {1: 1}
520
- */
521
- getRandomValue<T extends any>(val_1: UtilsOwnObject<T>, val_2: UtilsOwnObject<T>): T;
522
- /**
523
- * 获取随机的电脑端User-Agent
524
- * + Mozilla/5.0:以前用于Netscape浏览器,目前大多数浏览器UA都会带有
525
- * + Windows NT 13:代表Window11系统
526
- * + Windows NT 10.0:代表Window10系统
527
- * + Windows NT 6.1:代表windows7系统
528
- * + WOW64:Windows-on-Windows 64-bit,32位的应用程序运行于此64位处理器上
529
- * + Win64:64
530
- * + AppleWebKit/537.36:浏览器内核
531
- * + KHTML:HTML排版引擎
532
- * + like Gecko:这不是Geckeo 浏览器,但是运行起来像Geckeo浏览器
533
- * + Chrome/106.0.5068.19:Chrome版本号
534
- * + Safari/537.36:宣称自己是Safari?
535
- * @returns 返回随机字符串
536
- * @example
537
- * Utils.getRandomPCUA();
538
- * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
539
- **/
540
- getRandomPCUA(): string;
541
- /**
542
- * 获取元素上的使用React框架的实例属性,目前包括reactFiber、reactProps、reactEvents、reactEventHandlers、reactInternalInstance
543
- * @param element 需要获取的目标元素
544
- * @returns
545
- * @example
546
- * Utils.getReactObj(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
547
- */
548
- getReactObj(element: HTMLElement | Element): {
549
- reactFiber?: AnyObject;
550
- reactProps?: AnyObject;
551
- reactEvents?: AnyObject;
552
- reactEventHandlers?: AnyObject;
553
- reactInternalInstance?: AnyObject;
554
- reactContainer?: AnyObject;
555
- };
556
- /**
557
- * 获取对象上的Symbol属性,如果没设置keyName,那么返回一个对象,对象是所有遍历到的Symbol对象
558
- * @param target 目标对象
559
- * @param keyName (可选)Symbol名或者Symbol对象
560
- */
561
- getSymbol(target: any, keyName?: string | symbol): any;
562
- /**
563
- * 获取文本的字符长度
564
- * @param text
565
- * @example
566
- * Utils.getTextLength("测试文本")
567
- * > 12
568
- */
569
- getTextLength(text: string): number;
570
- /**
571
- * 获取文本占据的空间大小,返回自动的单位,如12 Kb,14 K,20 MB,1 GB
572
- * @param text 目标字符串
573
- * @param addType (可选)是否添加单位
574
- * + true (默认) 自动添加单位
575
- * + false 不添加单位
576
- * @example
577
- * Utils.getTextStorageSize("测试文本");
578
- * > '12.00B'
579
- */
580
- getTextStorageSize<T extends boolean>(text: string, addType?: T): T extends true ? string : number;
581
- /**
582
- * 获取迅雷协议的Url
583
- * @param url Url链接或者其它信息
584
- */
585
- getThunderUrl(url: string): string;
586
- /**
587
- * 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
588
- * @example
589
- let GM_cookie = new Utils.GM_Cookie();
590
- GM_cookie.list({name:"xxx_cookie_xxx"},function(cookies,error){
591
- if (!error) {
592
- console.log(cookies);
593
- console.log(cookies.value);
594
- } else {
595
- console.error(error);
596
- }
597
- });
598
- GM_cookie.set({name:"xxx_cookie_test_xxx",value:"这是Cookie测试值"},function(error){
599
- if (error) {
600
- console.error(error);
601
- } else {
602
- console.log('Cookie set successfully.');
603
- }
604
- })
605
- GM_cookie.delete({name:"xxx_cookie_test_xxx"},function(error){
606
- if (error) {
607
- console.error(error);
608
- } else {
609
- console.log('Cookie set successfully.');
610
- }
611
- })
612
- **/
613
- GM_Cookie: typeof UtilsGMCookie;
614
- /**
615
- * 注册油猴菜单,要求本地存储的键名不能存在其它键名`GM_Menu_Local_Map`会冲突/覆盖
616
- * @example
617
- let GM_Menu = new Utils.GM_Menu({
618
- data: [
619
- {
620
- menu_key: "menu_key",
621
- text: "测试按钮",
622
- enable: true,
623
- accessKey: "a",
624
- autoClose: false,
625
- showText(text, enable) {
626
- return "[" + (enable ? "√" : "×") + "]" + text;
627
- },
628
- callback(data) {
629
- console.log("点击菜单,值修改为", data.enable);
630
- },
631
- },
632
- ],
633
- autoReload: false,
634
- GM_getValue,
635
- GM_setValue,
636
- GM_registerMenuCommand,
637
- GM_unregisterMenuCommand,
638
- });
639
-
640
-
641
- // 获取某个菜单项的值
642
- GM_Menu.get("menu_key");
643
- > true
644
-
645
- // 获取某个菜单项的开启/关闭后显示的文本
646
- GM_Menu.getShowTextValue("menu_key");
647
- > √测试按钮
648
-
649
- // 添加键为menu_key2的菜单项
650
- GM_Menu.add({
651
- key:"menu_key2",
652
- text: "测试按钮2",
653
- enable: false,
654
- showText(text,enable){
655
- return "[" + (enable ? "√" : "×") + "]" + text;
656
- },
657
- callback(data){
658
- console.log("点击菜单,值修改为",data.enable);
659
- }
660
- });
661
- // 使用数组的方式添加多个菜单,如menu_key3、menu_key4
662
- GM_Menu.add([
663
- {
664
- key:"menu_key3",
665
- text: "测试按钮3",
666
- enable: false,
667
- showText(text,enable){
668
- return "[" + (enable ? "√" : "×") + "]" + text;
669
- },
670
- callback(data){
671
- console.log("点击菜单,值修改为",data.enable);
672
- }
673
- },
674
- {
675
- key:"menu_key4",
676
- text: "测试按钮4",
677
- enable: false,
678
- showText(text,enable){
679
- return "[" + (enable ? "√" : "×") + "]" + text;
680
- },
681
- callback(data){
682
- console.log("点击菜单,值修改为",data.enable);
683
- }
684
- }
685
- ]);
686
-
687
- // 更新键为menu_key的显示文字和点击回调
688
- GM_Menu.update({
689
- menu_key:{
690
- text: "更新后的测试按钮",
691
- enable: true,
692
- showText(text,enable){
693
- return "[" + (enable ? "√" : "×") + "]" + text;
694
- },
695
- callback(data){
696
- console.log("点击菜单更新后的测试按钮,新值修改为",data.enable);
697
- }
698
- }
699
- });
700
-
701
- // 删除键为menu_key的菜单
702
- GM_Menu.delete("menu_key");
703
- **/
704
- GM_Menu: typeof GMMenu;
705
- /**
706
- * 基于Function prototype,能够勾住和释放任何函数
707
- *
708
- * .hook
709
- * + realFunc {string} 用于保存原始函数的函数名称,用于unHook
710
- * + hookFunc {string} 替换的hook函数
711
- * + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
712
- * + methodName {string} 匿名函数需显式传入目标函数名eg:this.Begin = function(){....};}
713
- *
714
- * .unhook
715
- * + realFunc {string} 用于保存原始函数的函数名称,用于unHook
716
- * + funcName {string} 被Hook的函数名称
717
- * + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
718
- * @example
719
- let hook = new Utils.Hooks();
720
- hook.initEnv();
721
- function myFunction(){
722
- console.log("我自己需要执行的函数");
723
- }
724
- function testFunction(){
725
- console.log("正常执行的函数");
726
- }
727
- testFunction.hook(testFunction,myFunction,window);
728
- **/
729
- Hooks: typeof Hooks;
730
- /**
731
- * 为减少代码量和回调,把GM_xmlhttpRequest封装
732
- * 文档地址: https://www.tampermonkey.net/documentation.php?ext=iikm
733
- * 其中onloadstart、onprogress、onreadystatechange是回调形式,onabort、ontimeout、onerror可以设置全局回调函数
734
- * @param _GM_xmlHttpRequest_ 油猴中的GM_xmlhttpRequest
735
- * @example
736
- let httpx = new Utils.Httpx(GM_xmlhttpRequest);
737
- let postResp = await httpx.post({
738
- url:url,
739
- data:JSON.stringify({
740
- test:1
741
- }),
742
- timeout: 5000
743
- });
744
- console.log(postResp);
745
- > {
746
- status: true,
747
- data: {responseText: "...", response: xxx,...},
748
- msg: "请求完毕",
749
- type: "onload",
750
- }
751
-
752
- if(postResp === "onload" && postResp.status){
753
- // onload
754
- }else if(postResp === "ontimeout"){
755
- // ontimeout
756
- }
757
- * @example
758
- // 也可以先配置全局参数
759
- let httpx = new Utils.Httpx(GM_xmlhttpRequest);
760
- httpx.config({
761
- timeout: 5000,
762
- async: false,
763
- responseType: "html",
764
- redirect: "follow",
765
- })
766
- // 优先级为 默认details < 全局details < 单独的details
767
- */
768
- Httpx: typeof Httpx;
769
- /**
770
- * 浏览器端的indexedDB操作封装
771
- * @example
772
- let db = new Utils.indexedDB('web_DB', 'nav_text')
773
- let data = {name:'管理员', roleId: 1, type: 1};
774
- db.save('list',data).then((resolve)=>{
775
- console.log(resolve,'存储成功')
776
- })
777
-
778
- db.get('list').then((resolve)=>{
779
- console.log(resolve,'查询成功')
780
- })
781
-
782
- db.getPaging('list',20,10).then((resolve)=>{
783
- console.log(resolve,'查询分页偏移第20,一共10行成功');
784
- })
785
-
786
- db.delete('list').then(resolve=>{
787
- console.log(resolve,'删除成功---->>>>>>name')
788
- })
789
-
790
- db.deleteAll().then(resolve=>{
791
- console.log(resolve,'清除数据库---->>>>>>name')
792
- })
793
- **/
794
- indexedDB: typeof indexedDB;
795
- /**
796
- * 判断目标函数是否是Native Code
797
- * @param target
798
- * @returns
799
- * + true 是Native
800
- * + false 不是Native
801
- * @example
802
- * Utils.isNativeFunc(window.location.assign)
803
- * > true
804
- */
805
- isNativeFunc(target: Function): boolean;
806
- /**
807
- * 判断当前的位置是否位于页面底部附近
808
- * @param nearValue (可选)判断在页面底部的误差值,默认:50
809
- * @returns
810
- * + true 在底部附近
811
- * + false 不在底部附近
812
- */
813
- isNearBottom(nearValue?: number): boolean;
814
- /**
815
- * 判断对象是否是元素
816
- * @param target
817
- * @returns
818
- * + true 是元素
819
- * + false 不是元素
820
- * @example
821
- * Utils.isDOM(document.querySelector("a"))
822
- * > true
823
- */
824
- isDOM(target: any): boolean;
825
- /**
826
- * 判断浏览器是否支持全屏
827
- */
828
- isFullscreenEnabled(): boolean;
829
- /**
830
- * 判断对象是否是jQuery对象
831
- * @param target
832
- * @returns
833
- * + true 是jQuery对象
834
- * + false 不是jQuery对象
835
- * @example
836
- * Utils.isJQuery($("a"))
837
- * > true
838
- */
839
- isJQuery(target: any): boolean;
840
- /**
841
- * 判断当前设备是否是移动端
842
- * @param userAgent (可选)UA字符串,默认使用当前的navigator.userAgent
843
- * @returns
844
- * + true 是移动端
845
- * + false 不是移动端
846
- * @example
847
- * Utils.isPhone();
848
- * > true
849
- **/
850
- isPhone(userAgent?: string): boolean;
851
- /**
852
- * 判断传递的字符串是否是由相同的字符组成
853
- * @param targetStr 需要判断的字符串,长度(.length)需要≥2
854
- * @param coefficient 系数(默认:1),某个字符重复的系数大于它那么就是返回true,默认全部
855
- */
856
- isSameChars(targetStr: string, coefficient?: number): boolean;
857
- /**
858
- * 判断对象是否不为空
859
- * @returns {boolean}
860
- * + true 不为空
861
- * + false 为空
862
- * @example
863
- * Utils.isNotNull("123");
864
- * > true
865
- */
866
- isNotNull<T>(value: T | null): value is T;
867
- isNotNull(...args: any[]): boolean;
868
- /**
869
- * 判断对象或数据是否为空
870
- * + `String`判空的值,如 ""、"null"、"undefined"、" "
871
- * + `Number`判空的值,如 0
872
- * + `Object`判空的值,如 {}、null、undefined
873
- * + `Array`(存在属性Symbol.iterator)判空的值,如 []
874
- * + `Boolean`判空的值,如false
875
- * + `Function`判空的值,如()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){}
876
- * @returns
877
- * + true 为空
878
- * + false 不为空
879
- * @example
880
- Utils.isNull({});
881
- > true
882
- * @example
883
- Utils.isNull([]);
884
- > true
885
- * @example
886
- Utils.isNull(" ");
887
- > true
888
- * @example
889
- Utils.isNull(function(){});
890
- > true
891
- * @example
892
- Utils.isNull(()=>{}));
893
- > true
894
- * @example
895
- Utils.isNull("undefined");
896
- > true
897
- * @example
898
- Utils.isNull("null");
899
- > true
900
- * @example
901
- Utils.isNull(" ", false);
902
- > true
903
- * @example
904
- Utils.isNull([1],[]);
905
- > false
906
- * @example
907
- Utils.isNull([],[1]);
908
- > false
909
- * @example
910
- Utils.isNull(false,[123]);
911
- > false
912
- **/
913
- isNull<T>(value: T | null): value is null;
914
- isNull(...args: any[]): boolean;
915
- /**
916
- * 判断浏览器主题是否是暗黑|深色模式
917
- */
918
- isThemeDark(): boolean;
919
- /**
920
- * 判断元素是否在页面中可见
921
- * @param element 需要检查的元素,可以是普通元素|数组形式的元素|通过querySelectorAll获取的元素数组
922
- * @param inView
923
- * + true 在窗口可视区域
924
- * + false 不在窗口可视区域
925
- * @returns
926
- * + true 可见
927
- * + false 不可见
928
- * @example
929
- * Utils.isVisible(document.documentElement)
930
- * > true
931
- */
932
- isVisible(element: HTMLElement | HTMLElement[] | Element | NodeList, inView?: boolean): boolean;
933
- /**
934
- * 判断是否是Via浏览器环境
935
- * @returns
936
- * + true 是Via
937
- * + false 不是Via
938
- * @example
939
- * Utils.isWebView_Via()
940
- * > false
941
- */
942
- isWebView_Via(): boolean;
943
- /**
944
- * 判断是否是X浏览器环境
945
- * @returns
946
- * + true 是X浏览器
947
- * + false 不是X浏览器
948
- * @example
949
- * Utils.isWebView_X()
950
- * > false
951
- */
952
- isWebView_X(): boolean;
953
- /**
954
- * 把对象内的value值全部取出成数组
955
- * @param target 目标对象
956
- * @returns 返回数组
957
- * @example
958
- * Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
959
- * > ['jsonToArray', 'Array']
960
- **/
961
- parseObjectToArray(target: AnyObject): any;
962
- /**
963
- * 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
964
- * @example
965
- let lock = new Utils.LockFunction(()=>{console.log(1)}))
966
- lock.run();
967
- > 1
968
- * @example
969
- let lock = new Utils.LockFunction(()=>{console.log(1)}),true) -- 异步操作
970
- await lock.run();
971
- > 1
972
- **/
973
- LockFunction: typeof LockFunction;
974
- /**
975
- * 日志对象
976
- * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
977
- * @example
978
- let log = new Utils.Log(GM_info);
979
- log.info("普通输出");
980
- > 普通输出
981
-
982
- log.success("成功输出");
983
- > 成功输出
984
-
985
- log.error("错误输出");
986
- > 错误输出
987
-
988
- log.warn("警告输出");
989
- > 警告输出
990
-
991
- log.tag = "自定义tag信息";
992
- log.info("自定义info的颜色","#e0e0e0");
993
- > 自定义info的颜色
994
-
995
- log.config({
996
- successColor: "#31dc02",
997
- errorColor: "#e02d2d",
998
- infoColor: "black",
999
- })
1000
- log.success("颜色为#31dc02");
1001
- > 颜色为#31dc02
1002
- */
1003
- Log: typeof Log;
1004
- /**
1005
- * 合并数组内的JSON的值字符串
1006
- * @param data 需要合并的数组
1007
- * @param handleFunc 处理的函数|JSON的key
1008
- * @example
1009
- * Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
1010
- * > '数组内数据部分字段合并成字符串->mergeToString'
1011
- **/
1012
- mergeArrayToString(data: any[], handleFunc?: (val: any) => any): string;
1013
- /**
1014
- * 监听页面元素改变并处理
1015
- * @param target 需要监听的元素,如果不存在,可以等待它出现
1016
- * @param observer_config MutationObserver的配置
1017
- * @example
1018
- Utils.mutationObserver(document.querySelector("div.xxxx"),{
1019
- "callback":(mutations, observer)=>{},
1020
- "config":{childList:true,attributes:true}
1021
- });
1022
- * @example
1023
- Utils.mutationObserver(document.querySelectorAll("div.xxxx"),{
1024
- "callback":(mutations, observer)=>{},
1025
- "config":{childList:true,attributes:true}}
1026
- );
1027
- * @example
1028
- Utils.mutationObserver($("div.xxxx"),{
1029
- "callback":(mutations, observer)=>{},
1030
- "config":{childList:true,attributes:true}}
1031
- );
1032
- **/
1033
- mutationObserver(target: HTMLElement | Node | NodeList | Document, observer_config: {
1034
- /**
1035
- * observer的配置
1036
- */
1037
- config?: MutationObserverInit;
1038
- /**
1039
- * 是否主动触发一次
1040
- */
1041
- immediate?: boolean;
1042
- /**
1043
- * 触发的回调函数
1044
- */
1045
- callback: MutationCallback;
1046
- }): MutationObserver;
1047
- /**
1048
- * 使用观察器观察元素出现在视图内,出现的话触发回调
1049
- * @param target 目标元素
1050
- * @param callback 触发的回调
1051
- * @param options 观察器配置
1052
- * @example
1053
- * Utils.mutationVisible(document.querySelector("div.xxxx"),(entries,observer)=>{
1054
- * console.log("该元素出现在视图内");
1055
- * }))
1056
- */
1057
- mutationVisible(target: Element | Element[], callback: (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void, options?: IntersectionObserverInit): void;
1058
- /**
1059
- * 去除全局window下的Utils,返回控制权
1060
- * @example
1061
- * let utils = Utils.noConflict();
1062
- * > ...
1063
- */
1064
- noConflict(): Utils;
1065
- /**
1066
- * 恢复/释放该对象内的为function,让它无效/有效
1067
- * @param needReleaseObject 需要操作的对象
1068
- * @param needReleaseName 需要操作的对象的名字
1069
- * @param functionNameList (可选)需要释放的方法,默认:全部方法
1070
- * @param release (可选)
1071
- * + true (默认) 释放该对象下的某些方法
1072
- * + false 恢复该对象下的某些方法
1073
- * @example
1074
- // 释放该方法
1075
- Utils.noConflictFunc(console,"console",["log"],true);
1076
- console.log;
1077
- > () => {}
1078
-
1079
- * @example
1080
- // 恢复该方法
1081
- Utils.noConflictFunc(console,"console",["log"],false);
1082
- console.log;
1083
- > ƒ log() { [native code] }
1084
-
1085
- * @example
1086
- // 释放所有方法
1087
- Utils.noConflictFunc(console,"console",[],true);
1088
- console.debug;
1089
- > () => {}
1090
-
1091
- * @example
1092
- // 恢复所有方法
1093
- Utils.noConflictFunc(console,"console",[],false);
1094
- console.debug;
1095
- > ƒ log() { [native code] }
1096
- **/
1097
- noConflictFunc(needReleaseObject: object, needReleaseName: string, functionNameList?: any[], release?: boolean): void;
1098
- /**
1099
- * base64转blob
1100
- * @param dataUri base64的数据
1101
- * @returns blob的链接
1102
- * @example
1103
- * Utils.parseBase64ToBlob("data:image/jpeg;base64,.....");
1104
- * > blob://xxxxxxx
1105
- **/
1106
- parseBase64ToBlob(dataUri: string): Blob;
1107
- /**
1108
- * base64转File对象
1109
- * @param dataUri base64的数据
1110
- * @param fileName (可选)文件名,默认:example
1111
- * @returns blob的链接
1112
- * @example
1113
- * Utils.parseBase64ToFile("data:image/jpeg;base64,.....","测试文件");
1114
- * > object
1115
- **/
1116
- parseBase64ToFile(dataUri: string, fileName?: string): File;
1117
- /**
1118
- * 将正则匹配到的结果取出最后一个值并转换成int格式
1119
- * @param matchList 正则匹配的列表
1120
- * @param defaultValue 正则匹配的列表为空时,或者正则匹配的列表最后一项不为Int,返回该默认值0
1121
- * @example
1122
- * Utils.parseInt(["dadaadada123124","123124"],0);
1123
- * > 123124
1124
- *
1125
- * @example
1126
- * Utils.parseInt(null,0);
1127
- * > 0
1128
- * @example
1129
- * Utils.parseInt(["aaaaaa"]);
1130
- * > 0
1131
- *
1132
- * @example
1133
- * Utils.parseInt(["aaaaaa"],"66");
1134
- * > 66
1135
- *
1136
- * @example
1137
- * Utils.parseInt(["aaaaaaa"],"aa");
1138
- * > NaN
1139
- **/
1140
- parseInt(matchList?: any[], defaultValue?: number): number;
1141
- /**
1142
- * blob转File对象
1143
- * @param blobUrl 需要转换的blob的链接
1144
- * @param fileName (可选)转换成的File对象的文件名称,默认:example
1145
- * @example
1146
- * Utils.parseBlobToFile("blob://xxxxx");
1147
- * > object
1148
- **/
1149
- parseBlobToFile(blobUrl: string, fileName?: string): Promise<File | Error>;
1150
- /**
1151
- * 解析CDATA格式的内容字符串
1152
- * @param text 传入CDATA字符串
1153
- * @returns 返回解析出的内容
1154
- * @example
1155
- * let xml = "<root><![CDATA[This is some CDATA content.]]></root>";
1156
- * console.log(Utils.parseCDATA(xml));
1157
- * > This is some CDATA content.
1158
- */
1159
- parseCDATA(text: string): string;
1160
- /**
1161
- * 【异步函数】File对象转base64
1162
- * @param fileObj 需要转换的File对象
1163
- * @example
1164
- * await Utils.parseFileToBase64(object);
1165
- * > 'data:image/jpeg:base64/,xxxxxx'
1166
- **/
1167
- parseFileToBase64(fileObj: File): Promise<string>;
1168
- /**
1169
- * 解析字符串
1170
- * @param text 要解析的 DOMString。它必须包含 HTML、xml、xhtml+xml 或 svg 文档。
1171
- * @param mimeType (可选)解析成的类型
1172
- * + (默认)text/html
1173
- * + text/xml
1174
- * + application/xml
1175
- * + application/xhtml+xml
1176
- * + image/svg+xml
1177
- * @example
1178
- * Utils.parseFromString("<p>123<p>");
1179
- * > #document
1180
- */
1181
- parseFromString(text: string, mimeType?: "text/html" | "text/xml" | "application/xml" | "application/xhtml+xml" | "image/svg+xml"): HTMLElement | XMLDocument | SVGElement;
1182
- /**
1183
- * 将字符串进行正则转义
1184
- * 例如:^替换$
1185
- * 转换:\^替换\$
1186
- */
1187
- parseStringToRegExpString(text: string): string;
1188
- /**
1189
- * 阻止事件传递
1190
- * @param element 要进行处理的元素
1191
- * @param eventNameList (可选)要阻止的事件名|列表
1192
- * @param capture (可选)是否捕获,默认false
1193
- * @example
1194
- * Utils.preventEvent(document.querySelector("a"),"click")
1195
- * @example
1196
- * Utils.preventEvent(event);
1197
- */
1198
- preventEvent(event: Event): boolean;
1199
- /**
1200
- * 阻止事件传递
1201
- * @param element 要进行处理的元素
1202
- * @param eventNameList (可选)要阻止的事件名|列表
1203
- * @param capture (可选)是否捕获,默认false
1204
- * @example
1205
- * Utils.preventEvent(document.querySelector("a"),"click")
1206
- * @example
1207
- * Utils.preventEvent(event);
1208
- */
1209
- preventEvent(element: HTMLElement, eventNameList?: string | string[], capture?: boolean): boolean;
1210
- /**
1211
- * 在canvas元素节点上绘制进度圆圈
1212
- * @example
1213
- let progress = new Utils.Process({canvasNode:document.querySelector("canvas")});
1214
- progress.draw();
1215
- * **/
1216
- Progress: typeof Progress;
1217
- /**
1218
- * 劫持Event的isTrust为true,注入时刻,ducument-start
1219
- * @param isTrustValue (可选)让isTrusted为true
1220
- * @param filter (可选)过滤出需要的事件名,true为需要,false为不需要
1221
- * @example
1222
- * Utils.registerTrustClickEvent()
1223
- */
1224
- registerTrustClickEvent(isTrustValue?: boolean, filter?: (typeName: string) => boolean): void;
1225
- /**
1226
- * 将数字进行正/负转换
1227
- * @param num 需要进行转换的数字
1228
- */
1229
- reverseNumber(num: number): number;
1230
- /**
1231
- * 将元素上的文本或元素使用光标进行选中
1232
- *
1233
- * 注意,如果设置startIndex和endIndex,且元素上并无可选则的坐标,那么会报错
1234
- * @param element 目标元素
1235
- * @param childTextNode 目标元素下的#text元素
1236
- * @param startIndex (可选)开始坐标,可为空
1237
- * @param endIndex (可选)结束坐标,可为空
1238
- */
1239
- selectElementText(element: HTMLElement | Element | Node, childTextNode?: ChildNode, startIndex?: number, endIndex?: number): void;
1240
- /**
1241
- * 复制到剪贴板
1242
- * @param data 需要复制到剪贴板的文本
1243
- * @param info (可选)默认:text/plain
1244
- * @example
1245
- * Utils.setClip({1:2});
1246
- * > {"1":2}
1247
- * @example
1248
- * Utils.setClip( ()=>{
1249
- * console.log(1)
1250
- * });
1251
- * > ()=>{console.log(1)}
1252
- * @example
1253
- * Utils.setClip("xxxx");
1254
- * > xxxx
1255
- * @example
1256
- * Utils.setClip("xxxx","html");
1257
- * > xxxx
1258
- * @example
1259
- * Utils.setClip("xxxx","text/plain");
1260
- * > xxxx
1261
- **/
1262
- setClip(data: any, info?: {
1263
- type: string;
1264
- mimetype: string;
1265
- } | string): Promise<boolean>;
1266
- /**
1267
- * 【异步函数】等待N秒执行函数
1268
- * @param callback 待执行的函数(字符串)
1269
- * @param delayTime (可选)延时时间(ms),默认:0
1270
- * @example
1271
- * await Utils.setTimeout(()=>{}, 2500);
1272
- * > ƒ tryCatchObj() {}
1273
- * @example
1274
- * await Utils.setTimeout("()=>{console.log(12345)}", 2500);
1275
- * > ƒ tryCatchObj() {}
1276
- **/
1277
- setTimeout(callback: (() => void) | string, delayTime?: number): Promise<any>;
1278
- /**
1279
- * 【异步函数】延迟xxx毫秒
1280
- * @param delayTime (可选)延时时间(ms),默认:0
1281
- * @example
1282
- * await Utils.sleep(2500)
1283
- **/
1284
- sleep(delayTime?: number): Promise<void>;
1285
- /**
1286
- * 向右拖动滑块
1287
- * @param selector 选择器|元素
1288
- * @param offsetX (可选)水平拖动长度,默认:window.innerWidth
1289
- * @example
1290
- * Utils.dragSlider("#xxxx");
1291
- * @example
1292
- * Utils.dragSlider("#xxxx",100);
1293
- */
1294
- dragSlider(selector: string | Element | Node, offsetX?: number): void;
1295
- /**
1296
- * 使目标元素进入全屏
1297
- * @param element (可选)目标元素,默认:document.documentElement
1298
- * @param options (可选)配置,一般不用
1299
- * @example
1300
- * Utils.enterFullScreen();
1301
- */
1302
- enterFullScreen(element: HTMLElement, options?: FullscreenOptions): void;
1303
- /**
1304
- * 使浏览器退出全屏
1305
- * @param element (可选)目标元素,默认:document.documentElement
1306
- * @example
1307
- * Utils.exitFullScreen();
1308
- */
1309
- exitFullScreen(element?: HTMLElement): Promise<void>;
1310
- /**
1311
- * 数组按照内部某个值的大小比对排序,如[{"time":"2022-1-1"},{"time":"2022-2-2"}]
1312
- * @param data 数据|获取数据的方法
1313
- * @param getPropertyValueFunc 数组内部项的某个属性的值的方法,参数为这个项
1314
- * @param sortByDesc (可选)排序方式
1315
- * + true (默认)倒序(值最大排第一个,如:6、5、4、3...)
1316
- * + false 升序(值最小排第一个,如:12、3、4...)
1317
- * @returns 返回比较排序完成的数组
1318
- * @example
1319
- * Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]})
1320
- * > [{time: '2022-2-2'},{time: '2022-1-1'}]
1321
- * @example
1322
- * Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]},false)
1323
- * > [{time: '2022-1-1'},{time: '2022-2-2'}]
1324
- **/
1325
- sortListByProperty<T extends any>(data: T[], getPropertyValueFunc: string | ((value: T) => any), sortByDesc?: boolean): T[];
1326
- /**
1327
- * 字符串转正则,用于把字符串中不规范的字符进行转义
1328
- * @param targetString 需要进行转换的字符串
1329
- * @param flags 正则标志
1330
- */
1331
- stringToRegular(targetString: string | RegExp, flags?: "g" | "i" | "m" | "u" | "y" | string): RegExp;
1332
- /**
1333
- * 字符串首字母转大写
1334
- * @param targetString 目标字符串
1335
- * @param otherStrToLowerCase (可选)剩余部分字符串转小写,默认false
1336
- */
1337
- stringTitleToUpperCase(targetString: string, otherStrToLowerCase?: boolean): string;
1338
- /**
1339
- * 判断目标字符串是否是以xxx开始
1340
- *
1341
- * 如果searchString是字符串数组,那么判断的结果则是字符串数组中的任意字符匹配到返回true
1342
- * @param target 目标字符串
1343
- * @param searchString 需要搜索的字符串
1344
- * @param position (可选)目标字符串的判断起点,要求≥0,默认为0
1345
- */
1346
- startsWith(target: string, searchString: string | RegExp | string[], position?: number): boolean;
1347
- /**
1348
- * 字符串首字母转小写
1349
- * @param targetString 目标字符串
1350
- * @param otherStrToLowerCase (可选)剩余部分字符串转大写,默认false
1351
- */
1352
- stringTitleToLowerCase(targetString: string, otherStrToUpperCase?: boolean): string;
1353
- /**
1354
- * 字符串转Object对象,类似'{"test":""}' => {"test":""}
1355
- * @param data
1356
- * @param errorCallBack (可选)错误回调
1357
- * @example
1358
- * Utils.toJSON("{123:123}")
1359
- * > {123:123}
1360
- */
1361
- toJSON<T = any>(data: string | null, errorCallBack?: (error: Error) => void): T;
1362
- /**
1363
- * 对象转为UrlSearchParams格式的字符串
1364
- * @param obj 目标对象,可以是对象组成的数组
1365
- * @param addPrefix 是否添加前缀?
1366
- * @example
1367
- * Utils.toSearchParamsStr({
1368
- * "test": 1,
1369
- * "test2": 2
1370
- * })
1371
- * > test=1&test2=2
1372
- * @example
1373
- * Utils.toSearchParamsStr([{
1374
- * "test": 1,
1375
- * "test2": 2
1376
- * },
1377
- * {
1378
- * "test3": 3
1379
- * }
1380
- * ])
1381
- * > test=1&test2=2&test3=3
1382
- */
1383
- toSearchParamsStr(obj: object | object[], addPrefix?: boolean): string;
1384
- /**
1385
- * 将UrlSearchParams格式的字符串转为对象
1386
- */
1387
- searchParamStrToObj<T extends any>(searhParamsStr?: string | null | undefined): T;
1388
- /**
1389
- * 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
1390
- * @example
1391
- * Utils.tryCatch().error().run(()=>{console.log(1)});
1392
- * > 1
1393
- * @example
1394
- * Utils.tryCatch().config({log:true}).error((error)=>{console.log(error)}).run(()=>{throw new Error('测试错误')});
1395
- * > ()=>{throw new Error('测试错误')}出现错误
1396
- */
1397
- tryCatch: (...args: any) => {
1398
- config(paramDetails: import("./TryCatch").UtilsTryCatchConfig): any;
1399
- error(handler: ((...args: any[]) => any) | string | Function): any;
1400
- run<A extends any[], R>(callback: ((...args: A) => R) | string | Function, __context__?: any): import("./TryCatch").UtilsTryCatchType;
1401
- };
1402
- /**
1403
- * 数组去重,去除重复的值
1404
- * @param uniqueArrayData 需要去重的数组
1405
- * @param compareArrayData 用来比较的数组
1406
- * @param compareFun 数组比较方法,如果值相同,去除该数据
1407
- * @returns 返回去重完毕的数组
1408
- * @example
1409
- * Utils.uniqueArray([1,2,3],[1,2],(item,item2)=>{return item===item2 ? true:false});
1410
- * > [3]
1411
- *
1412
- * @example
1413
- * Utils.uniqueArray([1,2,3],[1,2]);
1414
- * > [3]
1415
- *
1416
- * @example
1417
- * Utils.uniqueArray([{"key":1,"value":2},{"key":2}],[{"key":1}],(item,item2)=>{return item["key"] === item2["key"] ? true:false});
1418
- * > [{"key": 2}]
1419
- **/
1420
- uniqueArray<T extends any, TT extends any>(uniqueArrayData?: T[], compareArrayData?: TT[], compareFun?: (item1: T, item2: TT) => boolean): any[];
1421
- /**
1422
- * 等待函数数组全部执行完毕,注意,每个函数的顺序不是同步
1423
- * @param data 需要遍历的数组
1424
- * @param handleFunc 对该数组进行操作的函数,该函数的参数为数组格式的参数,[数组下标,数组项]
1425
- * @example
1426
- * await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
1427
- **/
1428
- waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]>;
1429
- /**
1430
- * 等待元素出现
1431
- * @param selector CSS选择器
1432
- * @param parent (可选)父元素,默认document
1433
- * @example
1434
- * Utils.waitNode("div").then( $div =>{
1435
- * console.log($div); // div => HTMLDivELement
1436
- * })
1437
- * Utils.waitNode("div",document).then( $div =>{
1438
- * console.log($div); // div => HTMLDivELement
1439
- * })
1440
- */
1441
- waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K]>;
1442
- waitNode<T extends Element>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
1443
- /**
1444
- * 等待元素出现
1445
- * @param selectorList CSS选择器数组
1446
- * @param parent (可选)父元素,默认document
1447
- * @example
1448
- * Utils.waitNode(["div"]).then( ([$div]) =>{
1449
- * console.log($div); // div => HTMLDivELement[]
1450
- * })
1451
- * Utils.waitNode(["div"],document).then( ([$div]) =>{
1452
- * console.log($div); // div => HTMLDivELement[]
1453
- * })
1454
- */
1455
- waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K][]>;
1456
- waitNode<T extends Element[]>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
1457
- /**
1458
- * 等待元素出现
1459
- * @param selector CSS选择器
1460
- * @param parent 父元素,默认document
1461
- * @param timeout 超时时间,默认0
1462
- * @example
1463
- * Utils.waitNode("div",document,1000).then( $div =>{
1464
- * console.log($div); // $div => HTMLDivELement | null
1465
- * })
1466
- */
1467
- waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1468
- waitNode<T extends Element>(selector: string, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1469
- /**
1470
- * 等待元素出现
1471
- * @param selectorList CSS选择器数组
1472
- * @param parent 父元素,默认document
1473
- * @param timeout 超时时间,默认0
1474
- * @example
1475
- * Utils.waitNode(["div"],document,1000).then( ([$div]) =>{
1476
- * console.log($div); // $div => HTMLDivELement[] | null
1477
- * })
1478
- */
1479
- waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1480
- waitNode<T extends Element[]>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1481
- /**
1482
- * 等待元素出现
1483
- * @param selector CSS选择器
1484
- * @param timeout 超时时间,默认0
1485
- * @example
1486
- * Utils.waitNode("div",1000).then( $div =>{
1487
- * console.log($div); // $div => HTMLDivELement | null
1488
- * })
1489
- */
1490
- waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1491
- waitNode<T extends Element>(selector: string, timeout: number): Promise<T | null>;
1492
- /**
1493
- * 等待元素出现
1494
- * @param selectorList CSS选择器数组
1495
- * @param timeout 超时时间,默认0
1496
- * @example
1497
- * Utils.waitNode(["div"],1000).then( [$div] =>{
1498
- * console.log($div); // $div => HTMLDivELement[] | null
1499
- * })
1500
- */
1501
- waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1502
- waitNode<T extends Element[]>(selectorList: string[], timeout: number): Promise<T | null>;
1503
- /**
1504
- * 等待任意元素出现
1505
- * @param selectorList CSS选择器数组
1506
- * @param parent (可选)监听的父元素
1507
- * @example
1508
- * Utils.waitAnyNode(["div","div"]).then( $div =>{
1509
- * console.log($div); // $div => HTMLDivELement 这里是第一个
1510
- * })
1511
- * Utils.waitAnyNode(["a","div"],document).then( $a =>{
1512
- * console.log($a); // $a => HTMLAnchorElement 这里是第一个
1513
- * })
1514
- */
1515
- waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K]>;
1516
- waitAnyNode<T extends Element>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
1517
- /**
1518
- * 等待任意元素出现
1519
- * @param selectorList CSS选择器数组
1520
- * @param parent 父元素,默认document
1521
- * @param timeout 超时时间,默认0
1522
- * @example
1523
- * Utils.waitAnyNode(["div","div"],document,10000).then( $div =>{
1524
- * console.log($div); // $div => HTMLDivELement | null
1525
- * })
1526
- */
1527
- waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1528
- waitAnyNode<T extends Element>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1529
- /**
1530
- * 等待任意元素出现
1531
- * @param selectorList CSS选择器数组
1532
- * @param timeout 超时时间,默认0
1533
- * @example
1534
- * Utils.waitAnyNode(["div","div"],10000).then( $div =>{
1535
- * console.log($div); // $div => HTMLDivELement | null
1536
- * })
1537
- */
1538
- waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1539
- waitAnyNode<T extends Element>(selectorList: string[], timeout: number): Promise<T | null>;
1540
- /**
1541
- * 等待元素数组出现
1542
- * @param selector CSS选择器
1543
- * @param parent (可选)监听的父元素
1544
- * @example
1545
- * Utils.waitNodeList("div").then( $result =>{
1546
- * console.log($result); // $result => NodeListOf<HTMLDivElement>
1547
- * })
1548
- * Utils.waitNodeList("div",document).then( $result =>{
1549
- * console.log($result); // $result => NodeListOf<HTMLDivElement>
1550
- * })
1551
- */
1552
- waitNodeList<T extends keyof HTMLElementTagNameMap>(selector: T, parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[T]>>;
1553
- waitNodeList<T extends NodeListOf<Element>>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
1554
- /**
1555
- * 等待元素数组出现
1556
- * @param selectorList CSS选择器数组
1557
- * @param parent (可选)监听的父元素
1558
- * @example
1559
- * Utils.waitNodeList(["div"]).then( $result =>{
1560
- * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1561
- * })
1562
- * Utils.waitNodeList(["div"],document).then( $result =>{
1563
- * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1564
- * })
1565
- */
1566
- waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[K]>[]>;
1567
- waitNodeList<T extends NodeListOf<Element>[]>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
1568
- /**
1569
- * 等待元素数组出现
1570
- * @param selector CSS选择器
1571
- * @param parent 监听的父元素
1572
- * @param timeout 超时时间,默认0
1573
- * @example
1574
- * Utils.waitNodeList("div",document,10000).then( $result =>{
1575
- * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1576
- * })
1577
- */
1578
- waitNodeList<T extends NodeListOf<Element>>(selector: string, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1579
- waitNodeList<K extends keyof HTMLElementTagNameMap>(selector: K, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1580
- /**
1581
- * 等待元素数组出现
1582
- * @param selectorList CSS选择器数组
1583
- * @param parent 监听的父元素
1584
- * @param timeout 超时时间,默认0
1585
- * @example
1586
- * Utils.waitNodeList(["div"],document,10000).then( $result =>{
1587
- * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1588
- * })
1589
- */
1590
- waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
1591
- waitNodeList<T extends NodeListOf<Element>[]>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1592
- /**
1593
- * 等待元素数组出现
1594
- * @param selector CSS选择器数组
1595
- * @param timeout 超时时间,默认0
1596
- * @example
1597
- * Utils.waitNodeList("div",10000).then( $result =>{
1598
- * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1599
- * })
1600
- */
1601
- waitNodeList<K extends keyof HTMLElementTagNameMap>(selector: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1602
- waitNodeList<T extends NodeListOf<Element>>(selector: string[], timeout: number): Promise<T | null>;
1603
- /**
1604
- * 等待元素数组出现
1605
- * @param selectorList CSS选择器数组
1606
- * @param timeout 超时时间,默认0
1607
- * @example
1608
- * Utils.waitNodeList(["div"],10000).then( $result =>{
1609
- * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1610
- * })
1611
- */
1612
- waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
1613
- waitNodeList<T extends NodeListOf<Element>>(selectorList: string[], timeout: number): Promise<T[] | null>;
1614
- /**
1615
- * 等待任意元素数组出现
1616
- * @param selectorList CSS选择器数组
1617
- * @param parent (可选)监听的父元素
1618
- * @example
1619
- * Utils.waitAnyNodeList(["div","a"]).then( $result =>{
1620
- * console.log($result); // $result => NodeListOf<HTMLDivElement>
1621
- * })
1622
- * Utils.waitAnyNodeList(["div","a"],document).then( $result =>{
1623
- * console.log($result); // $result => NodeListOf<HTMLDivElement>
1624
- * })
1625
- */
1626
- waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[K]>>;
1627
- waitAnyNodeList<T extends Element>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<T>>;
1628
- /**
1629
- * 等待任意元素数组出现
1630
- * @param selectorList CSS选择器数组
1631
- * @param parent 父元素,默认document
1632
- * @param timeout 超时时间,默认0
1633
- * @example
1634
- * Utils.waitAnyNodeList(["div","a"],document,10000).then( $result =>{
1635
- * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1636
- * })
1637
- */
1638
- waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1639
- waitAnyNodeList<T extends Element>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<T> | null>;
1640
- /**
1641
- * 等待任意元素出现
1642
- * @param selectorList CSS选择器数组
1643
- * @param timeout 超时时间,默认0
1644
- * @example
1645
- * Utils.waitAnyNodeList(["div","div"],10000).then( $result =>{
1646
- * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1647
- * })
1648
- */
1649
- waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1650
- waitAnyNodeList<T extends Element>(selectorList: string[], timeout: number): Promise<NodeListOf<T> | null>;
1651
- /**
1652
- * 等待对象上的属性出现
1653
- * @param checkObj 检查的对象
1654
- * @param checkPropertyName 检查的对象的属性名
1655
- * @example
1656
- * await Utils.waitProperty(window,"test");
1657
- * console.log("test success set");
1658
- *
1659
- * window.test = 1;
1660
- * > "test success set"
1661
- *
1662
- */
1663
- waitProperty<T extends any>(checkObj: AnyObject | (() => AnyObject), checkPropertyName: string): Promise<T>;
1664
- /**
1665
- * 在规定时间内等待对象上的属性出现
1666
- * @param checkObj 检查的对象
1667
- * @param checkPropertyName 检查的对象的属性名
1668
- * @param intervalTimer (可选)检查间隔时间(ms),默认250ms
1669
- * @param maxTime (可选)限制在多长时间内,默认-1(不限制时间)
1670
- * @example
1671
- * await Utils.waitPropertyByInterval(window,"test");
1672
- * console.log("test success set");
1673
- */
1674
- waitPropertyByInterval<T extends any>(checkObj: AnyObject | (() => AnyObject), checkPropertyName: string | ((obj: any) => boolean), intervalTimer?: number, maxTime?: number): Promise<T>;
1675
- /**
1676
- * 在规定时间内等待元素上的__vue__属性或者__vue__属性上的某个值出现出现
1677
- * @param element 目标元素
1678
- * @param propertyName (可选)vue上的属性名或者传递一个获取属性的方法返回boolean
1679
- * @param timer (可选)间隔时间(ms),默认:250(ms)
1680
- * @param maxTime(可选) 限制在多长时间内,默认:-1(不限制时间)
1681
- * @param vueName (可选)vue挂载的属性名,默认:__vue__
1682
- * @example
1683
- * await Utils.waitVueByInterval(
1684
- * function(){
1685
- * return document.querySelector("a.xx")
1686
- * },
1687
- * function(__vue__){
1688
- * return Boolean(__vue__.xxx == null);
1689
- * },
1690
- * 250,
1691
- * 10000,
1692
- * "__vue__"
1693
- * )
1694
- */
1695
- waitVueByInterval(element: HTMLElement | (() => any), propertyName: string | ((__vue__: any) => boolean), timer?: number, maxTime?: number, vueName?: "__vue__" | string): Promise<boolean>;
1696
- /**
1697
- * 观察对象的set、get
1698
- * @param target 观察的对象
1699
- * @param propertyName 观察的对象的属性名
1700
- * @param getCallBack (可选)触发get的回调,可以自定义返回特定值
1701
- * @param setCallBack (可选)触发set的回调,参数为将要设置的value
1702
- * @example
1703
- * Utils.watchObject(window,"test",()=>{return 111;},(value)=>{console.log("test出现,值是",value)});
1704
- *
1705
- * window.test = 1;
1706
- * > test出现,值是 1
1707
- * console.log(window.test);
1708
- * > 111;
1709
- */
1710
- watchObject(target: AnyObject, propertyName: string, getCallBack: (value: any) => void, setCallBack: (value: any) => void): void;
1711
- /**
1712
- * 创建一个新的Utils实例
1713
- * @param option
1714
- * @returns
1715
- */
1716
- createUtils(option?: UtilsWindowApiOption): Utils;
1717
- /**
1718
- * 将对象转换为FormData
1719
- * @param data 待转换的对象
1720
- * @param isEncode 是否对值为string进行编码转换(encodeURIComponent),默认false
1721
- * @param valueAutoParseToStr 是否对值强制使用JSON.stringify()转换,默认false
1722
- * @example
1723
- * Utils.toFormData({
1724
- * test: "1",
1725
- * 666: 666,
1726
- * })
1727
- */
1728
- toFormData(data: {
1729
- [key: string]: string | Blob | File | number;
1730
- }, isEncode?: boolean, valueAutoParseToStr?: boolean): FormData;
1731
- /**
1732
- * 将链接转为URL对象,自动补充URL的protocol或者origin
1733
- * @param text 需要转换的链接字符串
1734
- * @example
1735
- * Utils.toUrl("//www.baidu.com/s?word=666");
1736
- * Utils.toUrl("/s?word=666");
1737
- */
1738
- toUrl(text: string): URL;
1739
- /**
1740
- * 生成uuid
1741
- * @example
1742
- * Utils.generateUUID()
1743
- */
1744
- generateUUID: () => string;
1745
- }
1746
- declare let utils: Utils;
1747
- export { utils as Utils };
1
+ import { ColorConversion } from "./ColorConversion";
2
+ import { GBKEncoder } from "./GBKEncoder";
3
+ import { UtilsGMCookie } from "./UtilsGMCookie";
4
+ import { GMMenu } from "./UtilsGMMenu";
5
+ import { Hooks } from "./Hooks";
6
+ import { Httpx } from "./Httpx";
7
+ import { indexedDB } from "./indexedDB";
8
+ import { LockFunction } from "./LockFunction";
9
+ import { Log } from "./Log";
10
+ import { Progress } from "./Progress";
11
+ import { UtilsDictionary } from "./Dictionary";
12
+ import type { DOMUtils_EventType } from "./Event";
13
+ import type { Vue2Object } from "./VueObject";
14
+ import type { UtilsAjaxHookResult } from "./AjaxHookerType";
15
+ import { type UtilsWindowApiOption } from "./WindowApi";
16
+ import { Vue } from "./Vue";
17
+ export declare var unsafeWindow: Window & typeof globalThis;
18
+ export type JSTypeMap = {
19
+ string: string;
20
+ number: number;
21
+ boolean: boolean;
22
+ object: object;
23
+ symbol: symbol;
24
+ bigint: bigint;
25
+ undefined: undefined;
26
+ null: null;
27
+ };
28
+ export type JSTypeNames = keyof JSTypeMap;
29
+ export type ArgsType<T extends JSTypeNames[]> = {
30
+ [I in keyof T]: JSTypeMap[T[I]];
31
+ };
32
+ export declare interface UtilsOwnObject<V extends any> {
33
+ [key: string]: V | UtilsOwnObject<V>;
34
+ }
35
+ export declare interface AnyObject {
36
+ [key: string]: any | AnyObject;
37
+ toString(): string;
38
+ }
39
+ export declare interface Vue2Context extends Vue2Object {
40
+ }
41
+ declare class Utils {
42
+ private windowApi;
43
+ constructor(option?: UtilsWindowApiOption);
44
+ /** 版本号 */
45
+ version: string;
46
+ /**
47
+ * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
48
+ * @param cssText css字符串
49
+ * @returns 返回添加的CSS标签
50
+ * @example
51
+ * Utils.GM_addStyle("html{}");
52
+ * > <style type="text/css">html{}</style>
53
+ */
54
+ addStyle(cssText: string): HTMLStyleElement;
55
+ /**
56
+ * JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
57
+ * @param target 目标数据
58
+ * @param source 源数据
59
+ * @param isAdd 是否可以追加键,默认false
60
+ * @example
61
+ * Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
62
+ * >
63
+ * {
64
+ "1": 1,
65
+ "2": {
66
+ "3": 4
67
+ }
68
+ }
69
+ */
70
+ assign<T1, T2 extends object, T3 extends boolean>(target: T1, source: T2, isAdd?: T3): T3 extends true ? T1 & T2 : T1;
71
+ /**
72
+ * 异步替换字符串
73
+ * @param string 需要被替换的目标字符串
74
+ * @param pattern 正则匹配模型
75
+ * @param asyncFn 异步获取的函数
76
+ */
77
+ asyncReplaceAll(string: string, pattern: RegExp | string, asyncFn: (item: string) => Promise<string>): Promise<string>;
78
+ /**
79
+ * ajax劫持库,支持xhr和fetch劫持。
80
+ * + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
81
+ * + 作者:cxxjackie
82
+ * + 版本:1.4.1
83
+ * + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
84
+ */
85
+ ajaxHooker: () => UtilsAjaxHookResult;
86
+ /**
87
+ * 根据坐标点击canvas元素的内部位置
88
+ * @param canvasElement 画布元素
89
+ * @param clientX X坐标,默认值0
90
+ * @param clientY Y坐标,默认值0
91
+ * @param view 触发的事件目标
92
+ */
93
+ canvasClickByPosition(canvasElement: HTMLCanvasElement, clientX?: number | string, clientY?: number | string, view?: Window & typeof globalThis): void;
94
+ /**
95
+ * 【手机】检测点击的地方是否在该元素区域内
96
+ * @param element 需要检测的元素
97
+ * @returns
98
+ * + true 点击在元素上
99
+ * + false 未点击在元素上
100
+ * @example
101
+ * Utils.checkUserClickInNode(document.querySelector(".xxx"));
102
+ * > false
103
+ **/
104
+ checkUserClickInNode(element: Element | Node | HTMLElement): boolean;
105
+ /**
106
+ * 复制formData数据
107
+ * @param formData 需要clone的数据
108
+ */
109
+ cloneFormData<T extends FormData>(formData: T): T;
110
+ /**
111
+ * 函数重载实现
112
+ * @example
113
+ * let getUsers = Utils.createOverload();
114
+ * getUsers.addImpl("",()=>{
115
+ * console.log("无参数");
116
+ * });
117
+ *
118
+ * getUsers.addImpl("boolean",()=>{
119
+ * console.log("boolean");
120
+ * });
121
+ *
122
+ * getUsers.addImpl("string",()=>{
123
+ * console.log("string");
124
+ * });
125
+ *
126
+ * getUsers.addImpl("number","string",()=>{
127
+ * console.log("number string");
128
+ * });
129
+ */
130
+ createOverload(): {
131
+ /**
132
+ * 前面的参数都是字符串,最后一个参数是函数
133
+ */
134
+ addImpl<T extends JSTypeNames[]>(...args: [...T, (...args: ArgsType<T>) => any]): void;
135
+ };
136
+ /**
137
+ * 颜色转换
138
+ * @returns
139
+ */
140
+ ColorConversion: typeof ColorConversion;
141
+ /**
142
+ * 深拷贝
143
+ * @param obj 对象
144
+ */
145
+ deepClone<T extends object | undefined | null>(obj?: T): T;
146
+ /**
147
+ * 防抖函数
148
+ * @param fn 需要触发的回调
149
+ * @param delay 防抖判定时间(毫秒),默认是0ms
150
+ */
151
+ debounce<A extends any[], R>(fn: (...args: A) => R, delay?: number): (...args: A) => void;
152
+ /**
153
+ * 删除某个父元素,父元素可能在上层或上上层或上上上层...
154
+ * @param element 当前元素
155
+ * @param targetSelector 判断是否满足父元素,参数为当前处理的父元素,满足返回true,否则false
156
+ * @returns
157
+ * + true 已删除
158
+ * + false 未删除
159
+ * @example
160
+ * Utils.deleteParentNode(document.querySelector("a"),".xxx");
161
+ * > true
162
+ **/
163
+ deleteParentNode(element: Node | HTMLElement | Element | null, targetSelector: string): boolean;
164
+ /**
165
+ * 字典
166
+ * @example
167
+ * let dictionary = new Utils.Dictionary();
168
+ * let dictionary2 = new Utils.Dictionary();
169
+ * dictionary.set("test","111");
170
+ * dictionary.get("test");
171
+ * > '111'
172
+ * dictionary.has("test");
173
+ * > true
174
+ * dictionary.concat(dictionary2);
175
+ **/
176
+ Dictionary: typeof UtilsDictionary;
177
+ /**
178
+ * 主动触发事件
179
+ * @param element 元素
180
+ * @param eventName 事件名称,可以是字符串,也可是字符串格式的列表
181
+ * @param details (可选)赋予触发的Event的额外属性
182
+ * + true 使用Proxy代理Event并设置获取isTrusted永远为True
183
+ * + false (默认) 不对Event进行Proxy代理
184
+ * @example
185
+ * Utils.dispatchEvent(document.querySelector("input","input"))
186
+ */
187
+ dispatchEvent(element: HTMLElement | Document, eventName: DOMUtils_EventType | DOMUtils_EventType[], details?: UtilsOwnObject<any>): void;
188
+ /**
189
+ * 主动触发事件
190
+ * @param element 元素
191
+ * @param eventName 事件名称,可以是字符串,也可是字符串格式的列表
192
+ * @param details (可选)赋予触发的Event的额外属性
193
+ * + true 使用Proxy代理Event并设置获取isTrusted永远为True
194
+ * + false (默认) 不对Event进行Proxy代理
195
+ * @example
196
+ * Utils.dispatchEvent(document.querySelector("input","input"))
197
+ */
198
+ dispatchEvent(element: HTMLElement | Document, eventName: string, details?: UtilsOwnObject<any>): void;
199
+ /**
200
+ * 下载base64格式的数据
201
+ * @param base64Data 需要转换的base64数据
202
+ * @param fileName 需要保存的文件名
203
+ * @param isIFrame (可选)是否使用iframe进行下载
204
+ * @example
205
+ * Utils.downloadBase64("data:image/jpeg:base64/,xxxxxx");
206
+ **/
207
+ downloadBase64(base64Data: string, fileName: string, isIFrame?: boolean): void;
208
+ /**
209
+ * 选中页面中的文字,类似Ctrl+F的选中
210
+ * @param str (可选)需要寻找的字符串,默认为空
211
+ * @param caseSensitive(可选)默认false
212
+ * + true 区分大小写
213
+ * + false (默认) 不区分大小写
214
+ * @returns
215
+ * + true 找到
216
+ * + false 未找到
217
+ * + undefined 不可使用该Api
218
+ * @example
219
+ * Utils.findWebPageVisibleText("xxxxx");
220
+ * > true
221
+ **/
222
+ findWebPageVisibleText(str?: string, caseSensitive?: boolean): boolean | void;
223
+ /**
224
+ * 定位元素上的字符串,返回一个迭代器
225
+ * @param element 目标元素
226
+ * @param text 需要定位的字符串
227
+ * @param filter (可选)过滤器函数,返回值为true是排除该元素
228
+ * @example
229
+ * let textIterator = Utils.findElementsWithText(document.documentElement,"xxxx");
230
+ * textIterator.next();
231
+ * > {value: ?HTMLElement, done: boolean, next: Function}
232
+ */
233
+ findElementsWithText<T extends HTMLElement | Element | Node>(element: T, text: string, filter?: (element: T) => boolean): Generator<HTMLElement | ChildNode, void, any>;
234
+ /**
235
+ * 判断该元素是否可见,如果不可见,向上找它的父元素直至找到可见的元素
236
+ * @param element
237
+ * @example
238
+ * let visibleElement = Utils.findVisibleElement(document.querySelector("a.xx"));
239
+ * > <HTMLElement>
240
+ */
241
+ findVisibleElement(element: HTMLElement | Element | Node): HTMLElement | null;
242
+ /**
243
+ * 格式化byte为KB、MB、GB、TB、PB、EB、ZB、YB、BB、NB、DB
244
+ * @param byteSize 字节
245
+ * @param addType (可选)是否添加单位
246
+ * + true (默认) 添加单位
247
+ * + false 不添加单位
248
+ * @returns
249
+ * + {string} 当addType为true时,且保留小数点末尾2位
250
+ * + {number} 当addType为false时,且保留小数点末尾2位
251
+ * @example
252
+ * Utils.formatByteToSize("812304");
253
+ * > '793.27KB'
254
+ * @example
255
+ * Utils.formatByteToSize("812304",false);
256
+ * > 793.27
257
+ **/
258
+ formatByteToSize(byteSize: number | string): number;
259
+ formatByteToSize<T extends boolean>(byteSize: number | string, addType?: T): T extends true ? string : number;
260
+ /**
261
+ * 应用场景: 当你想要获取数组形式的元素时,它可能是其它的选择器,那么需要按照先后顺序填入参数
262
+ * 第一个是优先级最高的,依次下降,如果都没有,返回空列表
263
+ * 支持document.querySelectorAll、$("")、()=>{return document.querySelectorAll("")}
264
+ * @param NodeList
265
+ * @example
266
+ * Utils.getNodeListValue(
267
+ * document.querySelectorAll("div.xxx"),
268
+ * document.querySelectorAll("a.xxx")
269
+ * );
270
+ * > [...div,div,div]
271
+ * @example
272
+ * Utils.getNodeListValue(divGetFunction,aGetFunction);
273
+ * > [...div,div,div]
274
+ */
275
+ getNodeListValue(...args: (NodeList | (() => HTMLElement))[]): HTMLElement[];
276
+ /**
277
+ * 自动判断N个参数,获取非空的值,如果都是空,返回最后一个值
278
+ */
279
+ getNonNullValue(...args: any[]): any;
280
+ /**
281
+ * 获取格式化后的时间
282
+ * @param text (可选)需要格式化的字符串或者时间戳,默认:new Date()
283
+ * @param formatType (可选)格式化成的显示类型,默认:yyyy-MM-dd HH:mm:ss
284
+ * + yyyy
285
+ * + MM
286
+ * + dd
287
+ * + HH 时 (24小时制)
288
+ * + hh 时 (12小时制)
289
+ * + mm
290
+ * + ss 秒
291
+ * @returns {string} 返回格式化后的时间
292
+ * @example
293
+ * Utils.formatTime("2022-08-21 23:59:00","HH:mm:ss");
294
+ * > '23:59:00'
295
+ * @example
296
+ * Utils.formatTime(1899187424988,"HH:mm:ss");
297
+ * > '15:10:13'
298
+ * @example
299
+ * Utils.formatTime()
300
+ * > '2023-1-1 00:00:00'
301
+ **/
302
+ formatTime(text?: string | number | Date, formatType?: string): string;
303
+ /**
304
+ * 获取格式化后的时间
305
+ * @param text (可选)需要格式化的字符串或者时间戳,默认:new Date()
306
+ * @param formatType (可选)格式化成的显示类型,默认:yyyy-MM-dd HH:mm:ss
307
+ * + yyyy
308
+ * + MM
309
+ * + dd
310
+ * + HH 时 (24小时制)
311
+ * + hh 时 (12小时制)
312
+ * + mm
313
+ * + ss 秒
314
+ * @returns {string} 返回格式化后的时间
315
+ * @example
316
+ * Utils.formatTime("2022-08-21 23:59:00","HH:mm:ss");
317
+ * > '23:59:00'
318
+ * @example
319
+ * Utils.formatTime(1899187424988,"HH:mm:ss");
320
+ * > '15:10:13'
321
+ * @example
322
+ * Utils.formatTime()
323
+ * > '2023-1-1 00:00:00'
324
+ **/
325
+ formatTime(text?: string | number | Date, formatType?: "yyyy-MM-dd HH:mm:ss" | "yyyy/MM/dd HH:mm:ss" | "yyyy_MM_dd_HH_mm_ss" | "yyyy年MM月dd日 HH时mm分ss秒" | "yyyy年MM月dd日 hh:mm:ss" | "yyyy年MM月dd日 HH:mm:ss" | "yyyy-MM-dd" | "yyyyMMdd" | "HH:mm:ss" | "yyyy" | "MM" | "dd" | "HH" | "mm" | "ss"): string;
326
+ /**
327
+ * 字符串格式的时间转时间戳
328
+ * @param text 字符串格式的时间,例如:
329
+ * + 2022-11-21 00:00:00
330
+ * + 00:00:00
331
+ * @returns 返回时间戳
332
+ * @example
333
+ * Utils.formatToTimeStamp("2022-11-21 00:00:00");
334
+ * > 1668960000000
335
+ **/
336
+ formatToTimeStamp(text: string): number;
337
+ /**
338
+ * gbk格式的url编码,来自https://greasyfork.org/zh-CN/scripts/427726-gbk-url-js
339
+ * @example
340
+ * let gbkEncoder = new Utils.GBKEncoder();
341
+ * gbkEncoder.encode("测试");
342
+ * > '%B2%E2%CA%D4'
343
+ * gbkEncoder.decode("%B2%E2%CA%D4");
344
+ * > 测试
345
+ */
346
+ GBKEncoder: typeof GBKEncoder;
347
+ /**
348
+ * 获取 transitionend 的在各个浏览器的兼容名
349
+ */
350
+ getTransitionEndNameList(): string[];
351
+ /**
352
+ * 获取 animationend 的在各个浏览器的兼容名
353
+ */
354
+ getAnimationEndNameList(): string[];
355
+ /**
356
+ * 获取NodeList或Array对象中的最后一个的值
357
+ * @param targetObj
358
+ * @returns
359
+ * @example
360
+ * Utils.getArrayLastValue(document.querySelectorAll("div"));
361
+ * > div
362
+ * @example
363
+ * Utils.getArrayLastValue([1,2,3,4,5]);
364
+ * > 5
365
+ */
366
+ getArrayLastValue<R extends any>(targetObj: NodeList | any[]): R;
367
+ /**
368
+ * 应用场景: 当想获取的元素可能是不同的选择器的时候,按顺序优先级获取
369
+ * 参数类型可以是Element或者是Function
370
+ * @returns 如果都没有的话,返回null
371
+ * @example
372
+ * // 如果a.aaa不存在的话,取a.bbb,这里假设a.aaa不存在
373
+ * Utils.getArrayRealValue(document.querySelector("a.aaa"),document.querySelector("a.bbb"));
374
+ * > a.bbb
375
+ * @example
376
+ * Utils.getArrayRealValue(()=>{return document.querySelector("a.aaa").href},()=>{document.querySelector("a.bbb").getAttribute("data-href")});
377
+ * > javascript:;
378
+ */
379
+ getArrayRealValue(...args: (NodeList | (() => HTMLElement))[]): any;
380
+ /**
381
+ * 获取天数差异,如何获取某个时间与另一个时间相差的天数
382
+ * @param timestamp1 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
383
+ * @param timestamp2 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
384
+ * @param type (可选)返回的数字的表达的类型,比如:年、月、天、时、分、秒、auto,默认天
385
+ * @example
386
+ * Utils.getDaysDifference(new Date().getTime());
387
+ * > 0
388
+ * @example
389
+ * Utils.getDaysDifference(new Date().getTime(),undefined,"秒");
390
+ * > 0
391
+ */
392
+ getDaysDifference(timestamp1?: number, timestamp2?: number, type?: "auto"): string;
393
+ /**
394
+ * 获取天数差异,如何获取某个时间与另一个时间相差的天数
395
+ * @param timestamp1 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
396
+ * @param timestamp2 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
397
+ * @param type (可选)返回的数字的表达的类型,比如:年、月、天、时、分、秒、auto,默认天
398
+ * @example
399
+ * Utils.getDaysDifference(new Date().getTime());
400
+ * > 0
401
+ * @example
402
+ * Utils.getDaysDifference(new Date().getTime(),undefined,"秒");
403
+ * > 0
404
+ */
405
+ getDaysDifference(timestamp1?: number, timestamp2?: number, type?: "年" | "月" | "天" | "时" | "分" | "秒"): number;
406
+ /**
407
+ * 获取元素的选择器字符串
408
+ * @param element
409
+ * @example
410
+ * Utils.getElementSelector(document.querySelector("a"))
411
+ * > '.....'
412
+ */
413
+ getElementSelector(element: HTMLElement): string;
414
+ /**
415
+ * 获取最大值
416
+ * @example
417
+ * Utils.getMaxValue(1,3,5,7,9)
418
+ * > 9
419
+ */
420
+ getMaxValue(...args: number[]): number;
421
+ /**
422
+ * 获取最大值
423
+ * @example
424
+ * Utils.getMaxValue([1,3,5])
425
+ * > 5
426
+ */
427
+ getMaxValue(val: number[]): number;
428
+ /**
429
+ * 获取最大值
430
+ * @example
431
+ * Utils.getMaxValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
432
+ * > 456
433
+ */
434
+ getMaxValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
435
+ /**
436
+ * 获取页面中最大的z-index的元素信息
437
+ * @param deviation 获取最大的z-index值的偏移,默认是+1
438
+ * @example
439
+ * Utils.getMaxZIndexNodeInfo();
440
+ * > {
441
+ * node: ...,
442
+ * zIndex: 1001
443
+ * }
444
+ **/
445
+ getMaxZIndexNodeInfo(deviation?: number): {
446
+ node: Element;
447
+ zIndex: number;
448
+ };
449
+ /**
450
+ * 获取页面中最大的z-index
451
+ * @param deviation 获取最大的z-index值的偏移,默认是+1
452
+ * @example
453
+ * Utils.getMaxZIndex();
454
+ * > 1001
455
+ **/
456
+ getMaxZIndex(deviation?: number): number;
457
+ /**
458
+ * 获取最小值
459
+ * @example
460
+ * Utils.getMinValue(1,3,5,7,9)
461
+ * > 1
462
+ */
463
+ getMinValue(...args: number[]): number;
464
+ /**
465
+ * 获取最小值
466
+ * @example
467
+ * Utils.getMinValue([1,3,5])
468
+ * > 1
469
+ */
470
+ getMinValue(val: number[]): number;
471
+ /**
472
+ * 获取最小值
473
+ * @example
474
+ * Utils.getMinValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
475
+ * > 123
476
+ */
477
+ getMinValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
478
+ /**
479
+ * 获取最小值
480
+ * @example
481
+ * Utils.getMinValue([{1:123},{2:345},{3:456}],(index,value)=>{return parseInt(index)})
482
+ * > 0
483
+ */
484
+ getMinValue(val: UtilsOwnObject<number>[], handler: (index: number, value: any) => number): number;
485
+ /**
486
+ * 获取随机的安卓手机User-Agent
487
+ * @example
488
+ * Utils.getRandomAndroidUA();
489
+ * > 'Mozilla/5.0 (Linux; Android 10; MI 13 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.3490.40 Mobile Safari/537.36'
490
+ **/
491
+ getRandomAndroidUA(): string;
492
+ /**
493
+ * 获取随机值
494
+ * @example
495
+ * Utils.getRandomValue(1,9,6,99)
496
+ * > 6
497
+ */
498
+ getRandomValue<T extends any>(...args: T[]): T;
499
+ /**
500
+ * 获取随机值
501
+ * @example
502
+ * Utils.getRandomValue([1,2,3])
503
+ * > 3
504
+ * @example
505
+ * Utils.getRandomValue({1:"结果1",2:"结果2",3:"结果3"}})
506
+ * > 结果2
507
+ */
508
+ getRandomValue<T extends any>(val: T[] | UtilsOwnObject<T>): T;
509
+ /**
510
+ * 获取两个数之间随机值
511
+ * @example
512
+ * Utils.getRandomValue(1,9)
513
+ * > 6
514
+ */
515
+ getRandomValue(val_1: number, val_2: number): number;
516
+ /**
517
+ * 获取随机值
518
+ * @example
519
+ * Utils.getRandomValue({1:1},{2:2})
520
+ * > {1: 1}
521
+ */
522
+ getRandomValue<T extends any>(val_1: UtilsOwnObject<T>, val_2: UtilsOwnObject<T>): T;
523
+ /**
524
+ * 获取随机的电脑端User-Agent
525
+ * + Mozilla/5.0:以前用于Netscape浏览器,目前大多数浏览器UA都会带有
526
+ * + Windows NT 13:代表Window11系统
527
+ * + Windows NT 10.0:代表Window10系统
528
+ * + Windows NT 6.1:代表windows7系统
529
+ * + WOW64Windows-on-Windows 64-bit,32位的应用程序运行于此64位处理器上
530
+ * + Win64:64位
531
+ * + AppleWebKit/537.36:浏览器内核
532
+ * + KHTML:HTML排版引擎
533
+ * + like Gecko:这不是Geckeo 浏览器,但是运行起来像Geckeo浏览器
534
+ * + Chrome/106.0.5068.19:Chrome版本号
535
+ * + Safari/537.36:宣称自己是Safari?
536
+ * @returns 返回随机字符串
537
+ * @example
538
+ * Utils.getRandomPCUA();
539
+ * > 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.5068.19 Safari/537.36'
540
+ **/
541
+ getRandomPCUA(): string;
542
+ /**
543
+ * 获取元素上的使用React框架的实例属性,目前包括reactFiber、reactProps、reactEvents、reactEventHandlers、reactInternalInstance
544
+ * @param element 需要获取的目标元素
545
+ * @returns
546
+ * @example
547
+ * Utils.getReactObj(document.querySelector("input"))?.reactProps?.onChange({target:{value:"123"}});
548
+ */
549
+ getReactObj(element: HTMLElement | Element): {
550
+ reactFiber?: any;
551
+ reactProps?: any;
552
+ reactEvents?: any;
553
+ reactEventHandlers?: any;
554
+ reactInternalInstance?: any;
555
+ reactContainer?: any;
556
+ };
557
+ /**
558
+ * 获取对象上的Symbol属性,如果没设置keyName,那么返回一个对象,对象是所有遍历到的Symbol对象
559
+ * @param target 目标对象
560
+ * @param keyName (可选)Symbol名或者Symbol对象
561
+ */
562
+ getSymbol(target: any, keyName?: string | symbol): any;
563
+ /**
564
+ * 获取文本的字符长度
565
+ * @param text
566
+ * @example
567
+ * Utils.getTextLength("测试文本")
568
+ * > 12
569
+ */
570
+ getTextLength(text: string): number;
571
+ /**
572
+ * 获取文本占据的空间大小,返回自动的单位,如12 Kb,14 K,20 MB,1 GB
573
+ * @param text 目标字符串
574
+ * @param addType (可选)是否添加单位
575
+ * + true (默认) 自动添加单位
576
+ * + false 不添加单位
577
+ * @example
578
+ * Utils.getTextStorageSize("测试文本");
579
+ * > '12.00B'
580
+ */
581
+ getTextStorageSize<T extends boolean>(text: string, addType?: T): T extends true ? string : number;
582
+ /**
583
+ * 获取迅雷协议的Url
584
+ * @param url Url链接或者其它信息
585
+ */
586
+ getThunderUrl(url: string): string;
587
+ /**
588
+ * 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
589
+ * @example
590
+ let GM_cookie = new Utils.GM_Cookie();
591
+ GM_cookie.list({name:"xxx_cookie_xxx"},function(cookies,error){
592
+ if (!error) {
593
+ console.log(cookies);
594
+ console.log(cookies.value);
595
+ } else {
596
+ console.error(error);
597
+ }
598
+ });
599
+ GM_cookie.set({name:"xxx_cookie_test_xxx",value:"这是Cookie测试值"},function(error){
600
+ if (error) {
601
+ console.error(error);
602
+ } else {
603
+ console.log('Cookie set successfully.');
604
+ }
605
+ })
606
+ GM_cookie.delete({name:"xxx_cookie_test_xxx"},function(error){
607
+ if (error) {
608
+ console.error(error);
609
+ } else {
610
+ console.log('Cookie set successfully.');
611
+ }
612
+ })
613
+ **/
614
+ GM_Cookie: typeof UtilsGMCookie;
615
+ /**
616
+ * 注册油猴菜单,要求本地存储的键名不能存在其它键名`GM_Menu_Local_Map`会冲突/覆盖
617
+ * @example
618
+ let GM_Menu = new Utils.GM_Menu({
619
+ data: [
620
+ {
621
+ menu_key: "menu_key",
622
+ text: "测试按钮",
623
+ enable: true,
624
+ accessKey: "a",
625
+ autoClose: false,
626
+ showText(text, enable) {
627
+ return "[" + (enable ? "√" : "×") + "]" + text;
628
+ },
629
+ callback(data) {
630
+ console.log("点击菜单,值修改为", data.enable);
631
+ },
632
+ },
633
+ ],
634
+ autoReload: false,
635
+ GM_getValue,
636
+ GM_setValue,
637
+ GM_registerMenuCommand,
638
+ GM_unregisterMenuCommand,
639
+ });
640
+
641
+
642
+ // 获取某个菜单项的值
643
+ GM_Menu.get("menu_key");
644
+ > true
645
+
646
+ // 获取某个菜单项的开启/关闭后显示的文本
647
+ GM_Menu.getShowTextValue("menu_key");
648
+ > √测试按钮
649
+
650
+ // 添加键为menu_key2的菜单项
651
+ GM_Menu.add({
652
+ key:"menu_key2",
653
+ text: "测试按钮2",
654
+ enable: false,
655
+ showText(text,enable){
656
+ return "[" + (enable ? "√" : "×") + "]" + text;
657
+ },
658
+ callback(data){
659
+ console.log("点击菜单,值修改为",data.enable);
660
+ }
661
+ });
662
+ // 使用数组的方式添加多个菜单,如menu_key3、menu_key4
663
+ GM_Menu.add([
664
+ {
665
+ key:"menu_key3",
666
+ text: "测试按钮3",
667
+ enable: false,
668
+ showText(text,enable){
669
+ return "[" + (enable ? "√" : "×") + "]" + text;
670
+ },
671
+ callback(data){
672
+ console.log("点击菜单,值修改为",data.enable);
673
+ }
674
+ },
675
+ {
676
+ key:"menu_key4",
677
+ text: "测试按钮4",
678
+ enable: false,
679
+ showText(text,enable){
680
+ return "[" + (enable ? "√" : "×") + "]" + text;
681
+ },
682
+ callback(data){
683
+ console.log("点击菜单,值修改为",data.enable);
684
+ }
685
+ }
686
+ ]);
687
+
688
+ // 更新键为menu_key的显示文字和点击回调
689
+ GM_Menu.update({
690
+ menu_key:{
691
+ text: "更新后的测试按钮",
692
+ enable: true,
693
+ showText(text,enable){
694
+ return "[" + (enable ? "√" : "×") + "]" + text;
695
+ },
696
+ callback(data){
697
+ console.log("点击菜单更新后的测试按钮,新值修改为",data.enable);
698
+ }
699
+ }
700
+ });
701
+
702
+ // 删除键为menu_key的菜单
703
+ GM_Menu.delete("menu_key");
704
+ **/
705
+ GM_Menu: typeof GMMenu;
706
+ /**
707
+ * 基于Function prototype,能够勾住和释放任何函数
708
+ *
709
+ * .hook
710
+ * + realFunc {string} 用于保存原始函数的函数名称,用于unHook
711
+ * + hookFunc {string} 替换的hook函数
712
+ * + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
713
+ * + methodName {string} 匿名函数需显式传入目标函数名eg:this.Begin = function(){....};}
714
+ *
715
+ * .unhook
716
+ * + realFunc {string} 用于保存原始函数的函数名称,用于unHook
717
+ * + funcName {string} 被Hook的函数名称
718
+ * + context {object} 目标函数所在对象,用于hook非window对象下的函数,如String.protype.slice,carInstance1
719
+ * @example
720
+ let hook = new Utils.Hooks();
721
+ hook.initEnv();
722
+ function myFunction(){
723
+ console.log("我自己需要执行的函数");
724
+ }
725
+ function testFunction(){
726
+ console.log("正常执行的函数");
727
+ }
728
+ testFunction.hook(testFunction,myFunction,window);
729
+ **/
730
+ Hooks: typeof Hooks;
731
+ /**
732
+ * 为减少代码量和回调,把GM_xmlhttpRequest封装
733
+ * 文档地址: https://www.tampermonkey.net/documentation.php?ext=iikm
734
+ * 其中onloadstart、onprogress、onreadystatechange是回调形式,onabort、ontimeout、onerror可以设置全局回调函数
735
+ * @param _GM_xmlHttpRequest_ 油猴中的GM_xmlhttpRequest
736
+ * @example
737
+ let httpx = new Utils.Httpx(GM_xmlhttpRequest);
738
+ let postResp = await httpx.post({
739
+ url:url,
740
+ data:JSON.stringify({
741
+ test:1
742
+ }),
743
+ timeout: 5000
744
+ });
745
+ console.log(postResp);
746
+ > {
747
+ status: true,
748
+ data: {responseText: "...", response: xxx,...},
749
+ msg: "请求完毕",
750
+ type: "onload",
751
+ }
752
+
753
+ if(postResp === "onload" && postResp.status){
754
+ // onload
755
+ }else if(postResp === "ontimeout"){
756
+ // ontimeout
757
+ }
758
+ * @example
759
+ // 也可以先配置全局参数
760
+ let httpx = new Utils.Httpx(GM_xmlhttpRequest);
761
+ httpx.config({
762
+ timeout: 5000,
763
+ async: false,
764
+ responseType: "html",
765
+ redirect: "follow",
766
+ })
767
+ // 优先级为 默认details < 全局details < 单独的details
768
+ */
769
+ Httpx: typeof Httpx;
770
+ /**
771
+ * 浏览器端的indexedDB操作封装
772
+ * @example
773
+ let db = new Utils.indexedDB('web_DB', 'nav_text')
774
+ let data = {name:'管理员', roleId: 1, type: 1};
775
+ db.save('list',data).then((resolve)=>{
776
+ console.log(resolve,'存储成功')
777
+ })
778
+
779
+ db.get('list').then((resolve)=>{
780
+ console.log(resolve,'查询成功')
781
+ })
782
+
783
+ db.getPaging('list',20,10).then((resolve)=>{
784
+ console.log(resolve,'查询分页偏移第20,一共10行成功');
785
+ })
786
+
787
+ db.delete('list').then(resolve=>{
788
+ console.log(resolve,'删除成功---->>>>>>name')
789
+ })
790
+
791
+ db.deleteAll().then(resolve=>{
792
+ console.log(resolve,'清除数据库---->>>>>>name')
793
+ })
794
+ **/
795
+ indexedDB: typeof indexedDB;
796
+ /**
797
+ * 判断目标函数是否是Native Code
798
+ * @param target
799
+ * @returns
800
+ * + true Native
801
+ * + false 不是Native
802
+ * @example
803
+ * Utils.isNativeFunc(window.location.assign)
804
+ * > true
805
+ */
806
+ isNativeFunc(target: Function): boolean;
807
+ /**
808
+ * 判断当前的位置是否位于页面底部附近
809
+ * @param nearValue (可选)判断在页面底部的误差值,默认:50
810
+ * @returns
811
+ * + true 在底部附近
812
+ * + false 不在底部附近
813
+ */
814
+ isNearBottom(nearValue?: number): boolean;
815
+ /**
816
+ * 判断对象是否是元素
817
+ * @param target
818
+ * @returns
819
+ * + true 是元素
820
+ * + false 不是元素
821
+ * @example
822
+ * Utils.isDOM(document.querySelector("a"))
823
+ * > true
824
+ */
825
+ isDOM(target: any): boolean;
826
+ /**
827
+ * 判断浏览器是否支持全屏
828
+ */
829
+ isFullscreenEnabled(): boolean;
830
+ /**
831
+ * 判断对象是否是jQuery对象
832
+ * @param target
833
+ * @returns
834
+ * + true jQuery对象
835
+ * + false 不是jQuery对象
836
+ * @example
837
+ * Utils.isJQuery($("a"))
838
+ * > true
839
+ */
840
+ isJQuery(target: any): boolean;
841
+ /**
842
+ * 判断当前设备是否是移动端
843
+ * @param userAgent (可选)UA字符串,默认使用当前的navigator.userAgent
844
+ * @returns
845
+ * + true 是移动端
846
+ * + false 不是移动端
847
+ * @example
848
+ * Utils.isPhone();
849
+ * > true
850
+ **/
851
+ isPhone(userAgent?: string): boolean;
852
+ /**
853
+ * 判断传递的字符串是否是由相同的字符组成
854
+ * @param targetStr 需要判断的字符串,长度(.length)需要≥2
855
+ * @param coefficient 系数(默认:1),某个字符重复的系数大于它那么就是返回true,默认全部
856
+ */
857
+ isSameChars(targetStr: string, coefficient?: number): boolean;
858
+ /**
859
+ * 判断对象是否不为空
860
+ * @returns {boolean}
861
+ * + true 不为空
862
+ * + false 为空
863
+ * @example
864
+ * Utils.isNotNull("123");
865
+ * > true
866
+ */
867
+ isNotNull<T>(value: T | null | undefined): value is T;
868
+ isNotNull(...args: any[]): boolean;
869
+ /**
870
+ * 判断对象或数据是否为空
871
+ * + `String`判空的值,如 ""、"null"、"undefined"、" "
872
+ * + `Number`判空的值,如 0
873
+ * + `Object`判空的值,如 {}、null、undefined
874
+ * + `Array`(存在属性Symbol.iterator)判空的值,如 []
875
+ * + `Boolean`判空的值,如false
876
+ * + `Function`判空的值,如()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){}
877
+ * @returns
878
+ * + true 为空
879
+ * + false 不为空
880
+ * @example
881
+ Utils.isNull({});
882
+ > true
883
+ * @example
884
+ Utils.isNull([]);
885
+ > true
886
+ * @example
887
+ Utils.isNull(" ");
888
+ > true
889
+ * @example
890
+ Utils.isNull(function(){});
891
+ > true
892
+ * @example
893
+ Utils.isNull(()=>{}));
894
+ > true
895
+ * @example
896
+ Utils.isNull("undefined");
897
+ > true
898
+ * @example
899
+ Utils.isNull("null");
900
+ > true
901
+ * @example
902
+ Utils.isNull(" ", false);
903
+ > true
904
+ * @example
905
+ Utils.isNull([1],[]);
906
+ > false
907
+ * @example
908
+ Utils.isNull([],[1]);
909
+ > false
910
+ * @example
911
+ Utils.isNull(false,[123]);
912
+ > false
913
+ **/
914
+ isNull<T>(value: T | undefined | null): value is null | undefined;
915
+ isNull(...args: any[]): boolean;
916
+ /**
917
+ * 判断浏览器主题是否是暗黑|深色模式
918
+ */
919
+ isThemeDark(): boolean;
920
+ /**
921
+ * 判断元素是否在页面中可见
922
+ * @param element 需要检查的元素,可以是普通元素|数组形式的元素|通过querySelectorAll获取的元素数组
923
+ * @param inView
924
+ * + true 在窗口可视区域
925
+ * + false 不在窗口可视区域
926
+ * @returns
927
+ * + true 可见
928
+ * + false 不可见
929
+ * @example
930
+ * Utils.isVisible(document.documentElement)
931
+ * > true
932
+ */
933
+ isVisible(element: HTMLElement | HTMLElement[] | Element | NodeList, inView?: boolean): boolean;
934
+ /**
935
+ * 判断是否是Via浏览器环境
936
+ * @returns
937
+ * + true Via
938
+ * + false 不是Via
939
+ * @example
940
+ * Utils.isWebView_Via()
941
+ * > false
942
+ */
943
+ isWebView_Via(): boolean;
944
+ /**
945
+ * 判断是否是X浏览器环境
946
+ * @returns
947
+ * + true X浏览器
948
+ * + false 不是X浏览器
949
+ * @example
950
+ * Utils.isWebView_X()
951
+ * > false
952
+ */
953
+ isWebView_X(): boolean;
954
+ /**
955
+ * 把对象内的value值全部取出成数组
956
+ * @param target 目标对象
957
+ * @returns 返回数组
958
+ * @example
959
+ * Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
960
+ * > ['jsonToArray', 'Array']
961
+ **/
962
+ parseObjectToArray(target: any): any;
963
+ /**
964
+ * 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
965
+ * @example
966
+ let lock = new Utils.LockFunction(()=>{console.log(1)}))
967
+ lock.run();
968
+ > 1
969
+ * @example
970
+ let lock = new Utils.LockFunction(()=>{console.log(1)}),true) -- 异步操作
971
+ await lock.run();
972
+ > 1
973
+ **/
974
+ LockFunction: typeof LockFunction;
975
+ /**
976
+ * 日志对象
977
+ * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}}
978
+ * @example
979
+ let log = new Utils.Log(GM_info);
980
+ log.info("普通输出");
981
+ > 普通输出
982
+
983
+ log.success("成功输出");
984
+ > 成功输出
985
+
986
+ log.error("错误输出");
987
+ > 错误输出
988
+
989
+ log.warn("警告输出");
990
+ > 警告输出
991
+
992
+ log.tag = "自定义tag信息";
993
+ log.info("自定义info的颜色","#e0e0e0");
994
+ > 自定义info的颜色
995
+
996
+ log.config({
997
+ successColor: "#31dc02",
998
+ errorColor: "#e02d2d",
999
+ infoColor: "black",
1000
+ })
1001
+ log.success("颜色为#31dc02");
1002
+ > 颜色为#31dc02
1003
+ */
1004
+ Log: typeof Log;
1005
+ /**
1006
+ * 合并数组内的JSON的值字符串
1007
+ * @param data 需要合并的数组
1008
+ * @param handleFunc 处理的函数|JSON的key
1009
+ * @example
1010
+ * Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
1011
+ * > '数组内数据部分字段合并成字符串->mergeToString'
1012
+ **/
1013
+ mergeArrayToString(data: any[], handleFunc?: (val: any) => any): string;
1014
+ /**
1015
+ * 监听页面元素改变并处理
1016
+ * @param target 需要监听的元素,如果不存在,可以等待它出现
1017
+ * @param observer_config MutationObserver的配置
1018
+ * @example
1019
+ Utils.mutationObserver(document.querySelector("div.xxxx"),{
1020
+ "callback":(mutations, observer)=>{},
1021
+ "config":{childList:true,attributes:true}
1022
+ });
1023
+ * @example
1024
+ Utils.mutationObserver(document.querySelectorAll("div.xxxx"),{
1025
+ "callback":(mutations, observer)=>{},
1026
+ "config":{childList:true,attributes:true}}
1027
+ );
1028
+ * @example
1029
+ Utils.mutationObserver($("div.xxxx"),{
1030
+ "callback":(mutations, observer)=>{},
1031
+ "config":{childList:true,attributes:true}}
1032
+ );
1033
+ **/
1034
+ mutationObserver(target: HTMLElement | Node | NodeList | Document, observer_config: {
1035
+ /**
1036
+ * observer的配置
1037
+ */
1038
+ config?: MutationObserverInit;
1039
+ /**
1040
+ * 是否主动触发一次
1041
+ */
1042
+ immediate?: boolean;
1043
+ /**
1044
+ * 触发的回调函数
1045
+ */
1046
+ callback: MutationCallback;
1047
+ }): MutationObserver;
1048
+ /**
1049
+ * 使用观察器观察元素出现在视图内,出现的话触发回调
1050
+ * @param target 目标元素
1051
+ * @param callback 触发的回调
1052
+ * @param options 观察器配置
1053
+ * @example
1054
+ * Utils.mutationVisible(document.querySelector("div.xxxx"),(entries,observer)=>{
1055
+ * console.log("该元素出现在视图内");
1056
+ * }))
1057
+ */
1058
+ mutationVisible(target: Element | Element[], callback: (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void, options?: IntersectionObserverInit): void;
1059
+ /**
1060
+ * 去除全局window下的Utils,返回控制权
1061
+ * @example
1062
+ * let utils = Utils.noConflict();
1063
+ * > ...
1064
+ */
1065
+ noConflict(): Utils;
1066
+ /**
1067
+ * 恢复/释放该对象内的为function,让它无效/有效
1068
+ * @param needReleaseObject 需要操作的对象
1069
+ * @param needReleaseName 需要操作的对象的名字
1070
+ * @param functionNameList (可选)需要释放的方法,默认:全部方法
1071
+ * @param release (可选)
1072
+ * + true (默认) 释放该对象下的某些方法
1073
+ * + false 恢复该对象下的某些方法
1074
+ * @example
1075
+ // 释放该方法
1076
+ Utils.noConflictFunc(console,"console",["log"],true);
1077
+ console.log;
1078
+ > () => {}
1079
+
1080
+ * @example
1081
+ // 恢复该方法
1082
+ Utils.noConflictFunc(console,"console",["log"],false);
1083
+ console.log;
1084
+ > ƒ log() { [native code] }
1085
+
1086
+ * @example
1087
+ // 释放所有方法
1088
+ Utils.noConflictFunc(console,"console",[],true);
1089
+ console.debug;
1090
+ > () => {}
1091
+
1092
+ * @example
1093
+ // 恢复所有方法
1094
+ Utils.noConflictFunc(console,"console",[],false);
1095
+ console.debug;
1096
+ > ƒ log() { [native code] }
1097
+ **/
1098
+ noConflictFunc(needReleaseObject: object, needReleaseName: string, functionNameList?: any[], release?: boolean): void;
1099
+ /**
1100
+ * base64转blob
1101
+ * @param dataUri base64的数据
1102
+ * @returns blob的链接
1103
+ * @example
1104
+ * Utils.parseBase64ToBlob("data:image/jpeg;base64,.....");
1105
+ * > blob://xxxxxxx
1106
+ **/
1107
+ parseBase64ToBlob(dataUri: string): Blob;
1108
+ /**
1109
+ * base64转File对象
1110
+ * @param dataUri base64的数据
1111
+ * @param fileName (可选)文件名,默认:example
1112
+ * @returns blob的链接
1113
+ * @example
1114
+ * Utils.parseBase64ToFile("data:image/jpeg;base64,.....","测试文件");
1115
+ * > object
1116
+ **/
1117
+ parseBase64ToFile(dataUri: string, fileName?: string): File;
1118
+ /**
1119
+ * 将正则匹配到的结果取出最后一个值并转换成int格式
1120
+ * @param matchList 正则匹配的列表
1121
+ * @param defaultValue 正则匹配的列表为空时,或者正则匹配的列表最后一项不为Int,返回该默认值0
1122
+ * @example
1123
+ * Utils.parseInt(["dadaadada123124","123124"],0);
1124
+ * > 123124
1125
+ *
1126
+ * @example
1127
+ * Utils.parseInt(null,0);
1128
+ * > 0
1129
+ * @example
1130
+ * Utils.parseInt(["aaaaaa"]);
1131
+ * > 0
1132
+ *
1133
+ * @example
1134
+ * Utils.parseInt(["aaaaaa"],"66");
1135
+ * > 66
1136
+ *
1137
+ * @example
1138
+ * Utils.parseInt(["aaaaaaa"],"aa");
1139
+ * > NaN
1140
+ **/
1141
+ parseInt(matchList?: any[], defaultValue?: number): number;
1142
+ /**
1143
+ * blob转File对象
1144
+ * @param blobUrl 需要转换的blob的链接
1145
+ * @param fileName (可选)转换成的File对象的文件名称,默认:example
1146
+ * @example
1147
+ * Utils.parseBlobToFile("blob://xxxxx");
1148
+ * > object
1149
+ **/
1150
+ parseBlobToFile(blobUrl: string, fileName?: string): Promise<File | Error>;
1151
+ /**
1152
+ * 解析CDATA格式的内容字符串
1153
+ * @param text 传入CDATA字符串
1154
+ * @returns 返回解析出的内容
1155
+ * @example
1156
+ * let xml = "<root><![CDATA[This is some CDATA content.]]></root>";
1157
+ * console.log(Utils.parseCDATA(xml));
1158
+ * > This is some CDATA content.
1159
+ */
1160
+ parseCDATA(text: string): string;
1161
+ /**
1162
+ * 【异步函数】File对象转base64
1163
+ * @param fileObj 需要转换的File对象
1164
+ * @example
1165
+ * await Utils.parseFileToBase64(object);
1166
+ * > 'data:image/jpeg:base64/,xxxxxx'
1167
+ **/
1168
+ parseFileToBase64(fileObj: File): Promise<string>;
1169
+ /**
1170
+ * 解析字符串
1171
+ * @param text 要解析的 DOMString。它必须包含 HTML、xml、xhtml+xml 或 svg 文档。
1172
+ * @param mimeType (可选)解析成的类型
1173
+ * + (默认)text/html
1174
+ * + text/xml
1175
+ * + application/xml
1176
+ * + application/xhtml+xml
1177
+ * + image/svg+xml
1178
+ * @example
1179
+ * Utils.parseFromString("<p>123<p>");
1180
+ * > #document
1181
+ */
1182
+ parseFromString(text: string, mimeType?: "text/html" | "text/xml" | "application/xml" | "application/xhtml+xml" | "image/svg+xml"): HTMLElement | XMLDocument | SVGElement;
1183
+ /**
1184
+ * 将字符串进行正则转义
1185
+ * 例如:^替换$
1186
+ * 转换:\^替换\$
1187
+ */
1188
+ parseStringToRegExpString(text: string): string;
1189
+ /**
1190
+ * 阻止事件传递
1191
+ * @param element 要进行处理的元素
1192
+ * @param eventNameList (可选)要阻止的事件名|列表
1193
+ * @param capture (可选)是否捕获,默认false
1194
+ * @example
1195
+ * Utils.preventEvent(document.querySelector("a"),"click")
1196
+ * @example
1197
+ * Utils.preventEvent(event);
1198
+ */
1199
+ preventEvent(event: Event): boolean;
1200
+ /**
1201
+ * 阻止事件传递
1202
+ * @param element 要进行处理的元素
1203
+ * @param eventNameList (可选)要阻止的事件名|列表
1204
+ * @param capture (可选)是否捕获,默认false
1205
+ * @example
1206
+ * Utils.preventEvent(document.querySelector("a"),"click")
1207
+ * @example
1208
+ * Utils.preventEvent(event);
1209
+ */
1210
+ preventEvent(element: HTMLElement, eventNameList?: string | string[], capture?: boolean): boolean;
1211
+ /**
1212
+ * 在canvas元素节点上绘制进度圆圈
1213
+ * @example
1214
+ let progress = new Utils.Process({canvasNode:document.querySelector("canvas")});
1215
+ progress.draw();
1216
+ * **/
1217
+ Progress: typeof Progress;
1218
+ /**
1219
+ * 劫持Event的isTrust为true,注入时刻,ducument-start
1220
+ * @param isTrustValue (可选)让isTrusted为true
1221
+ * @param filter (可选)过滤出需要的事件名,true为需要,false为不需要
1222
+ * @example
1223
+ * Utils.registerTrustClickEvent()
1224
+ */
1225
+ registerTrustClickEvent(isTrustValue?: boolean, filter?: (typeName: string) => boolean): void;
1226
+ /**
1227
+ * 将数字进行正/负转换
1228
+ * @param num 需要进行转换的数字
1229
+ */
1230
+ reverseNumber(num: number): number;
1231
+ /**
1232
+ * 将元素上的文本或元素使用光标进行选中
1233
+ *
1234
+ * 注意,如果设置startIndex和endIndex,且元素上并无可选则的坐标,那么会报错
1235
+ * @param element 目标元素
1236
+ * @param childTextNode 目标元素下的#text元素
1237
+ * @param startIndex (可选)开始坐标,可为空
1238
+ * @param endIndex (可选)结束坐标,可为空
1239
+ */
1240
+ selectElementText(element: HTMLElement | Element | Node, childTextNode?: ChildNode, startIndex?: number, endIndex?: number): void;
1241
+ /**
1242
+ * 复制到剪贴板
1243
+ * @param data 需要复制到剪贴板的文本
1244
+ * @param info (可选)默认:text/plain
1245
+ * @example
1246
+ * Utils.setClip({1:2});
1247
+ * > {"1":2}
1248
+ * @example
1249
+ * Utils.setClip( ()=>{
1250
+ * console.log(1)
1251
+ * });
1252
+ * > ()=>{console.log(1)}
1253
+ * @example
1254
+ * Utils.setClip("xxxx");
1255
+ * > xxxx
1256
+ * @example
1257
+ * Utils.setClip("xxxx","html");
1258
+ * > xxxx
1259
+ * @example
1260
+ * Utils.setClip("xxxx","text/plain");
1261
+ * > xxxx
1262
+ **/
1263
+ setClip(data: any, info?: {
1264
+ type: string;
1265
+ mimetype: string;
1266
+ } | string): Promise<boolean>;
1267
+ /**
1268
+ * 【异步函数】等待N秒执行函数
1269
+ * @param callback 待执行的函数(字符串)
1270
+ * @param delayTime (可选)延时时间(ms),默认:0
1271
+ * @example
1272
+ * await Utils.setTimeout(()=>{}, 2500);
1273
+ * > ƒ tryCatchObj() {}
1274
+ * @example
1275
+ * await Utils.setTimeout("()=>{console.log(12345)}", 2500);
1276
+ * > ƒ tryCatchObj() {}
1277
+ **/
1278
+ setTimeout(callback: (() => void) | string, delayTime?: number): Promise<any>;
1279
+ /**
1280
+ * 【异步函数】延迟xxx毫秒
1281
+ * @param delayTime (可选)延时时间(ms),默认:0
1282
+ * @example
1283
+ * await Utils.sleep(2500)
1284
+ **/
1285
+ sleep(delayTime?: number): Promise<void>;
1286
+ /**
1287
+ * 向右拖动滑块
1288
+ * @param selector 选择器|元素
1289
+ * @param offsetX (可选)水平拖动长度,默认:window.innerWidth
1290
+ * @example
1291
+ * Utils.dragSlider("#xxxx");
1292
+ * @example
1293
+ * Utils.dragSlider("#xxxx",100);
1294
+ */
1295
+ dragSlider(selector: string | Element | Node, offsetX?: number): void;
1296
+ /**
1297
+ * 使目标元素进入全屏
1298
+ * @param element (可选)目标元素,默认:document.documentElement
1299
+ * @param options (可选)配置,一般不用
1300
+ * @example
1301
+ * Utils.enterFullScreen();
1302
+ */
1303
+ enterFullScreen(element: HTMLElement, options?: FullscreenOptions): void;
1304
+ /**
1305
+ * 使浏览器退出全屏
1306
+ * @param element (可选)目标元素,默认:document.documentElement
1307
+ * @example
1308
+ * Utils.exitFullScreen();
1309
+ */
1310
+ exitFullScreen(element?: HTMLElement): Promise<void>;
1311
+ /**
1312
+ * 数组按照内部某个值的大小比对排序,如[{"time":"2022-1-1"},{"time":"2022-2-2"}]
1313
+ * @param data 数据|获取数据的方法
1314
+ * @param getPropertyValueFunc 数组内部项的某个属性的值的方法,参数为这个项
1315
+ * @param sortByDesc (可选)排序方式
1316
+ * + true (默认)倒序(值最大排第一个,如:654、3...)
1317
+ * + false 升序(值最小排第一个,如:1、2、3、4...)
1318
+ * @returns 返回比较排序完成的数组
1319
+ * @example
1320
+ * Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]})
1321
+ * > [{time: '2022-2-2'},{time: '2022-1-1'}]
1322
+ * @example
1323
+ * Utils.sortListByProperty([{"time":"2022-1-1"},{"time":"2022-2-2"}],(item)=>{return item["time"]},false)
1324
+ * > [{time: '2022-1-1'},{time: '2022-2-2'}]
1325
+ **/
1326
+ sortListByProperty<T extends any>(data: T[], getPropertyValueFunc: string | ((value: T) => any), sortByDesc?: boolean): T[];
1327
+ /**
1328
+ * 字符串转正则,用于把字符串中不规范的字符进行转义
1329
+ * @param targetString 需要进行转换的字符串
1330
+ * @param flags 正则标志
1331
+ */
1332
+ stringToRegular(targetString: string | RegExp, flags?: "g" | "i" | "m" | "u" | "y" | string): RegExp;
1333
+ /**
1334
+ * 字符串首字母转大写
1335
+ * @param targetString 目标字符串
1336
+ * @param otherStrToLowerCase (可选)剩余部分字符串转小写,默认false
1337
+ */
1338
+ stringTitleToUpperCase(targetString: string, otherStrToLowerCase?: boolean): string;
1339
+ /**
1340
+ * 判断目标字符串是否是以xxx开始
1341
+ *
1342
+ * 如果searchString是字符串数组,那么判断的结果则是字符串数组中的任意字符匹配到返回true
1343
+ * @param target 目标字符串
1344
+ * @param searchString 需要搜索的字符串
1345
+ * @param position (可选)目标字符串的判断起点,要求≥0,默认为0
1346
+ */
1347
+ startsWith(target: string, searchString: string | RegExp | string[], position?: number): boolean;
1348
+ /**
1349
+ * 字符串首字母转小写
1350
+ * @param targetString 目标字符串
1351
+ * @param otherStrToLowerCase (可选)剩余部分字符串转大写,默认false
1352
+ */
1353
+ stringTitleToLowerCase(targetString: string, otherStrToUpperCase?: boolean): string;
1354
+ /**
1355
+ * 字符串转Object对象,类似'{"test":""}' => {"test":""}
1356
+ * @param data
1357
+ * @param errorCallBack (可选)错误回调
1358
+ * @example
1359
+ * Utils.toJSON("{123:123}")
1360
+ * > {123:123}
1361
+ */
1362
+ toJSON<T = any>(data: string | null, errorCallBack?: (error: Error) => void): T;
1363
+ /**
1364
+ * 对象转为UrlSearchParams格式的字符串
1365
+ * @param obj 目标对象,可以是对象组成的数组
1366
+ * @param addPrefix 是否添加前缀?
1367
+ * @example
1368
+ * Utils.toSearchParamsStr({
1369
+ * "test": 1,
1370
+ * "test2": 2
1371
+ * })
1372
+ * > test=1&test2=2
1373
+ * @example
1374
+ * Utils.toSearchParamsStr([{
1375
+ * "test": 1,
1376
+ * "test2": 2
1377
+ * },
1378
+ * {
1379
+ * "test3": 3
1380
+ * }
1381
+ * ])
1382
+ * > test=1&test2=2&test3=3
1383
+ */
1384
+ toSearchParamsStr(obj: object | object[], addPrefix?: boolean): string;
1385
+ /**
1386
+ * 将UrlSearchParams格式的字符串转为对象
1387
+ */
1388
+ searchParamStrToObj<T extends any>(searhParamsStr?: string | null | undefined): T;
1389
+ /**
1390
+ * 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
1391
+ * @example
1392
+ * Utils.tryCatch().error().run(()=>{console.log(1)});
1393
+ * > 1
1394
+ * @example
1395
+ * Utils.tryCatch().config({log:true}).error((error)=>{console.log(error)}).run(()=>{throw new Error('测试错误')});
1396
+ * > ()=>{throw new Error('测试错误')}出现错误
1397
+ */
1398
+ tryCatch: (...args: any) => {
1399
+ config(paramDetails: import("./TryCatch").UtilsTryCatchConfig): any;
1400
+ error(handler: ((...args: any[]) => any) | string | Function): any;
1401
+ run<A extends any[], R>(callback: ((...args: A) => R) | string | Function, __context__?: any): import("./TryCatch").UtilsTryCatchType;
1402
+ };
1403
+ /**
1404
+ * 数组去重,去除重复的值
1405
+ * @param uniqueArrayData 需要去重的数组
1406
+ * @param compareArrayData 用来比较的数组
1407
+ * @param compareFun 数组比较方法,如果值相同,去除该数据
1408
+ * @returns 返回去重完毕的数组
1409
+ * @example
1410
+ * Utils.uniqueArray([1,2,3],[1,2],(item,item2)=>{return item===item2 ? true:false});
1411
+ * > [3]
1412
+ *
1413
+ * @example
1414
+ * Utils.uniqueArray([1,2,3],[1,2]);
1415
+ * > [3]
1416
+ *
1417
+ * @example
1418
+ * Utils.uniqueArray([{"key":1,"value":2},{"key":2}],[{"key":1}],(item,item2)=>{return item["key"] === item2["key"] ? true:false});
1419
+ * > [{"key": 2}]
1420
+ **/
1421
+ uniqueArray<T extends any, TT extends any>(uniqueArrayData?: T[], compareArrayData?: TT[], compareFun?: (item1: T, item2: TT) => boolean): any[];
1422
+ /**
1423
+ * 等待函数数组全部执行完毕,注意,每个函数的顺序不是同步
1424
+ * @param data 需要遍历的数组
1425
+ * @param handleFunc 对该数组进行操作的函数,该函数的参数为数组格式的参数,[数组下标,数组项]
1426
+ * @example
1427
+ * await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
1428
+ **/
1429
+ waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]>;
1430
+ /**
1431
+ * 等待元素出现
1432
+ * @param selector CSS选择器
1433
+ * @param parent (可选)父元素,默认document
1434
+ * @example
1435
+ * Utils.waitNode("div").then( $div =>{
1436
+ * console.log($div); // div => HTMLDivELement
1437
+ * })
1438
+ * Utils.waitNode("div",document).then( $div =>{
1439
+ * console.log($div); // div => HTMLDivELement
1440
+ * })
1441
+ */
1442
+ waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K]>;
1443
+ waitNode<T extends Element>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
1444
+ /**
1445
+ * 等待元素出现
1446
+ * @param selectorList CSS选择器数组
1447
+ * @param parent (可选)父元素,默认document
1448
+ * @example
1449
+ * Utils.waitNode(["div"]).then( ([$div]) =>{
1450
+ * console.log($div); // div => HTMLDivELement[]
1451
+ * })
1452
+ * Utils.waitNode(["div"],document).then( ([$div]) =>{
1453
+ * console.log($div); // div => HTMLDivELement[]
1454
+ * })
1455
+ */
1456
+ waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K][]>;
1457
+ waitNode<T extends Element[]>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
1458
+ /**
1459
+ * 等待元素出现
1460
+ * @param selector CSS选择器
1461
+ * @param parent 父元素,默认document
1462
+ * @param timeout 超时时间,默认0
1463
+ * @example
1464
+ * Utils.waitNode("div",document,1000).then( $div =>{
1465
+ * console.log($div); // $div => HTMLDivELement | null
1466
+ * })
1467
+ */
1468
+ waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1469
+ waitNode<T extends Element>(selector: string, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1470
+ /**
1471
+ * 等待元素出现
1472
+ * @param selectorList CSS选择器数组
1473
+ * @param parent 父元素,默认document
1474
+ * @param timeout 超时时间,默认0
1475
+ * @example
1476
+ * Utils.waitNode(["div"],document,1000).then( ([$div]) =>{
1477
+ * console.log($div); // $div => HTMLDivELement[] | null
1478
+ * })
1479
+ */
1480
+ waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1481
+ waitNode<T extends Element[]>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1482
+ /**
1483
+ * 等待元素出现
1484
+ * @param selector CSS选择器
1485
+ * @param timeout 超时时间,默认0
1486
+ * @example
1487
+ * Utils.waitNode("div",1000).then( $div =>{
1488
+ * console.log($div); // $div => HTMLDivELement | null
1489
+ * })
1490
+ */
1491
+ waitNode<K extends keyof HTMLElementTagNameMap>(selector: K, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1492
+ waitNode<T extends Element>(selector: string, timeout: number): Promise<T | null>;
1493
+ /**
1494
+ * 等待元素出现
1495
+ * @param selectorList CSS选择器数组
1496
+ * @param timeout 超时时间,默认0
1497
+ * @example
1498
+ * Utils.waitNode(["div"],1000).then( [$div] =>{
1499
+ * console.log($div); // $div => HTMLDivELement[] | null
1500
+ * })
1501
+ */
1502
+ waitNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1503
+ waitNode<T extends Element[]>(selectorList: string[], timeout: number): Promise<T | null>;
1504
+ /**
1505
+ * 等待任意元素出现
1506
+ * @param selectorList CSS选择器数组
1507
+ * @param parent (可选)监听的父元素
1508
+ * @example
1509
+ * Utils.waitAnyNode(["div","div"]).then( $div =>{
1510
+ * console.log($div); // $div => HTMLDivELement 这里是第一个
1511
+ * })
1512
+ * Utils.waitAnyNode(["a","div"],document).then( $a =>{
1513
+ * console.log($a); // $a => HTMLAnchorElement 这里是第一个
1514
+ * })
1515
+ */
1516
+ waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<HTMLElementTagNameMap[K]>;
1517
+ waitAnyNode<T extends Element>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
1518
+ /**
1519
+ * 等待任意元素出现
1520
+ * @param selectorList CSS选择器数组
1521
+ * @param parent 父元素,默认document
1522
+ * @param timeout 超时时间,默认0
1523
+ * @example
1524
+ * Utils.waitAnyNode(["div","div"],document,10000).then( $div =>{
1525
+ * console.log($div); // $div => HTMLDivELement | null
1526
+ * })
1527
+ */
1528
+ waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1529
+ waitAnyNode<T extends Element>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1530
+ /**
1531
+ * 等待任意元素出现
1532
+ * @param selectorList CSS选择器数组
1533
+ * @param timeout 超时时间,默认0
1534
+ * @example
1535
+ * Utils.waitAnyNode(["div","div"],10000).then( $div =>{
1536
+ * console.log($div); // $div => HTMLDivELement | null
1537
+ * })
1538
+ */
1539
+ waitAnyNode<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<HTMLElementTagNameMap[K] | null>;
1540
+ waitAnyNode<T extends Element>(selectorList: string[], timeout: number): Promise<T | null>;
1541
+ /**
1542
+ * 等待元素数组出现
1543
+ * @param selector CSS选择器
1544
+ * @param parent (可选)监听的父元素
1545
+ * @example
1546
+ * Utils.waitNodeList("div").then( $result =>{
1547
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>
1548
+ * })
1549
+ * Utils.waitNodeList("div",document).then( $result =>{
1550
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>
1551
+ * })
1552
+ */
1553
+ waitNodeList<T extends keyof HTMLElementTagNameMap>(selector: T, parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[T]>>;
1554
+ waitNodeList<T extends NodeListOf<Element>>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
1555
+ /**
1556
+ * 等待元素数组出现
1557
+ * @param selectorList CSS选择器数组
1558
+ * @param parent (可选)监听的父元素
1559
+ * @example
1560
+ * Utils.waitNodeList(["div"]).then( $result =>{
1561
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1562
+ * })
1563
+ * Utils.waitNodeList(["div"],document).then( $result =>{
1564
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>[]
1565
+ * })
1566
+ */
1567
+ waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[K]>[]>;
1568
+ waitNodeList<T extends NodeListOf<Element>[]>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<T>;
1569
+ /**
1570
+ * 等待元素数组出现
1571
+ * @param selector CSS选择器
1572
+ * @param parent 监听的父元素
1573
+ * @param timeout 超时时间,默认0
1574
+ * @example
1575
+ * Utils.waitNodeList("div",document,10000).then( $result =>{
1576
+ * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1577
+ * })
1578
+ */
1579
+ waitNodeList<T extends NodeListOf<Element>>(selector: string, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1580
+ waitNodeList<K extends keyof HTMLElementTagNameMap>(selector: K, parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1581
+ /**
1582
+ * 等待元素数组出现
1583
+ * @param selectorList CSS选择器数组
1584
+ * @param parent 监听的父元素
1585
+ * @param timeout 超时时间,默认0
1586
+ * @example
1587
+ * Utils.waitNodeList(["div"],document,10000).then( $result =>{
1588
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1589
+ * })
1590
+ */
1591
+ waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
1592
+ waitNodeList<T extends NodeListOf<Element>[]>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<T | null>;
1593
+ /**
1594
+ * 等待元素数组出现
1595
+ * @param selector CSS选择器数组
1596
+ * @param timeout 超时时间,默认0
1597
+ * @example
1598
+ * Utils.waitNodeList("div",10000).then( $result =>{
1599
+ * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1600
+ * })
1601
+ */
1602
+ waitNodeList<K extends keyof HTMLElementTagNameMap>(selector: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1603
+ waitNodeList<T extends NodeListOf<Element>>(selector: string[], timeout: number): Promise<T | null>;
1604
+ /**
1605
+ * 等待元素数组出现
1606
+ * @param selectorList CSS选择器数组
1607
+ * @param timeout 超时时间,默认0
1608
+ * @example
1609
+ * Utils.waitNodeList(["div"],10000).then( $result =>{
1610
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>[] | null
1611
+ * })
1612
+ */
1613
+ waitNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
1614
+ waitNodeList<T extends NodeListOf<Element>>(selectorList: string[], timeout: number): Promise<T[] | null>;
1615
+ /**
1616
+ * 等待任意元素数组出现
1617
+ * @param selectorList CSS选择器数组
1618
+ * @param parent (可选)监听的父元素
1619
+ * @example
1620
+ * Utils.waitAnyNodeList(["div","a"]).then( $result =>{
1621
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>
1622
+ * })
1623
+ * Utils.waitAnyNodeList(["div","a"],document).then( $result =>{
1624
+ * console.log($result); // $result => NodeListOf<HTMLDivElement>
1625
+ * })
1626
+ */
1627
+ waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<HTMLElementTagNameMap[K]>>;
1628
+ waitAnyNodeList<T extends Element>(selectorList: string[], parent?: Node | Element | Document | HTMLElement): Promise<NodeListOf<T>>;
1629
+ /**
1630
+ * 等待任意元素数组出现
1631
+ * @param selectorList CSS选择器数组
1632
+ * @param parent 父元素,默认document
1633
+ * @param timeout 超时时间,默认0
1634
+ * @example
1635
+ * Utils.waitAnyNodeList(["div","a"],document,10000).then( $result =>{
1636
+ * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1637
+ * })
1638
+ */
1639
+ waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1640
+ waitAnyNodeList<T extends Element>(selectorList: string[], parent: Node | Element | Document | HTMLElement, timeout: number): Promise<NodeListOf<T> | null>;
1641
+ /**
1642
+ * 等待任意元素出现
1643
+ * @param selectorList CSS选择器数组
1644
+ * @param timeout 超时时间,默认0
1645
+ * @example
1646
+ * Utils.waitAnyNodeList(["div","div"],10000).then( $result =>{
1647
+ * console.log($result); // $result => NodeListOf<HTMLDivElement> | null
1648
+ * })
1649
+ */
1650
+ waitAnyNodeList<K extends keyof HTMLElementTagNameMap>(selectorList: K[], timeout: number): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
1651
+ waitAnyNodeList<T extends Element>(selectorList: string[], timeout: number): Promise<NodeListOf<T> | null>;
1652
+ /**
1653
+ * 等待对象上的属性出现
1654
+ * @param checkObj 检查的对象
1655
+ * @param checkPropertyName 检查的对象的属性名
1656
+ * @example
1657
+ * await Utils.waitProperty(window,"test");
1658
+ * console.log("test success set");
1659
+ *
1660
+ * window.test = 1;
1661
+ * > "test success set"
1662
+ *
1663
+ */
1664
+ waitProperty<T extends any>(checkObj: any | (() => any), checkPropertyName: string): Promise<T>;
1665
+ /**
1666
+ * 在规定时间内等待对象上的属性出现
1667
+ * @param checkObj 检查的对象
1668
+ * @param checkPropertyName 检查的对象的属性名
1669
+ * @param intervalTimer (可选)检查间隔时间(ms),默认250ms
1670
+ * @param maxTime (可选)限制在多长时间内,默认-1(不限制时间)
1671
+ * @example
1672
+ * await Utils.waitPropertyByInterval(window,"test");
1673
+ * console.log("test success set");
1674
+ */
1675
+ waitPropertyByInterval<T extends any>(checkObj: any | (() => any), checkPropertyName: string | ((obj: any) => boolean), intervalTimer?: number, maxTime?: number): Promise<T>;
1676
+ /**
1677
+ * 在规定时间内等待元素上的__vue__属性或者__vue__属性上的某个值出现出现
1678
+ * @param element 目标元素
1679
+ * @param propertyName (可选)vue上的属性名或者传递一个获取属性的方法返回boolean
1680
+ * @param timer (可选)间隔时间(ms),默认:250(ms)
1681
+ * @param maxTime(可选) 限制在多长时间内,默认:-1(不限制时间)
1682
+ * @param vueName (可选)vue挂载的属性名,默认:__vue__
1683
+ * @example
1684
+ * await Utils.waitVueByInterval(
1685
+ * function(){
1686
+ * return document.querySelector("a.xx")
1687
+ * },
1688
+ * function(__vue__){
1689
+ * return Boolean(__vue__.xxx == null);
1690
+ * },
1691
+ * 250,
1692
+ * 10000,
1693
+ * "__vue__"
1694
+ * )
1695
+ */
1696
+ waitVueByInterval(element: HTMLElement | (() => any), propertyName: string | ((__vue__: any) => boolean), timer?: number, maxTime?: number, vueName?: "__vue__" | string): Promise<boolean>;
1697
+ /**
1698
+ * 观察对象的set、get
1699
+ * @param target 观察的对象
1700
+ * @param propertyName 观察的对象的属性名
1701
+ * @param getCallBack (可选)触发get的回调,可以自定义返回特定值
1702
+ * @param setCallBack (可选)触发set的回调,参数为将要设置的value
1703
+ * @example
1704
+ * Utils.watchObject(window,"test",()=>{return 111;},(value)=>{console.log("test出现,值是",value)});
1705
+ *
1706
+ * window.test = 1;
1707
+ * > test出现,值是 1
1708
+ * console.log(window.test);
1709
+ * > 111;
1710
+ */
1711
+ watchObject(target: any, propertyName: string, getCallBack: (value: any) => void, setCallBack: (value: any) => void): void;
1712
+ /**
1713
+ * 创建一个新的Utils实例
1714
+ * @param option
1715
+ * @returns
1716
+ */
1717
+ createUtils(option?: UtilsWindowApiOption): Utils;
1718
+ /**
1719
+ * 将对象转换为FormData
1720
+ * @param data 待转换的对象
1721
+ * @param isEncode 是否对值为string进行编码转换(encodeURIComponent),默认false
1722
+ * @param valueAutoParseToStr 是否对值强制使用JSON.stringify()转换,默认false
1723
+ * @example
1724
+ * Utils.toFormData({
1725
+ * test: "1",
1726
+ * 666: 666,
1727
+ * })
1728
+ */
1729
+ toFormData(data: {
1730
+ [key: string]: string | Blob | File | number;
1731
+ }, isEncode?: boolean, valueAutoParseToStr?: boolean): FormData;
1732
+ /**
1733
+ * 将链接转为URL对象,自动补充URL的protocol或者origin
1734
+ * @param text 需要转换的链接字符串
1735
+ * @example
1736
+ * Utils.toUrl("//www.baidu.com/s?word=666");
1737
+ * Utils.toUrl("/s?word=666");
1738
+ */
1739
+ toUrl(text: string): URL;
1740
+ /**
1741
+ * 生成uuid
1742
+ * @example
1743
+ * Utils.generateUUID()
1744
+ */
1745
+ generateUUID: () => string;
1746
+ /**
1747
+ * 自定义的动态响应对象
1748
+ */
1749
+ Vue: typeof Vue;
1750
+ }
1751
+ declare let utils: Utils;
1752
+ export { utils as Utils };