@whitesev/utils 2.3.0 → 2.3.1
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.
- package/dist/index.amd.js +92 -56
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +92 -56
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +92 -56
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +92 -56
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +92 -56
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +92 -56
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +1273 -1273
- package/dist/types/src/Log.d.ts +96 -96
- package/dist/types/src/Utils.d.ts +1752 -1752
- package/dist/types/src/VueObject.d.ts +110 -110
- package/package.json +1 -1
- package/src/Httpx.ts +114 -71
|
@@ -1,1752 +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
|
-
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
|
-
* + WOW64:Windows-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 (默认)倒序(值最大排第一个,如:6、5、4、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 };
|
|
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
|
+
* + WOW64:Windows-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 (默认)倒序(值最大排第一个,如:6、5、4、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 };
|