@whitesev/utils 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js +183 -173
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +183 -173
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +183 -173
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +183 -173
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +183 -173
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +183 -173
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +5 -4
- package/dist/types/src/UtilsGMCookie.d.ts +6 -0
- package/dist/types/src/UtilsWindowApi.d.ts +22 -0
- package/dist/types/src/types/global.d.ts +1 -0
- package/package.json +2 -1
- package/src/Httpx.ts +3 -5
- package/src/Log.ts +1 -2
- package/src/Progress.ts +4 -10
- package/src/Utils.ts +139 -111
- package/src/UtilsCommon.ts +2 -4
- package/src/UtilsGMCookie.ts +29 -16
- package/src/UtilsGMMenu.ts +1 -2
- package/src/UtilsWindowApi.ts +44 -0
- package/src/indexedDB.ts +4 -6
- package/src/types/global.d.ts +1 -0
- package/dist/types/src/UtilsCore.d.ts +0 -16
- package/src/UtilsCore.ts +0 -47
package/dist/index.umd.js
CHANGED
|
@@ -230,45 +230,16 @@
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
const UtilsCoreDefaultEnv = {
|
|
234
|
-
document: document,
|
|
235
|
-
window: window,
|
|
236
|
-
globalThis: globalThis,
|
|
237
|
-
self: self,
|
|
238
|
-
top: top,
|
|
239
|
-
};
|
|
240
|
-
const UtilsCoreEnv = {
|
|
241
|
-
document: document,
|
|
242
|
-
window: window,
|
|
243
|
-
globalThis: globalThis,
|
|
244
|
-
self: self,
|
|
245
|
-
top: top,
|
|
246
|
-
};
|
|
247
|
-
const UtilsCore = {
|
|
248
|
-
init(option) {
|
|
249
|
-
if (!option) {
|
|
250
|
-
option = Object.assign({}, UtilsCoreDefaultEnv);
|
|
251
|
-
}
|
|
252
|
-
Object.assign(UtilsCoreEnv, option);
|
|
253
|
-
},
|
|
254
|
-
get document() {
|
|
255
|
-
return UtilsCoreEnv.document;
|
|
256
|
-
},
|
|
257
|
-
get window() {
|
|
258
|
-
return UtilsCoreEnv.window;
|
|
259
|
-
},
|
|
260
|
-
get globalThis() {
|
|
261
|
-
return UtilsCoreEnv.globalThis;
|
|
262
|
-
},
|
|
263
|
-
get self() {
|
|
264
|
-
return UtilsCoreEnv.self;
|
|
265
|
-
},
|
|
266
|
-
get top() {
|
|
267
|
-
return UtilsCoreEnv.top;
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
|
|
271
233
|
class UtilsGMCookie {
|
|
234
|
+
windowApi = {
|
|
235
|
+
window: window,
|
|
236
|
+
document: document,
|
|
237
|
+
};
|
|
238
|
+
constructor(windowApiOption) {
|
|
239
|
+
if (windowApiOption) {
|
|
240
|
+
this.windowApi = Object.assign({}, windowApiOption);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
272
243
|
/**
|
|
273
244
|
* 获取单个cookie
|
|
274
245
|
* @param cookieName cookie名
|
|
@@ -277,7 +248,7 @@
|
|
|
277
248
|
if (typeof cookieName !== "string") {
|
|
278
249
|
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
279
250
|
}
|
|
280
|
-
let cookies =
|
|
251
|
+
let cookies = this.windowApi.document.cookie.split(";");
|
|
281
252
|
let findValue = void 0;
|
|
282
253
|
for (const cookieItem of cookies) {
|
|
283
254
|
let item = cookieItem.trim();
|
|
@@ -287,7 +258,7 @@
|
|
|
287
258
|
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
288
259
|
if (itemName === cookieName) {
|
|
289
260
|
findValue = {
|
|
290
|
-
domain:
|
|
261
|
+
domain: this.windowApi.window.location.hostname,
|
|
291
262
|
expirationDate: null,
|
|
292
263
|
hostOnly: true,
|
|
293
264
|
httpOnly: false,
|
|
@@ -317,13 +288,13 @@
|
|
|
317
288
|
let resultData = [];
|
|
318
289
|
try {
|
|
319
290
|
let details = {
|
|
320
|
-
url:
|
|
321
|
-
domain:
|
|
291
|
+
url: this.windowApi.window.location.href,
|
|
292
|
+
domain: this.windowApi.window.location.hostname,
|
|
322
293
|
name: "",
|
|
323
294
|
path: "/",
|
|
324
295
|
};
|
|
325
296
|
details = utils.assign(details, paramDetails);
|
|
326
|
-
let cookies =
|
|
297
|
+
let cookies = this.windowApi.document.cookie.split(";");
|
|
327
298
|
cookies.forEach((item) => {
|
|
328
299
|
item = item.trim();
|
|
329
300
|
let itemSplit = item.split("=");
|
|
@@ -335,7 +306,7 @@
|
|
|
335
306
|
: new RegExp("^" + details.name, "g");
|
|
336
307
|
if (itemName.match(nameRegexp)) {
|
|
337
308
|
resultData.push({
|
|
338
|
-
domain:
|
|
309
|
+
domain: this.windowApi.window.location.hostname,
|
|
339
310
|
expirationDate: null,
|
|
340
311
|
hostOnly: true,
|
|
341
312
|
httpOnly: false,
|
|
@@ -368,13 +339,13 @@
|
|
|
368
339
|
}
|
|
369
340
|
let resultData = [];
|
|
370
341
|
let details = {
|
|
371
|
-
url:
|
|
372
|
-
domain:
|
|
342
|
+
url: this.windowApi.window.location.href,
|
|
343
|
+
domain: this.windowApi.window.location.hostname,
|
|
373
344
|
name: "",
|
|
374
345
|
path: "/",
|
|
375
346
|
};
|
|
376
347
|
details = utils.assign(details, paramDetails);
|
|
377
|
-
let cookies =
|
|
348
|
+
let cookies = this.windowApi.document.cookie.split(";");
|
|
378
349
|
cookies.forEach((item) => {
|
|
379
350
|
item = item.trim();
|
|
380
351
|
let itemSplit = item.split("=");
|
|
@@ -386,7 +357,7 @@
|
|
|
386
357
|
: new RegExp("^" + details.name, "g");
|
|
387
358
|
if (itemName.match(nameRegexp)) {
|
|
388
359
|
resultData.push({
|
|
389
|
-
domain:
|
|
360
|
+
domain: this.windowApi.window.location.hostname,
|
|
390
361
|
expirationDate: null,
|
|
391
362
|
hostOnly: true,
|
|
392
363
|
httpOnly: false,
|
|
@@ -409,10 +380,10 @@
|
|
|
409
380
|
set(paramDetails, callback = (error) => { }) {
|
|
410
381
|
try {
|
|
411
382
|
let details = {
|
|
412
|
-
url:
|
|
383
|
+
url: this.windowApi.window.location.href,
|
|
413
384
|
name: "",
|
|
414
385
|
value: "",
|
|
415
|
-
domain:
|
|
386
|
+
domain: this.windowApi.window.location.hostname,
|
|
416
387
|
path: "/",
|
|
417
388
|
secure: true,
|
|
418
389
|
httpOnly: false,
|
|
@@ -431,7 +402,7 @@
|
|
|
431
402
|
";expires=" +
|
|
432
403
|
new Date(life).toGMTString() +
|
|
433
404
|
"; path=/";
|
|
434
|
-
|
|
405
|
+
this.windowApi.document.cookie = cookieStr;
|
|
435
406
|
callback();
|
|
436
407
|
}
|
|
437
408
|
catch (error) {
|
|
@@ -446,14 +417,14 @@
|
|
|
446
417
|
delete(paramDetails, callback = (error) => { }) {
|
|
447
418
|
try {
|
|
448
419
|
let details = {
|
|
449
|
-
url:
|
|
420
|
+
url: this.windowApi.window.location.href,
|
|
450
421
|
name: "",
|
|
451
422
|
// @ts-ignore
|
|
452
423
|
firstPartyDomain: "",
|
|
453
424
|
};
|
|
454
425
|
details = utils.assign(details, paramDetails);
|
|
455
426
|
let cookieStr = details.name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
456
|
-
|
|
427
|
+
this.windowApi.document.cookie = cookieStr;
|
|
457
428
|
callback();
|
|
458
429
|
}
|
|
459
430
|
catch (error) {
|
|
@@ -1223,7 +1194,7 @@
|
|
|
1223
1194
|
}
|
|
1224
1195
|
/* 不刷新网页就刷新菜单 */
|
|
1225
1196
|
if (menuOption.autoReload) {
|
|
1226
|
-
|
|
1197
|
+
window.location.reload();
|
|
1227
1198
|
}
|
|
1228
1199
|
else {
|
|
1229
1200
|
that.context.update();
|
|
@@ -1542,8 +1513,8 @@
|
|
|
1542
1513
|
* 生成uuid
|
|
1543
1514
|
*/
|
|
1544
1515
|
const GenerateUUID = function () {
|
|
1545
|
-
if (typeof
|
|
1546
|
-
return
|
|
1516
|
+
if (typeof window?.crypto?.randomUUID === "function") {
|
|
1517
|
+
return window.crypto.randomUUID();
|
|
1547
1518
|
}
|
|
1548
1519
|
else {
|
|
1549
1520
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
@@ -1915,14 +1886,13 @@
|
|
|
1915
1886
|
}
|
|
1916
1887
|
catch (error) {
|
|
1917
1888
|
if (details.url.startsWith("//")) {
|
|
1918
|
-
details.url =
|
|
1889
|
+
details.url = window.location.protocol + details.url;
|
|
1919
1890
|
}
|
|
1920
1891
|
else if (details.url.startsWith("/")) {
|
|
1921
|
-
details.url =
|
|
1892
|
+
details.url = window.location.origin + details.url;
|
|
1922
1893
|
}
|
|
1923
1894
|
else {
|
|
1924
|
-
details.url =
|
|
1925
|
-
UtilsCore.globalThis.location.origin + "/" + details.url;
|
|
1895
|
+
details.url = window.location.origin + "/" + details.url;
|
|
1926
1896
|
}
|
|
1927
1897
|
}
|
|
1928
1898
|
return details;
|
|
@@ -2548,10 +2518,10 @@
|
|
|
2548
2518
|
// @ts-ignore
|
|
2549
2519
|
#slqVersion = "1";
|
|
2550
2520
|
/* 监听IndexDB */
|
|
2551
|
-
#indexedDB =
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2521
|
+
#indexedDB = window.indexedDB ||
|
|
2522
|
+
window.mozIndexedDB ||
|
|
2523
|
+
window.webkitIndexedDB ||
|
|
2524
|
+
window.msIndexedDB;
|
|
2555
2525
|
/* 缓存数据库,避免同一个页面重复创建和销毁 */
|
|
2556
2526
|
#db = {};
|
|
2557
2527
|
// @ts-ignore
|
|
@@ -2981,7 +2951,7 @@
|
|
|
2981
2951
|
* @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
|
|
2982
2952
|
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
2983
2953
|
*/
|
|
2984
|
-
constructor(_GM_info_, console =
|
|
2954
|
+
constructor(_GM_info_, console = window.console) {
|
|
2985
2955
|
if (typeof _GM_info_ === "string") {
|
|
2986
2956
|
this.tag = _GM_info_;
|
|
2987
2957
|
}
|
|
@@ -3242,14 +3212,12 @@
|
|
|
3242
3212
|
/* 元素高度 */
|
|
3243
3213
|
this.#height = this.#config.canvasNode.height;
|
|
3244
3214
|
/* 清除锯齿 */
|
|
3245
|
-
if (
|
|
3215
|
+
if (window.devicePixelRatio) {
|
|
3246
3216
|
this.#config.canvasNode.style.width = this.#width + "px";
|
|
3247
3217
|
this.#config.canvasNode.style.height = this.#height + "px";
|
|
3248
|
-
this.#config.canvasNode.height =
|
|
3249
|
-
|
|
3250
|
-
this.#
|
|
3251
|
-
this.#width * UtilsCore.window.devicePixelRatio;
|
|
3252
|
-
this.#ctx.scale(UtilsCore.window.devicePixelRatio, UtilsCore.window.devicePixelRatio);
|
|
3218
|
+
this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
|
|
3219
|
+
this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
|
|
3220
|
+
this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
|
3253
3221
|
}
|
|
3254
3222
|
/* 设置线宽 */
|
|
3255
3223
|
this.#ctx.lineWidth = this.#config.lineWidth;
|
|
@@ -3518,9 +3486,44 @@
|
|
|
3518
3486
|
}
|
|
3519
3487
|
}
|
|
3520
3488
|
|
|
3489
|
+
class UtilsWindowApi {
|
|
3490
|
+
/** 默认的配置 */
|
|
3491
|
+
defaultApi = {
|
|
3492
|
+
document: document,
|
|
3493
|
+
window: window,
|
|
3494
|
+
globalThis: globalThis,
|
|
3495
|
+
self: self,
|
|
3496
|
+
top: top,
|
|
3497
|
+
};
|
|
3498
|
+
/** 使用的配置 */
|
|
3499
|
+
api;
|
|
3500
|
+
constructor(option) {
|
|
3501
|
+
if (!option) {
|
|
3502
|
+
option = Object.assign({}, this.defaultApi);
|
|
3503
|
+
}
|
|
3504
|
+
this.api = Object.assign({}, option);
|
|
3505
|
+
}
|
|
3506
|
+
get document() {
|
|
3507
|
+
return this.api.document;
|
|
3508
|
+
}
|
|
3509
|
+
get window() {
|
|
3510
|
+
return this.api.window;
|
|
3511
|
+
}
|
|
3512
|
+
get globalThis() {
|
|
3513
|
+
return this.api.globalThis;
|
|
3514
|
+
}
|
|
3515
|
+
get self() {
|
|
3516
|
+
return this.api.self;
|
|
3517
|
+
}
|
|
3518
|
+
get top() {
|
|
3519
|
+
return this.api.top;
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3521
3523
|
class Utils {
|
|
3524
|
+
windowApi;
|
|
3522
3525
|
constructor(option) {
|
|
3523
|
-
|
|
3526
|
+
this.windowApi = new UtilsWindowApi(option);
|
|
3524
3527
|
}
|
|
3525
3528
|
/** 版本号 */
|
|
3526
3529
|
version = "2024.7.20";
|
|
@@ -3528,24 +3531,24 @@
|
|
|
3528
3531
|
if (typeof cssText !== "string") {
|
|
3529
3532
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
3530
3533
|
}
|
|
3531
|
-
let cssNode =
|
|
3534
|
+
let cssNode = this.windowApi.document.createElement("style");
|
|
3532
3535
|
cssNode.setAttribute("type", "text/css");
|
|
3533
3536
|
cssNode.innerHTML = cssText;
|
|
3534
|
-
if (
|
|
3537
|
+
if (this.windowApi.document.head) {
|
|
3535
3538
|
/* 插入head最后 */
|
|
3536
|
-
|
|
3539
|
+
this.windowApi.document.head.appendChild(cssNode);
|
|
3537
3540
|
}
|
|
3538
|
-
else if (
|
|
3541
|
+
else if (this.windowApi.document.body) {
|
|
3539
3542
|
/* 插入body后 */
|
|
3540
|
-
|
|
3543
|
+
this.windowApi.document.body.appendChild(cssNode);
|
|
3541
3544
|
}
|
|
3542
|
-
else if (
|
|
3545
|
+
else if (this.windowApi.document.documentElement.childNodes.length === 0) {
|
|
3543
3546
|
/* 插入#html第一个元素后 */
|
|
3544
|
-
|
|
3547
|
+
this.windowApi.document.documentElement.appendChild(cssNode);
|
|
3545
3548
|
}
|
|
3546
3549
|
else {
|
|
3547
3550
|
/* 插入head前面 */
|
|
3548
|
-
|
|
3551
|
+
this.windowApi.document.documentElement.insertBefore(cssNode, this.windowApi.document.documentElement.childNodes[0]);
|
|
3549
3552
|
}
|
|
3550
3553
|
return cssNode;
|
|
3551
3554
|
}
|
|
@@ -3676,7 +3679,7 @@
|
|
|
3676
3679
|
let elementPosXRight = Number(element.getBoundingClientRect().right); /* 要检测的元素的相对屏幕的横坐标最右边 */
|
|
3677
3680
|
let elementPosYTop = Number(element.getBoundingClientRect().top); /* 要检测的元素的相对屏幕的纵坐标最上边 */
|
|
3678
3681
|
let elementPosYBottom = Number(element.getBoundingClientRect().bottom); /* 要检测的元素的相对屏幕的纵坐标最下边 */
|
|
3679
|
-
let clickNodeHTML =
|
|
3682
|
+
let clickNodeHTML = this.windowApi.window.event.target
|
|
3680
3683
|
.innerHTML;
|
|
3681
3684
|
if (mouseClickPosX >= elementPosXLeft &&
|
|
3682
3685
|
mouseClickPosX <= elementPosXRight &&
|
|
@@ -3805,18 +3808,18 @@
|
|
|
3805
3808
|
}
|
|
3806
3809
|
if (isIFrame) {
|
|
3807
3810
|
/* 使用iframe */
|
|
3808
|
-
const iframeElement =
|
|
3811
|
+
const iframeElement = this.windowApi.document.createElement("iframe");
|
|
3809
3812
|
iframeElement.style.display = "none";
|
|
3810
3813
|
iframeElement.src = base64Data;
|
|
3811
|
-
|
|
3814
|
+
this.windowApi.document.body.appendChild(iframeElement);
|
|
3812
3815
|
setTimeout(() => {
|
|
3813
3816
|
iframeElement.contentWindow.document.execCommand("SaveAs", true, fileName);
|
|
3814
|
-
|
|
3817
|
+
this.windowApi.document.body.removeChild(iframeElement);
|
|
3815
3818
|
}, 100);
|
|
3816
3819
|
}
|
|
3817
3820
|
else {
|
|
3818
3821
|
/* 使用A标签 */
|
|
3819
|
-
const linkElement =
|
|
3822
|
+
const linkElement = this.windowApi.document.createElement("a");
|
|
3820
3823
|
linkElement.setAttribute("target", "_blank");
|
|
3821
3824
|
linkElement.download = fileName;
|
|
3822
3825
|
linkElement.href = base64Data;
|
|
@@ -3826,13 +3829,13 @@
|
|
|
3826
3829
|
findWebPageVisibleText(str = "", caseSensitive = false) {
|
|
3827
3830
|
let TRange = null;
|
|
3828
3831
|
let strFound;
|
|
3829
|
-
if (
|
|
3832
|
+
if (this.windowApi.globalThis.find) {
|
|
3830
3833
|
/* CODE FOR BROWSERS THAT SUPPORT window.find */
|
|
3831
|
-
let windowFind =
|
|
3834
|
+
let windowFind = this.windowApi.self.find;
|
|
3832
3835
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
3833
3836
|
if (strFound &&
|
|
3834
|
-
|
|
3835
|
-
!
|
|
3837
|
+
this.windowApi.self.getSelection &&
|
|
3838
|
+
!this.windowApi.self.getSelection().anchorNode) {
|
|
3836
3839
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
3837
3840
|
}
|
|
3838
3841
|
if (!strFound) {
|
|
@@ -3851,7 +3854,7 @@
|
|
|
3851
3854
|
TRange.select();
|
|
3852
3855
|
}
|
|
3853
3856
|
if (TRange == null || strFound == 0) {
|
|
3854
|
-
TRange =
|
|
3857
|
+
TRange = this.windowApi.self.document.body.createTextRange();
|
|
3855
3858
|
strFound = TRange.findText(str);
|
|
3856
3859
|
if (strFound)
|
|
3857
3860
|
TRange.select();
|
|
@@ -4227,8 +4230,8 @@
|
|
|
4227
4230
|
let maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
4228
4231
|
// 当前页面最大的z-index
|
|
4229
4232
|
let zIndex = 0;
|
|
4230
|
-
|
|
4231
|
-
let nodeStyle =
|
|
4233
|
+
this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
|
|
4234
|
+
let nodeStyle = this.windowApi.window.getComputedStyle($ele);
|
|
4232
4235
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
4233
4236
|
if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
|
|
4234
4237
|
let nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
@@ -4442,7 +4445,7 @@
|
|
|
4442
4445
|
if (url.trim() === "") {
|
|
4443
4446
|
throw new TypeError("url不能为空字符串或纯空格");
|
|
4444
4447
|
}
|
|
4445
|
-
return `thunder://${
|
|
4448
|
+
return `thunder://${this.windowApi.globalThis.btoa("AA" + url + "ZZ")}`;
|
|
4446
4449
|
}
|
|
4447
4450
|
/**
|
|
4448
4451
|
* 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
|
|
@@ -4657,21 +4660,21 @@
|
|
|
4657
4660
|
return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
|
|
4658
4661
|
}
|
|
4659
4662
|
isNearBottom(nearValue = 50) {
|
|
4660
|
-
var scrollTop =
|
|
4661
|
-
|
|
4662
|
-
var windowHeight =
|
|
4663
|
-
|
|
4664
|
-
var documentHeight =
|
|
4663
|
+
var scrollTop = this.windowApi.window.pageYOffset ||
|
|
4664
|
+
this.windowApi.document.documentElement.scrollTop;
|
|
4665
|
+
var windowHeight = this.windowApi.window.innerHeight ||
|
|
4666
|
+
this.windowApi.document.documentElement.clientHeight;
|
|
4667
|
+
var documentHeight = this.windowApi.document.documentElement.scrollHeight;
|
|
4665
4668
|
return scrollTop + windowHeight >= documentHeight - nearValue;
|
|
4666
4669
|
}
|
|
4667
4670
|
isDOM(target) {
|
|
4668
4671
|
return target instanceof Node;
|
|
4669
4672
|
}
|
|
4670
4673
|
isFullscreenEnabled() {
|
|
4671
|
-
return !!(
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4674
|
+
return !!(this.windowApi.document.fullscreenEnabled ||
|
|
4675
|
+
this.windowApi.document.webkitFullScreenEnabled ||
|
|
4676
|
+
this.windowApi.document.mozFullScreenEnabled ||
|
|
4677
|
+
this.windowApi.document.msFullScreenEnabled);
|
|
4675
4678
|
}
|
|
4676
4679
|
isJQuery(target) {
|
|
4677
4680
|
let result = false;
|
|
@@ -4904,7 +4907,7 @@
|
|
|
4904
4907
|
return result;
|
|
4905
4908
|
}
|
|
4906
4909
|
isThemeDark() {
|
|
4907
|
-
return
|
|
4910
|
+
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
4908
4911
|
.matches;
|
|
4909
4912
|
}
|
|
4910
4913
|
isVisible(element, inView = false) {
|
|
@@ -4918,17 +4921,17 @@
|
|
|
4918
4921
|
}
|
|
4919
4922
|
let result = true;
|
|
4920
4923
|
for (const domItem of needCheckDomList) {
|
|
4921
|
-
let domDisplay =
|
|
4924
|
+
let domDisplay = this.windowApi.window.getComputedStyle(domItem);
|
|
4922
4925
|
if (domDisplay.display === "none") {
|
|
4923
4926
|
result = false;
|
|
4924
4927
|
}
|
|
4925
4928
|
else {
|
|
4926
4929
|
let domClientRect = domItem.getBoundingClientRect();
|
|
4927
4930
|
if (inView) {
|
|
4928
|
-
let viewportWidth =
|
|
4929
|
-
|
|
4930
|
-
let viewportHeight =
|
|
4931
|
-
|
|
4931
|
+
let viewportWidth = this.windowApi.window.innerWidth ||
|
|
4932
|
+
this.windowApi.document.documentElement.clientWidth;
|
|
4933
|
+
let viewportHeight = this.windowApi.window.innerHeight ||
|
|
4934
|
+
this.windowApi.document.documentElement.clientHeight;
|
|
4932
4935
|
result = !(domClientRect.right < 0 ||
|
|
4933
4936
|
domClientRect.left > viewportWidth ||
|
|
4934
4937
|
domClientRect.bottom < 0 ||
|
|
@@ -4948,10 +4951,10 @@
|
|
|
4948
4951
|
isWebView_Via() {
|
|
4949
4952
|
let result = true;
|
|
4950
4953
|
let UtilsContext = this;
|
|
4951
|
-
if (typeof
|
|
4952
|
-
for (const key in Object.values(
|
|
4953
|
-
if (Reflect.has(
|
|
4954
|
-
let objValueFunc =
|
|
4954
|
+
if (typeof this.windowApi.top.window.via === "object") {
|
|
4955
|
+
for (const key in Object.values(this.windowApi.top.window.via)) {
|
|
4956
|
+
if (Reflect.has(this.windowApi.top.window.via, key)) {
|
|
4957
|
+
let objValueFunc = this.windowApi.top.window.via[key];
|
|
4955
4958
|
if (typeof objValueFunc === "function" &&
|
|
4956
4959
|
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
4957
4960
|
result = true;
|
|
@@ -4971,10 +4974,10 @@
|
|
|
4971
4974
|
isWebView_X() {
|
|
4972
4975
|
let result = true;
|
|
4973
4976
|
let UtilsContext = this;
|
|
4974
|
-
if (typeof
|
|
4975
|
-
for (const key in Object.values(
|
|
4976
|
-
if (Reflect.has(
|
|
4977
|
-
let objValueFunc =
|
|
4977
|
+
if (typeof this.windowApi.top.window.mbrowser === "object") {
|
|
4978
|
+
for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
|
|
4979
|
+
if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
|
|
4980
|
+
let objValueFunc = this.windowApi.top.window.mbrowser[key];
|
|
4978
4981
|
if (typeof objValueFunc === "function" &&
|
|
4979
4982
|
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
4980
4983
|
result = true;
|
|
@@ -5146,9 +5149,9 @@
|
|
|
5146
5149
|
immediate: false,
|
|
5147
5150
|
};
|
|
5148
5151
|
observer_config = UtilsContext.assign(default_obverser_config, observer_config);
|
|
5149
|
-
let windowMutationObserver =
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
+
let windowMutationObserver = this.windowApi.window.MutationObserver ||
|
|
5153
|
+
this.windowApi.window.webkitMutationObserver ||
|
|
5154
|
+
this.windowApi.window.MozMutationObserver;
|
|
5152
5155
|
// 观察者对象
|
|
5153
5156
|
let mutationObserver = new windowMutationObserver(function (mutations, observer) {
|
|
5154
5157
|
if (typeof observer_config.callback === "function") {
|
|
@@ -5184,13 +5187,13 @@
|
|
|
5184
5187
|
* let utils = Utils.noConflict();
|
|
5185
5188
|
* > ...
|
|
5186
5189
|
*/
|
|
5187
|
-
noConflict
|
|
5188
|
-
if (
|
|
5189
|
-
Reflect.deleteProperty(
|
|
5190
|
+
noConflict() {
|
|
5191
|
+
if (this.windowApi.window.Utils) {
|
|
5192
|
+
Reflect.deleteProperty(this.windowApi.window, "Utils");
|
|
5190
5193
|
}
|
|
5191
|
-
|
|
5194
|
+
this.windowApi.window.Utils = utils;
|
|
5192
5195
|
return utils;
|
|
5193
|
-
}
|
|
5196
|
+
}
|
|
5194
5197
|
noConflictFunc(needReleaseObject, needReleaseName, functionNameList = [], release = true) {
|
|
5195
5198
|
let UtilsContext = this;
|
|
5196
5199
|
if (typeof needReleaseObject !== "object") {
|
|
@@ -5207,11 +5210,12 @@
|
|
|
5207
5210
|
* 释放所有
|
|
5208
5211
|
*/
|
|
5209
5212
|
function releaseAll() {
|
|
5210
|
-
if (typeof
|
|
5213
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] !==
|
|
5214
|
+
"undefined") {
|
|
5211
5215
|
/* 已存在 */
|
|
5212
5216
|
return;
|
|
5213
5217
|
}
|
|
5214
|
-
|
|
5218
|
+
UtilsContext.windowApi.window[needReleaseKey] =
|
|
5215
5219
|
UtilsContext.deepClone(needReleaseObject);
|
|
5216
5220
|
Object.values(needReleaseObject).forEach((value) => {
|
|
5217
5221
|
if (typeof value === "function") {
|
|
@@ -5226,11 +5230,12 @@
|
|
|
5226
5230
|
Array.from(functionNameList).forEach((item) => {
|
|
5227
5231
|
Object.values(needReleaseObject).forEach((value) => {
|
|
5228
5232
|
if (typeof value === "function") {
|
|
5229
|
-
if (typeof
|
|
5230
|
-
|
|
5233
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
5234
|
+
"undefined") {
|
|
5235
|
+
UtilsContext.windowApi.window[needReleaseKey] = {};
|
|
5231
5236
|
}
|
|
5232
5237
|
if (item === value.name) {
|
|
5233
|
-
|
|
5238
|
+
UtilsContext.windowApi.window[needReleaseKey][value.name] = needReleaseObject[value.name];
|
|
5234
5239
|
needReleaseObject[value.name] = () => { };
|
|
5235
5240
|
}
|
|
5236
5241
|
}
|
|
@@ -5241,26 +5246,29 @@
|
|
|
5241
5246
|
* 恢复所有
|
|
5242
5247
|
*/
|
|
5243
5248
|
function recoveryAll() {
|
|
5244
|
-
if (typeof
|
|
5249
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
5250
|
+
"undefined") {
|
|
5245
5251
|
/* 未存在 */
|
|
5246
5252
|
return;
|
|
5247
5253
|
}
|
|
5248
|
-
Object.assign(needReleaseObject,
|
|
5249
|
-
Reflect.deleteProperty(
|
|
5254
|
+
Object.assign(needReleaseObject, UtilsContext.windowApi.window[needReleaseKey]);
|
|
5255
|
+
Reflect.deleteProperty(UtilsContext.windowApi.window, "needReleaseKey");
|
|
5250
5256
|
}
|
|
5251
5257
|
/**
|
|
5252
5258
|
* 恢复单个
|
|
5253
5259
|
*/
|
|
5254
5260
|
function recoveryOne() {
|
|
5255
|
-
if (typeof
|
|
5261
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
5262
|
+
"undefined") {
|
|
5256
5263
|
/* 未存在 */
|
|
5257
5264
|
return;
|
|
5258
5265
|
}
|
|
5259
5266
|
Array.from(functionNameList).forEach((item) => {
|
|
5260
|
-
if (
|
|
5261
|
-
needReleaseObject[item] =
|
|
5262
|
-
Reflect.deleteProperty(
|
|
5263
|
-
if (Object.keys(
|
|
5267
|
+
if (UtilsContext.windowApi.window[needReleaseKey][item]) {
|
|
5268
|
+
needReleaseObject[item] = UtilsContext.windowApi.window[needReleaseKey][item];
|
|
5269
|
+
Reflect.deleteProperty(UtilsContext.windowApi.window[needReleaseKey], item);
|
|
5270
|
+
if (Object.keys(UtilsContext.windowApi.window[needReleaseKey])
|
|
5271
|
+
.length === 0) {
|
|
5264
5272
|
Reflect.deleteProperty(window, needReleaseKey);
|
|
5265
5273
|
}
|
|
5266
5274
|
}
|
|
@@ -5466,7 +5474,7 @@
|
|
|
5466
5474
|
return isNegative ? -reversedNum : reversedNum;
|
|
5467
5475
|
}
|
|
5468
5476
|
selectElementText(element, childTextNode, startIndex, endIndex) {
|
|
5469
|
-
let range =
|
|
5477
|
+
let range = this.windowApi.document.createRange();
|
|
5470
5478
|
range.selectNodeContents(element);
|
|
5471
5479
|
if (childTextNode) {
|
|
5472
5480
|
if (childTextNode.nodeType !== Node.TEXT_NODE) {
|
|
@@ -5477,7 +5485,7 @@
|
|
|
5477
5485
|
range.setEnd(childTextNode, endIndex);
|
|
5478
5486
|
}
|
|
5479
5487
|
}
|
|
5480
|
-
let selection =
|
|
5488
|
+
let selection = this.windowApi.globalThis.getSelection();
|
|
5481
5489
|
if (selection) {
|
|
5482
5490
|
selection.removeAllRanges();
|
|
5483
5491
|
selection.addRange(range);
|
|
@@ -5505,6 +5513,7 @@
|
|
|
5505
5513
|
else {
|
|
5506
5514
|
textType = "text/plain";
|
|
5507
5515
|
}
|
|
5516
|
+
let UtilsContext = this;
|
|
5508
5517
|
class UtilsClipboard {
|
|
5509
5518
|
#resolve;
|
|
5510
5519
|
#copyData;
|
|
@@ -5559,15 +5568,15 @@
|
|
|
5559
5568
|
*/
|
|
5560
5569
|
copyTextByTextArea() {
|
|
5561
5570
|
try {
|
|
5562
|
-
let copyElement =
|
|
5571
|
+
let copyElement = UtilsContext.windowApi.document.createElement("textarea");
|
|
5563
5572
|
copyElement.value = this.#copyData;
|
|
5564
5573
|
copyElement.setAttribute("type", "text");
|
|
5565
5574
|
copyElement.setAttribute("style", "opacity:0;position:absolute;");
|
|
5566
5575
|
copyElement.setAttribute("readonly", "readonly");
|
|
5567
|
-
|
|
5576
|
+
UtilsContext.windowApi.document.body.appendChild(copyElement);
|
|
5568
5577
|
copyElement.select();
|
|
5569
|
-
|
|
5570
|
-
|
|
5578
|
+
UtilsContext.windowApi.document.execCommand("copy");
|
|
5579
|
+
UtilsContext.windowApi.document.body.removeChild(copyElement);
|
|
5571
5580
|
return true;
|
|
5572
5581
|
}
|
|
5573
5582
|
catch (error) {
|
|
@@ -5644,11 +5653,11 @@
|
|
|
5644
5653
|
}
|
|
5645
5654
|
return new Promise((resolve) => {
|
|
5646
5655
|
const utilsClipboard = new UtilsClipboard(resolve, data, textType);
|
|
5647
|
-
if (
|
|
5656
|
+
if (UtilsContext.windowApi.document.hasFocus()) {
|
|
5648
5657
|
utilsClipboard.init();
|
|
5649
5658
|
}
|
|
5650
5659
|
else {
|
|
5651
|
-
|
|
5660
|
+
UtilsContext.windowApi.window.addEventListener("focus", () => {
|
|
5652
5661
|
utilsClipboard.init();
|
|
5653
5662
|
}, { once: true });
|
|
5654
5663
|
}
|
|
@@ -5678,15 +5687,16 @@
|
|
|
5678
5687
|
}, delayTime);
|
|
5679
5688
|
});
|
|
5680
5689
|
}
|
|
5681
|
-
dragSlider(selector, offsetX =
|
|
5690
|
+
dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
|
|
5691
|
+
let UtilsContext = this;
|
|
5682
5692
|
function initMouseEvent(eventName, offSetX, offSetY) {
|
|
5683
5693
|
let win = unsafeWindow || window;
|
|
5684
|
-
let mouseEvent =
|
|
5694
|
+
let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
5685
5695
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
5686
5696
|
return mouseEvent;
|
|
5687
5697
|
}
|
|
5688
5698
|
let sliderElement = typeof selector === "string"
|
|
5689
|
-
?
|
|
5699
|
+
? this.windowApi.document.querySelector(selector)
|
|
5690
5700
|
: selector;
|
|
5691
5701
|
if (!(sliderElement instanceof Node) ||
|
|
5692
5702
|
!(sliderElement instanceof Element)) {
|
|
@@ -5698,7 +5708,7 @@
|
|
|
5698
5708
|
sliderElement.dispatchEvent(initMouseEvent("mouseleave", x1, y1));
|
|
5699
5709
|
sliderElement.dispatchEvent(initMouseEvent("mouseout", x1, y1));
|
|
5700
5710
|
}
|
|
5701
|
-
enterFullScreen(element =
|
|
5711
|
+
enterFullScreen(element = this.windowApi.document.documentElement, options) {
|
|
5702
5712
|
try {
|
|
5703
5713
|
if (element.requestFullscreen) {
|
|
5704
5714
|
element.requestFullscreen(options);
|
|
@@ -5720,18 +5730,18 @@
|
|
|
5720
5730
|
console.error(err);
|
|
5721
5731
|
}
|
|
5722
5732
|
}
|
|
5723
|
-
exitFullScreen(element =
|
|
5724
|
-
if (
|
|
5725
|
-
return
|
|
5733
|
+
exitFullScreen(element = this.windowApi.document.documentElement) {
|
|
5734
|
+
if (this.windowApi.document.exitFullscreen) {
|
|
5735
|
+
return this.windowApi.document.exitFullscreen();
|
|
5726
5736
|
}
|
|
5727
|
-
else if (
|
|
5728
|
-
return
|
|
5737
|
+
else if (this.windowApi.document.msExitFullscreen) {
|
|
5738
|
+
return this.windowApi.document.msExitFullscreen();
|
|
5729
5739
|
}
|
|
5730
|
-
else if (
|
|
5731
|
-
return
|
|
5740
|
+
else if (this.windowApi.document.mozCancelFullScreen) {
|
|
5741
|
+
return this.windowApi.document.mozCancelFullScreen();
|
|
5732
5742
|
}
|
|
5733
|
-
else if (
|
|
5734
|
-
return
|
|
5743
|
+
else if (this.windowApi.document.webkitCancelFullScreen) {
|
|
5744
|
+
return this.windowApi.document.webkitCancelFullScreen();
|
|
5735
5745
|
}
|
|
5736
5746
|
else {
|
|
5737
5747
|
return new Promise((resolve, reject) => {
|
|
@@ -5907,7 +5917,7 @@
|
|
|
5907
5917
|
UtilsContext.tryCatch()
|
|
5908
5918
|
.error(() => {
|
|
5909
5919
|
try {
|
|
5910
|
-
result =
|
|
5920
|
+
result = UtilsContext.windowApi.window.eval("(" + data + ")");
|
|
5911
5921
|
}
|
|
5912
5922
|
catch (error2) {
|
|
5913
5923
|
if (typeof errorCallBack === "function") {
|
|
@@ -5984,11 +5994,11 @@
|
|
|
5984
5994
|
waitNode(...args) {
|
|
5985
5995
|
// 过滤掉undefined
|
|
5986
5996
|
args = args.filter((arg) => arg !== void 0);
|
|
5987
|
-
let
|
|
5997
|
+
let UtilsContext = this;
|
|
5988
5998
|
// 选择器
|
|
5989
5999
|
let selector = args[0];
|
|
5990
6000
|
// 父元素(监听的元素)
|
|
5991
|
-
let parent =
|
|
6001
|
+
let parent = UtilsContext.windowApi.document;
|
|
5992
6002
|
// 超时时间
|
|
5993
6003
|
let timeout = 0;
|
|
5994
6004
|
if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
|
|
@@ -6050,7 +6060,7 @@
|
|
|
6050
6060
|
return parent.querySelector(selector);
|
|
6051
6061
|
}
|
|
6052
6062
|
}
|
|
6053
|
-
var observer =
|
|
6063
|
+
var observer = UtilsContext.mutationObserver(parent, {
|
|
6054
6064
|
config: {
|
|
6055
6065
|
subtree: true,
|
|
6056
6066
|
childList: true,
|
|
@@ -6083,11 +6093,11 @@
|
|
|
6083
6093
|
waitAnyNode(...args) {
|
|
6084
6094
|
// 过滤掉undefined
|
|
6085
6095
|
args = args.filter((arg) => arg !== void 0);
|
|
6086
|
-
let
|
|
6096
|
+
let UtilsContext = this;
|
|
6087
6097
|
// 选择器
|
|
6088
6098
|
let selectorList = args[0];
|
|
6089
6099
|
// 父元素(监听的元素)
|
|
6090
|
-
let parent =
|
|
6100
|
+
let parent = UtilsContext.windowApi.document;
|
|
6091
6101
|
// 超时时间
|
|
6092
6102
|
let timeout = 0;
|
|
6093
6103
|
if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
|
|
@@ -6132,18 +6142,18 @@
|
|
|
6132
6142
|
throw new TypeError("Utils.waitAnyNode 参数个数错误");
|
|
6133
6143
|
}
|
|
6134
6144
|
let promiseList = selectorList.map((selector) => {
|
|
6135
|
-
return
|
|
6145
|
+
return UtilsContext.waitNode(selector, parent, timeout);
|
|
6136
6146
|
});
|
|
6137
6147
|
return Promise.any(promiseList);
|
|
6138
6148
|
}
|
|
6139
6149
|
waitNodeList(...args) {
|
|
6140
6150
|
// 过滤掉undefined
|
|
6141
6151
|
args = args.filter((arg) => arg !== void 0);
|
|
6142
|
-
let
|
|
6152
|
+
let UtilsContext = this;
|
|
6143
6153
|
// 选择器数组
|
|
6144
6154
|
let selector = args[0];
|
|
6145
6155
|
// 父元素(监听的元素)
|
|
6146
|
-
let parent =
|
|
6156
|
+
let parent = UtilsContext.windowApi.document;
|
|
6147
6157
|
// 超时时间
|
|
6148
6158
|
let timeout = 0;
|
|
6149
6159
|
if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
|
|
@@ -6208,7 +6218,7 @@
|
|
|
6208
6218
|
}
|
|
6209
6219
|
}
|
|
6210
6220
|
}
|
|
6211
|
-
var observer =
|
|
6221
|
+
var observer = UtilsContext.mutationObserver(parent, {
|
|
6212
6222
|
config: {
|
|
6213
6223
|
subtree: true,
|
|
6214
6224
|
childList: true,
|
|
@@ -6242,11 +6252,11 @@
|
|
|
6242
6252
|
waitAnyNodeList(...args) {
|
|
6243
6253
|
// 过滤掉undefined
|
|
6244
6254
|
args = args.filter((arg) => arg !== void 0);
|
|
6245
|
-
let
|
|
6255
|
+
let UtilsContext = this;
|
|
6246
6256
|
// 选择器数组
|
|
6247
6257
|
let selectorList = args[0];
|
|
6248
6258
|
// 父元素(监听的元素)
|
|
6249
|
-
let parent =
|
|
6259
|
+
let parent = UtilsContext.windowApi.document;
|
|
6250
6260
|
// 超时时间
|
|
6251
6261
|
let timeout = 0;
|
|
6252
6262
|
if (!Array.isArray(args[0])) {
|
|
@@ -6291,7 +6301,7 @@
|
|
|
6291
6301
|
throw new TypeError("Utils.waitAnyNodeList 参数个数错误");
|
|
6292
6302
|
}
|
|
6293
6303
|
let promiseList = selectorList.map((selector) => {
|
|
6294
|
-
return
|
|
6304
|
+
return UtilsContext.waitNodeList(selector, parent, timeout);
|
|
6295
6305
|
});
|
|
6296
6306
|
return Promise.any(promiseList);
|
|
6297
6307
|
}
|
|
@@ -6494,12 +6504,12 @@
|
|
|
6494
6504
|
if (text.startsWith("//")) {
|
|
6495
6505
|
/* //www.baidu.com/xxxxxxx */
|
|
6496
6506
|
/* 没有protocol,加上 */
|
|
6497
|
-
text =
|
|
6507
|
+
text = this.windowApi.globalThis.location.protocol + text;
|
|
6498
6508
|
}
|
|
6499
6509
|
else if (text.startsWith("/")) {
|
|
6500
6510
|
/* /xxx/info?xxx=xxx */
|
|
6501
6511
|
/* 没有Origin,加上 */
|
|
6502
|
-
text =
|
|
6512
|
+
text = this.windowApi.globalThis.location.origin + text;
|
|
6503
6513
|
}
|
|
6504
6514
|
return new URL(text);
|
|
6505
6515
|
}
|