@whitesev/utils 2.0.2 → 2.1.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 +186 -175
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +186 -175
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +186 -175
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +186 -175
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +186 -175
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +186 -175
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +6 -5
- package/dist/types/src/UtilsGMCookie.d.ts +6 -0
- package/dist/types/src/WindowApi.d.ts +22 -0
- package/dist/types/src/types/global.d.ts +1 -0
- package/package.json +1 -1
- package/src/Httpx.ts +3 -5
- package/src/Log.ts +1 -2
- package/src/Progress.ts +4 -10
- package/src/Utils.ts +150 -119
- package/src/UtilsCommon.ts +2 -4
- package/src/UtilsGMCookie.ts +29 -16
- package/src/UtilsGMMenu.ts +1 -2
- package/src/WindowApi.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.esm.js
CHANGED
|
@@ -224,45 +224,16 @@ class GBKEncoder {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
const UtilsCoreDefaultEnv = {
|
|
228
|
-
document: document,
|
|
229
|
-
window: window,
|
|
230
|
-
globalThis: globalThis,
|
|
231
|
-
self: self,
|
|
232
|
-
top: top,
|
|
233
|
-
};
|
|
234
|
-
const UtilsCoreEnv = {
|
|
235
|
-
document: document,
|
|
236
|
-
window: window,
|
|
237
|
-
globalThis: globalThis,
|
|
238
|
-
self: self,
|
|
239
|
-
top: top,
|
|
240
|
-
};
|
|
241
|
-
const UtilsCore = {
|
|
242
|
-
init(option) {
|
|
243
|
-
if (!option) {
|
|
244
|
-
option = Object.assign({}, UtilsCoreDefaultEnv);
|
|
245
|
-
}
|
|
246
|
-
Object.assign(UtilsCoreEnv, option);
|
|
247
|
-
},
|
|
248
|
-
get document() {
|
|
249
|
-
return UtilsCoreEnv.document;
|
|
250
|
-
},
|
|
251
|
-
get window() {
|
|
252
|
-
return UtilsCoreEnv.window;
|
|
253
|
-
},
|
|
254
|
-
get globalThis() {
|
|
255
|
-
return UtilsCoreEnv.globalThis;
|
|
256
|
-
},
|
|
257
|
-
get self() {
|
|
258
|
-
return UtilsCoreEnv.self;
|
|
259
|
-
},
|
|
260
|
-
get top() {
|
|
261
|
-
return UtilsCoreEnv.top;
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
|
|
265
227
|
class UtilsGMCookie {
|
|
228
|
+
windowApi = {
|
|
229
|
+
window: window,
|
|
230
|
+
document: document,
|
|
231
|
+
};
|
|
232
|
+
constructor(windowApiOption) {
|
|
233
|
+
if (windowApiOption) {
|
|
234
|
+
this.windowApi = Object.assign({}, windowApiOption);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
266
237
|
/**
|
|
267
238
|
* 获取单个cookie
|
|
268
239
|
* @param cookieName cookie名
|
|
@@ -271,7 +242,7 @@ class UtilsGMCookie {
|
|
|
271
242
|
if (typeof cookieName !== "string") {
|
|
272
243
|
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
273
244
|
}
|
|
274
|
-
let cookies =
|
|
245
|
+
let cookies = this.windowApi.document.cookie.split(";");
|
|
275
246
|
let findValue = void 0;
|
|
276
247
|
for (const cookieItem of cookies) {
|
|
277
248
|
let item = cookieItem.trim();
|
|
@@ -281,7 +252,7 @@ class UtilsGMCookie {
|
|
|
281
252
|
let itemValue = decodeURIComponent(itemSplit.join(""));
|
|
282
253
|
if (itemName === cookieName) {
|
|
283
254
|
findValue = {
|
|
284
|
-
domain:
|
|
255
|
+
domain: this.windowApi.window.location.hostname,
|
|
285
256
|
expirationDate: null,
|
|
286
257
|
hostOnly: true,
|
|
287
258
|
httpOnly: false,
|
|
@@ -311,13 +282,13 @@ class UtilsGMCookie {
|
|
|
311
282
|
let resultData = [];
|
|
312
283
|
try {
|
|
313
284
|
let details = {
|
|
314
|
-
url:
|
|
315
|
-
domain:
|
|
285
|
+
url: this.windowApi.window.location.href,
|
|
286
|
+
domain: this.windowApi.window.location.hostname,
|
|
316
287
|
name: "",
|
|
317
288
|
path: "/",
|
|
318
289
|
};
|
|
319
290
|
details = utils.assign(details, paramDetails);
|
|
320
|
-
let cookies =
|
|
291
|
+
let cookies = this.windowApi.document.cookie.split(";");
|
|
321
292
|
cookies.forEach((item) => {
|
|
322
293
|
item = item.trim();
|
|
323
294
|
let itemSplit = item.split("=");
|
|
@@ -329,7 +300,7 @@ class UtilsGMCookie {
|
|
|
329
300
|
: new RegExp("^" + details.name, "g");
|
|
330
301
|
if (itemName.match(nameRegexp)) {
|
|
331
302
|
resultData.push({
|
|
332
|
-
domain:
|
|
303
|
+
domain: this.windowApi.window.location.hostname,
|
|
333
304
|
expirationDate: null,
|
|
334
305
|
hostOnly: true,
|
|
335
306
|
httpOnly: false,
|
|
@@ -362,13 +333,13 @@ class UtilsGMCookie {
|
|
|
362
333
|
}
|
|
363
334
|
let resultData = [];
|
|
364
335
|
let details = {
|
|
365
|
-
url:
|
|
366
|
-
domain:
|
|
336
|
+
url: this.windowApi.window.location.href,
|
|
337
|
+
domain: this.windowApi.window.location.hostname,
|
|
367
338
|
name: "",
|
|
368
339
|
path: "/",
|
|
369
340
|
};
|
|
370
341
|
details = utils.assign(details, paramDetails);
|
|
371
|
-
let cookies =
|
|
342
|
+
let cookies = this.windowApi.document.cookie.split(";");
|
|
372
343
|
cookies.forEach((item) => {
|
|
373
344
|
item = item.trim();
|
|
374
345
|
let itemSplit = item.split("=");
|
|
@@ -380,7 +351,7 @@ class UtilsGMCookie {
|
|
|
380
351
|
: new RegExp("^" + details.name, "g");
|
|
381
352
|
if (itemName.match(nameRegexp)) {
|
|
382
353
|
resultData.push({
|
|
383
|
-
domain:
|
|
354
|
+
domain: this.windowApi.window.location.hostname,
|
|
384
355
|
expirationDate: null,
|
|
385
356
|
hostOnly: true,
|
|
386
357
|
httpOnly: false,
|
|
@@ -403,10 +374,10 @@ class UtilsGMCookie {
|
|
|
403
374
|
set(paramDetails, callback = (error) => { }) {
|
|
404
375
|
try {
|
|
405
376
|
let details = {
|
|
406
|
-
url:
|
|
377
|
+
url: this.windowApi.window.location.href,
|
|
407
378
|
name: "",
|
|
408
379
|
value: "",
|
|
409
|
-
domain:
|
|
380
|
+
domain: this.windowApi.window.location.hostname,
|
|
410
381
|
path: "/",
|
|
411
382
|
secure: true,
|
|
412
383
|
httpOnly: false,
|
|
@@ -425,7 +396,7 @@ class UtilsGMCookie {
|
|
|
425
396
|
";expires=" +
|
|
426
397
|
new Date(life).toGMTString() +
|
|
427
398
|
"; path=/";
|
|
428
|
-
|
|
399
|
+
this.windowApi.document.cookie = cookieStr;
|
|
429
400
|
callback();
|
|
430
401
|
}
|
|
431
402
|
catch (error) {
|
|
@@ -440,14 +411,14 @@ class UtilsGMCookie {
|
|
|
440
411
|
delete(paramDetails, callback = (error) => { }) {
|
|
441
412
|
try {
|
|
442
413
|
let details = {
|
|
443
|
-
url:
|
|
414
|
+
url: this.windowApi.window.location.href,
|
|
444
415
|
name: "",
|
|
445
416
|
// @ts-ignore
|
|
446
417
|
firstPartyDomain: "",
|
|
447
418
|
};
|
|
448
419
|
details = utils.assign(details, paramDetails);
|
|
449
420
|
let cookieStr = details.name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
450
|
-
|
|
421
|
+
this.windowApi.document.cookie = cookieStr;
|
|
451
422
|
callback();
|
|
452
423
|
}
|
|
453
424
|
catch (error) {
|
|
@@ -1217,7 +1188,7 @@ class GMMenu {
|
|
|
1217
1188
|
}
|
|
1218
1189
|
/* 不刷新网页就刷新菜单 */
|
|
1219
1190
|
if (menuOption.autoReload) {
|
|
1220
|
-
|
|
1191
|
+
window.location.reload();
|
|
1221
1192
|
}
|
|
1222
1193
|
else {
|
|
1223
1194
|
that.context.update();
|
|
@@ -1536,8 +1507,8 @@ class Hooks {
|
|
|
1536
1507
|
* 生成uuid
|
|
1537
1508
|
*/
|
|
1538
1509
|
const GenerateUUID = function () {
|
|
1539
|
-
if (typeof
|
|
1540
|
-
return
|
|
1510
|
+
if (typeof window?.crypto?.randomUUID === "function") {
|
|
1511
|
+
return window.crypto.randomUUID();
|
|
1541
1512
|
}
|
|
1542
1513
|
else {
|
|
1543
1514
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
@@ -1909,14 +1880,13 @@ class Httpx {
|
|
|
1909
1880
|
}
|
|
1910
1881
|
catch (error) {
|
|
1911
1882
|
if (details.url.startsWith("//")) {
|
|
1912
|
-
details.url =
|
|
1883
|
+
details.url = window.location.protocol + details.url;
|
|
1913
1884
|
}
|
|
1914
1885
|
else if (details.url.startsWith("/")) {
|
|
1915
|
-
details.url =
|
|
1886
|
+
details.url = window.location.origin + details.url;
|
|
1916
1887
|
}
|
|
1917
1888
|
else {
|
|
1918
|
-
details.url =
|
|
1919
|
-
UtilsCore.globalThis.location.origin + "/" + details.url;
|
|
1889
|
+
details.url = window.location.origin + "/" + details.url;
|
|
1920
1890
|
}
|
|
1921
1891
|
}
|
|
1922
1892
|
return details;
|
|
@@ -2542,10 +2512,10 @@ class indexedDB {
|
|
|
2542
2512
|
// @ts-ignore
|
|
2543
2513
|
#slqVersion = "1";
|
|
2544
2514
|
/* 监听IndexDB */
|
|
2545
|
-
#indexedDB =
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2515
|
+
#indexedDB = window.indexedDB ||
|
|
2516
|
+
window.mozIndexedDB ||
|
|
2517
|
+
window.webkitIndexedDB ||
|
|
2518
|
+
window.msIndexedDB;
|
|
2549
2519
|
/* 缓存数据库,避免同一个页面重复创建和销毁 */
|
|
2550
2520
|
#db = {};
|
|
2551
2521
|
// @ts-ignore
|
|
@@ -2975,7 +2945,7 @@ class Log {
|
|
|
2975
2945
|
* @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
|
|
2976
2946
|
* @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
|
|
2977
2947
|
*/
|
|
2978
|
-
constructor(_GM_info_, console =
|
|
2948
|
+
constructor(_GM_info_, console = window.console) {
|
|
2979
2949
|
if (typeof _GM_info_ === "string") {
|
|
2980
2950
|
this.tag = _GM_info_;
|
|
2981
2951
|
}
|
|
@@ -3236,14 +3206,12 @@ class Progress {
|
|
|
3236
3206
|
/* 元素高度 */
|
|
3237
3207
|
this.#height = this.#config.canvasNode.height;
|
|
3238
3208
|
/* 清除锯齿 */
|
|
3239
|
-
if (
|
|
3209
|
+
if (window.devicePixelRatio) {
|
|
3240
3210
|
this.#config.canvasNode.style.width = this.#width + "px";
|
|
3241
3211
|
this.#config.canvasNode.style.height = this.#height + "px";
|
|
3242
|
-
this.#config.canvasNode.height =
|
|
3243
|
-
|
|
3244
|
-
this.#
|
|
3245
|
-
this.#width * UtilsCore.window.devicePixelRatio;
|
|
3246
|
-
this.#ctx.scale(UtilsCore.window.devicePixelRatio, UtilsCore.window.devicePixelRatio);
|
|
3212
|
+
this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
|
|
3213
|
+
this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
|
|
3214
|
+
this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
|
3247
3215
|
}
|
|
3248
3216
|
/* 设置线宽 */
|
|
3249
3217
|
this.#ctx.lineWidth = this.#config.lineWidth;
|
|
@@ -3512,34 +3480,69 @@ class UtilsDictionary {
|
|
|
3512
3480
|
}
|
|
3513
3481
|
}
|
|
3514
3482
|
|
|
3483
|
+
class WindowApi {
|
|
3484
|
+
/** 默认的配置 */
|
|
3485
|
+
defaultApi = {
|
|
3486
|
+
document: document,
|
|
3487
|
+
window: window,
|
|
3488
|
+
globalThis: globalThis,
|
|
3489
|
+
self: self,
|
|
3490
|
+
top: top,
|
|
3491
|
+
};
|
|
3492
|
+
/** 使用的配置 */
|
|
3493
|
+
api;
|
|
3494
|
+
constructor(option) {
|
|
3495
|
+
if (!option) {
|
|
3496
|
+
option = Object.assign({}, this.defaultApi);
|
|
3497
|
+
}
|
|
3498
|
+
this.api = Object.assign({}, option);
|
|
3499
|
+
}
|
|
3500
|
+
get document() {
|
|
3501
|
+
return this.api.document;
|
|
3502
|
+
}
|
|
3503
|
+
get window() {
|
|
3504
|
+
return this.api.window;
|
|
3505
|
+
}
|
|
3506
|
+
get globalThis() {
|
|
3507
|
+
return this.api.globalThis;
|
|
3508
|
+
}
|
|
3509
|
+
get self() {
|
|
3510
|
+
return this.api.self;
|
|
3511
|
+
}
|
|
3512
|
+
get top() {
|
|
3513
|
+
return this.api.top;
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3515
3517
|
class Utils {
|
|
3518
|
+
windowApi;
|
|
3516
3519
|
constructor(option) {
|
|
3517
|
-
|
|
3520
|
+
this.windowApi = new WindowApi(option);
|
|
3518
3521
|
}
|
|
3519
3522
|
/** 版本号 */
|
|
3520
|
-
version = "2024.7.
|
|
3523
|
+
version = "2024.7.24";
|
|
3521
3524
|
addStyle(cssText) {
|
|
3522
3525
|
if (typeof cssText !== "string") {
|
|
3523
3526
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
3524
3527
|
}
|
|
3525
|
-
let cssNode =
|
|
3528
|
+
let cssNode = this.windowApi.document.createElement("style");
|
|
3526
3529
|
cssNode.setAttribute("type", "text/css");
|
|
3527
3530
|
cssNode.innerHTML = cssText;
|
|
3528
|
-
if (
|
|
3531
|
+
if (this.windowApi.document.head) {
|
|
3529
3532
|
/* 插入head最后 */
|
|
3530
|
-
|
|
3533
|
+
this.windowApi.document.head.appendChild(cssNode);
|
|
3531
3534
|
}
|
|
3532
|
-
else if (
|
|
3535
|
+
else if (this.windowApi.document.body) {
|
|
3533
3536
|
/* 插入body后 */
|
|
3534
|
-
|
|
3537
|
+
this.windowApi.document.body.appendChild(cssNode);
|
|
3535
3538
|
}
|
|
3536
|
-
else if (
|
|
3539
|
+
else if (this.windowApi.document.documentElement.childNodes.length === 0) {
|
|
3537
3540
|
/* 插入#html第一个元素后 */
|
|
3538
|
-
|
|
3541
|
+
this.windowApi.document.documentElement.appendChild(cssNode);
|
|
3539
3542
|
}
|
|
3540
3543
|
else {
|
|
3541
3544
|
/* 插入head前面 */
|
|
3542
|
-
|
|
3545
|
+
this.windowApi.document.documentElement.insertBefore(cssNode, this.windowApi.document.documentElement.childNodes[0]);
|
|
3543
3546
|
}
|
|
3544
3547
|
return cssNode;
|
|
3545
3548
|
}
|
|
@@ -3670,7 +3673,7 @@ class Utils {
|
|
|
3670
3673
|
let elementPosXRight = Number(element.getBoundingClientRect().right); /* 要检测的元素的相对屏幕的横坐标最右边 */
|
|
3671
3674
|
let elementPosYTop = Number(element.getBoundingClientRect().top); /* 要检测的元素的相对屏幕的纵坐标最上边 */
|
|
3672
3675
|
let elementPosYBottom = Number(element.getBoundingClientRect().bottom); /* 要检测的元素的相对屏幕的纵坐标最下边 */
|
|
3673
|
-
let clickNodeHTML =
|
|
3676
|
+
let clickNodeHTML = this.windowApi.window.event.target
|
|
3674
3677
|
.innerHTML;
|
|
3675
3678
|
if (mouseClickPosX >= elementPosXLeft &&
|
|
3676
3679
|
mouseClickPosX <= elementPosXRight &&
|
|
@@ -3799,18 +3802,18 @@ class Utils {
|
|
|
3799
3802
|
}
|
|
3800
3803
|
if (isIFrame) {
|
|
3801
3804
|
/* 使用iframe */
|
|
3802
|
-
const iframeElement =
|
|
3805
|
+
const iframeElement = this.windowApi.document.createElement("iframe");
|
|
3803
3806
|
iframeElement.style.display = "none";
|
|
3804
3807
|
iframeElement.src = base64Data;
|
|
3805
|
-
|
|
3808
|
+
this.windowApi.document.body.appendChild(iframeElement);
|
|
3806
3809
|
setTimeout(() => {
|
|
3807
3810
|
iframeElement.contentWindow.document.execCommand("SaveAs", true, fileName);
|
|
3808
|
-
|
|
3811
|
+
this.windowApi.document.body.removeChild(iframeElement);
|
|
3809
3812
|
}, 100);
|
|
3810
3813
|
}
|
|
3811
3814
|
else {
|
|
3812
3815
|
/* 使用A标签 */
|
|
3813
|
-
const linkElement =
|
|
3816
|
+
const linkElement = this.windowApi.document.createElement("a");
|
|
3814
3817
|
linkElement.setAttribute("target", "_blank");
|
|
3815
3818
|
linkElement.download = fileName;
|
|
3816
3819
|
linkElement.href = base64Data;
|
|
@@ -3820,13 +3823,13 @@ class Utils {
|
|
|
3820
3823
|
findWebPageVisibleText(str = "", caseSensitive = false) {
|
|
3821
3824
|
let TRange = null;
|
|
3822
3825
|
let strFound;
|
|
3823
|
-
if (
|
|
3826
|
+
if (this.windowApi.globalThis.find) {
|
|
3824
3827
|
/* CODE FOR BROWSERS THAT SUPPORT window.find */
|
|
3825
|
-
let windowFind =
|
|
3828
|
+
let windowFind = this.windowApi.self.find;
|
|
3826
3829
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
3827
3830
|
if (strFound &&
|
|
3828
|
-
|
|
3829
|
-
!
|
|
3831
|
+
this.windowApi.self.getSelection &&
|
|
3832
|
+
!this.windowApi.self.getSelection().anchorNode) {
|
|
3830
3833
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
3831
3834
|
}
|
|
3832
3835
|
if (!strFound) {
|
|
@@ -3845,7 +3848,7 @@ class Utils {
|
|
|
3845
3848
|
TRange.select();
|
|
3846
3849
|
}
|
|
3847
3850
|
if (TRange == null || strFound == 0) {
|
|
3848
|
-
TRange =
|
|
3851
|
+
TRange = this.windowApi.self.document.body.createTextRange();
|
|
3849
3852
|
strFound = TRange.findText(str);
|
|
3850
3853
|
if (strFound)
|
|
3851
3854
|
TRange.select();
|
|
@@ -4221,8 +4224,8 @@ class Utils {
|
|
|
4221
4224
|
let maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
4222
4225
|
// 当前页面最大的z-index
|
|
4223
4226
|
let zIndex = 0;
|
|
4224
|
-
|
|
4225
|
-
let nodeStyle =
|
|
4227
|
+
this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
|
|
4228
|
+
let nodeStyle = this.windowApi.window.getComputedStyle($ele);
|
|
4226
4229
|
/* 不对position为static和display为none的元素进行获取它们的z-index */
|
|
4227
4230
|
if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
|
|
4228
4231
|
let nodeZIndex = parseInt(nodeStyle.zIndex);
|
|
@@ -4436,7 +4439,7 @@ class Utils {
|
|
|
4436
4439
|
if (url.trim() === "") {
|
|
4437
4440
|
throw new TypeError("url不能为空字符串或纯空格");
|
|
4438
4441
|
}
|
|
4439
|
-
return `thunder://${
|
|
4442
|
+
return `thunder://${this.windowApi.globalThis.btoa("AA" + url + "ZZ")}`;
|
|
4440
4443
|
}
|
|
4441
4444
|
/**
|
|
4442
4445
|
* 对于GM_cookie的兼容写法,当无法使用GM_cookie时可以使用这个,但是并不完全兼容,有些写不出来且限制了httponly是无法访问的
|
|
@@ -4651,21 +4654,21 @@ class Utils {
|
|
|
4651
4654
|
return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
|
|
4652
4655
|
}
|
|
4653
4656
|
isNearBottom(nearValue = 50) {
|
|
4654
|
-
var scrollTop =
|
|
4655
|
-
|
|
4656
|
-
var windowHeight =
|
|
4657
|
-
|
|
4658
|
-
var documentHeight =
|
|
4657
|
+
var scrollTop = this.windowApi.window.pageYOffset ||
|
|
4658
|
+
this.windowApi.document.documentElement.scrollTop;
|
|
4659
|
+
var windowHeight = this.windowApi.window.innerHeight ||
|
|
4660
|
+
this.windowApi.document.documentElement.clientHeight;
|
|
4661
|
+
var documentHeight = this.windowApi.document.documentElement.scrollHeight;
|
|
4659
4662
|
return scrollTop + windowHeight >= documentHeight - nearValue;
|
|
4660
4663
|
}
|
|
4661
4664
|
isDOM(target) {
|
|
4662
4665
|
return target instanceof Node;
|
|
4663
4666
|
}
|
|
4664
4667
|
isFullscreenEnabled() {
|
|
4665
|
-
return !!(
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4668
|
+
return !!(this.windowApi.document.fullscreenEnabled ||
|
|
4669
|
+
this.windowApi.document.webkitFullScreenEnabled ||
|
|
4670
|
+
this.windowApi.document.mozFullScreenEnabled ||
|
|
4671
|
+
this.windowApi.document.msFullScreenEnabled);
|
|
4669
4672
|
}
|
|
4670
4673
|
isJQuery(target) {
|
|
4671
4674
|
let result = false;
|
|
@@ -4898,7 +4901,7 @@ class Utils {
|
|
|
4898
4901
|
return result;
|
|
4899
4902
|
}
|
|
4900
4903
|
isThemeDark() {
|
|
4901
|
-
return
|
|
4904
|
+
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
4902
4905
|
.matches;
|
|
4903
4906
|
}
|
|
4904
4907
|
isVisible(element, inView = false) {
|
|
@@ -4912,17 +4915,17 @@ class Utils {
|
|
|
4912
4915
|
}
|
|
4913
4916
|
let result = true;
|
|
4914
4917
|
for (const domItem of needCheckDomList) {
|
|
4915
|
-
let domDisplay =
|
|
4918
|
+
let domDisplay = this.windowApi.window.getComputedStyle(domItem);
|
|
4916
4919
|
if (domDisplay.display === "none") {
|
|
4917
4920
|
result = false;
|
|
4918
4921
|
}
|
|
4919
4922
|
else {
|
|
4920
4923
|
let domClientRect = domItem.getBoundingClientRect();
|
|
4921
4924
|
if (inView) {
|
|
4922
|
-
let viewportWidth =
|
|
4923
|
-
|
|
4924
|
-
let viewportHeight =
|
|
4925
|
-
|
|
4925
|
+
let viewportWidth = this.windowApi.window.innerWidth ||
|
|
4926
|
+
this.windowApi.document.documentElement.clientWidth;
|
|
4927
|
+
let viewportHeight = this.windowApi.window.innerHeight ||
|
|
4928
|
+
this.windowApi.document.documentElement.clientHeight;
|
|
4926
4929
|
result = !(domClientRect.right < 0 ||
|
|
4927
4930
|
domClientRect.left > viewportWidth ||
|
|
4928
4931
|
domClientRect.bottom < 0 ||
|
|
@@ -4942,10 +4945,10 @@ class Utils {
|
|
|
4942
4945
|
isWebView_Via() {
|
|
4943
4946
|
let result = true;
|
|
4944
4947
|
let UtilsContext = this;
|
|
4945
|
-
if (typeof
|
|
4946
|
-
for (const key in Object.values(
|
|
4947
|
-
if (Reflect.has(
|
|
4948
|
-
let objValueFunc =
|
|
4948
|
+
if (typeof this.windowApi.top.window.via === "object") {
|
|
4949
|
+
for (const key in Object.values(this.windowApi.top.window.via)) {
|
|
4950
|
+
if (Reflect.has(this.windowApi.top.window.via, key)) {
|
|
4951
|
+
let objValueFunc = this.windowApi.top.window.via[key];
|
|
4949
4952
|
if (typeof objValueFunc === "function" &&
|
|
4950
4953
|
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
4951
4954
|
result = true;
|
|
@@ -4965,10 +4968,10 @@ class Utils {
|
|
|
4965
4968
|
isWebView_X() {
|
|
4966
4969
|
let result = true;
|
|
4967
4970
|
let UtilsContext = this;
|
|
4968
|
-
if (typeof
|
|
4969
|
-
for (const key in Object.values(
|
|
4970
|
-
if (Reflect.has(
|
|
4971
|
-
let objValueFunc =
|
|
4971
|
+
if (typeof this.windowApi.top.window.mbrowser === "object") {
|
|
4972
|
+
for (const key in Object.values(this.windowApi.top.window.mbrowser)) {
|
|
4973
|
+
if (Reflect.has(this.windowApi.top.window.mbrowser, key)) {
|
|
4974
|
+
let objValueFunc = this.windowApi.top.window.mbrowser[key];
|
|
4972
4975
|
if (typeof objValueFunc === "function" &&
|
|
4973
4976
|
UtilsContext.isNativeFunc(objValueFunc)) {
|
|
4974
4977
|
result = true;
|
|
@@ -5140,9 +5143,9 @@ class Utils {
|
|
|
5140
5143
|
immediate: false,
|
|
5141
5144
|
};
|
|
5142
5145
|
observer_config = UtilsContext.assign(default_obverser_config, observer_config);
|
|
5143
|
-
let windowMutationObserver =
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
+
let windowMutationObserver = this.windowApi.window.MutationObserver ||
|
|
5147
|
+
this.windowApi.window.webkitMutationObserver ||
|
|
5148
|
+
this.windowApi.window.MozMutationObserver;
|
|
5146
5149
|
// 观察者对象
|
|
5147
5150
|
let mutationObserver = new windowMutationObserver(function (mutations, observer) {
|
|
5148
5151
|
if (typeof observer_config.callback === "function") {
|
|
@@ -5178,13 +5181,13 @@ class Utils {
|
|
|
5178
5181
|
* let utils = Utils.noConflict();
|
|
5179
5182
|
* > ...
|
|
5180
5183
|
*/
|
|
5181
|
-
noConflict
|
|
5182
|
-
if (
|
|
5183
|
-
Reflect.deleteProperty(
|
|
5184
|
+
noConflict() {
|
|
5185
|
+
if (this.windowApi.window.Utils) {
|
|
5186
|
+
Reflect.deleteProperty(this.windowApi.window, "Utils");
|
|
5184
5187
|
}
|
|
5185
|
-
|
|
5188
|
+
this.windowApi.window.Utils = utils;
|
|
5186
5189
|
return utils;
|
|
5187
|
-
}
|
|
5190
|
+
}
|
|
5188
5191
|
noConflictFunc(needReleaseObject, needReleaseName, functionNameList = [], release = true) {
|
|
5189
5192
|
let UtilsContext = this;
|
|
5190
5193
|
if (typeof needReleaseObject !== "object") {
|
|
@@ -5201,11 +5204,12 @@ class Utils {
|
|
|
5201
5204
|
* 释放所有
|
|
5202
5205
|
*/
|
|
5203
5206
|
function releaseAll() {
|
|
5204
|
-
if (typeof
|
|
5207
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] !==
|
|
5208
|
+
"undefined") {
|
|
5205
5209
|
/* 已存在 */
|
|
5206
5210
|
return;
|
|
5207
5211
|
}
|
|
5208
|
-
|
|
5212
|
+
UtilsContext.windowApi.window[needReleaseKey] =
|
|
5209
5213
|
UtilsContext.deepClone(needReleaseObject);
|
|
5210
5214
|
Object.values(needReleaseObject).forEach((value) => {
|
|
5211
5215
|
if (typeof value === "function") {
|
|
@@ -5220,11 +5224,12 @@ class Utils {
|
|
|
5220
5224
|
Array.from(functionNameList).forEach((item) => {
|
|
5221
5225
|
Object.values(needReleaseObject).forEach((value) => {
|
|
5222
5226
|
if (typeof value === "function") {
|
|
5223
|
-
if (typeof
|
|
5224
|
-
|
|
5227
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
5228
|
+
"undefined") {
|
|
5229
|
+
UtilsContext.windowApi.window[needReleaseKey] = {};
|
|
5225
5230
|
}
|
|
5226
5231
|
if (item === value.name) {
|
|
5227
|
-
|
|
5232
|
+
UtilsContext.windowApi.window[needReleaseKey][value.name] = needReleaseObject[value.name];
|
|
5228
5233
|
needReleaseObject[value.name] = () => { };
|
|
5229
5234
|
}
|
|
5230
5235
|
}
|
|
@@ -5235,26 +5240,29 @@ class Utils {
|
|
|
5235
5240
|
* 恢复所有
|
|
5236
5241
|
*/
|
|
5237
5242
|
function recoveryAll() {
|
|
5238
|
-
if (typeof
|
|
5243
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
5244
|
+
"undefined") {
|
|
5239
5245
|
/* 未存在 */
|
|
5240
5246
|
return;
|
|
5241
5247
|
}
|
|
5242
|
-
Object.assign(needReleaseObject,
|
|
5243
|
-
Reflect.deleteProperty(
|
|
5248
|
+
Object.assign(needReleaseObject, UtilsContext.windowApi.window[needReleaseKey]);
|
|
5249
|
+
Reflect.deleteProperty(UtilsContext.windowApi.window, "needReleaseKey");
|
|
5244
5250
|
}
|
|
5245
5251
|
/**
|
|
5246
5252
|
* 恢复单个
|
|
5247
5253
|
*/
|
|
5248
5254
|
function recoveryOne() {
|
|
5249
|
-
if (typeof
|
|
5255
|
+
if (typeof UtilsContext.windowApi.window[needReleaseKey] ===
|
|
5256
|
+
"undefined") {
|
|
5250
5257
|
/* 未存在 */
|
|
5251
5258
|
return;
|
|
5252
5259
|
}
|
|
5253
5260
|
Array.from(functionNameList).forEach((item) => {
|
|
5254
|
-
if (
|
|
5255
|
-
needReleaseObject[item] =
|
|
5256
|
-
Reflect.deleteProperty(
|
|
5257
|
-
if (Object.keys(
|
|
5261
|
+
if (UtilsContext.windowApi.window[needReleaseKey][item]) {
|
|
5262
|
+
needReleaseObject[item] = UtilsContext.windowApi.window[needReleaseKey][item];
|
|
5263
|
+
Reflect.deleteProperty(UtilsContext.windowApi.window[needReleaseKey], item);
|
|
5264
|
+
if (Object.keys(UtilsContext.windowApi.window[needReleaseKey])
|
|
5265
|
+
.length === 0) {
|
|
5258
5266
|
Reflect.deleteProperty(window, needReleaseKey);
|
|
5259
5267
|
}
|
|
5260
5268
|
}
|
|
@@ -5460,7 +5468,7 @@ class Utils {
|
|
|
5460
5468
|
return isNegative ? -reversedNum : reversedNum;
|
|
5461
5469
|
}
|
|
5462
5470
|
selectElementText(element, childTextNode, startIndex, endIndex) {
|
|
5463
|
-
let range =
|
|
5471
|
+
let range = this.windowApi.document.createRange();
|
|
5464
5472
|
range.selectNodeContents(element);
|
|
5465
5473
|
if (childTextNode) {
|
|
5466
5474
|
if (childTextNode.nodeType !== Node.TEXT_NODE) {
|
|
@@ -5471,7 +5479,7 @@ class Utils {
|
|
|
5471
5479
|
range.setEnd(childTextNode, endIndex);
|
|
5472
5480
|
}
|
|
5473
5481
|
}
|
|
5474
|
-
let selection =
|
|
5482
|
+
let selection = this.windowApi.globalThis.getSelection();
|
|
5475
5483
|
if (selection) {
|
|
5476
5484
|
selection.removeAllRanges();
|
|
5477
5485
|
selection.addRange(range);
|
|
@@ -5499,6 +5507,7 @@ class Utils {
|
|
|
5499
5507
|
else {
|
|
5500
5508
|
textType = "text/plain";
|
|
5501
5509
|
}
|
|
5510
|
+
let UtilsContext = this;
|
|
5502
5511
|
class UtilsClipboard {
|
|
5503
5512
|
#resolve;
|
|
5504
5513
|
#copyData;
|
|
@@ -5553,15 +5562,15 @@ class Utils {
|
|
|
5553
5562
|
*/
|
|
5554
5563
|
copyTextByTextArea() {
|
|
5555
5564
|
try {
|
|
5556
|
-
let copyElement =
|
|
5565
|
+
let copyElement = UtilsContext.windowApi.document.createElement("textarea");
|
|
5557
5566
|
copyElement.value = this.#copyData;
|
|
5558
5567
|
copyElement.setAttribute("type", "text");
|
|
5559
5568
|
copyElement.setAttribute("style", "opacity:0;position:absolute;");
|
|
5560
5569
|
copyElement.setAttribute("readonly", "readonly");
|
|
5561
|
-
|
|
5570
|
+
UtilsContext.windowApi.document.body.appendChild(copyElement);
|
|
5562
5571
|
copyElement.select();
|
|
5563
|
-
|
|
5564
|
-
|
|
5572
|
+
UtilsContext.windowApi.document.execCommand("copy");
|
|
5573
|
+
UtilsContext.windowApi.document.body.removeChild(copyElement);
|
|
5565
5574
|
return true;
|
|
5566
5575
|
}
|
|
5567
5576
|
catch (error) {
|
|
@@ -5638,11 +5647,11 @@ class Utils {
|
|
|
5638
5647
|
}
|
|
5639
5648
|
return new Promise((resolve) => {
|
|
5640
5649
|
const utilsClipboard = new UtilsClipboard(resolve, data, textType);
|
|
5641
|
-
if (
|
|
5650
|
+
if (UtilsContext.windowApi.document.hasFocus()) {
|
|
5642
5651
|
utilsClipboard.init();
|
|
5643
5652
|
}
|
|
5644
5653
|
else {
|
|
5645
|
-
|
|
5654
|
+
UtilsContext.windowApi.window.addEventListener("focus", () => {
|
|
5646
5655
|
utilsClipboard.init();
|
|
5647
5656
|
}, { once: true });
|
|
5648
5657
|
}
|
|
@@ -5672,15 +5681,16 @@ class Utils {
|
|
|
5672
5681
|
}, delayTime);
|
|
5673
5682
|
});
|
|
5674
5683
|
}
|
|
5675
|
-
dragSlider(selector, offsetX =
|
|
5684
|
+
dragSlider(selector, offsetX = this.windowApi.window.innerWidth) {
|
|
5685
|
+
let UtilsContext = this;
|
|
5676
5686
|
function initMouseEvent(eventName, offSetX, offSetY) {
|
|
5677
5687
|
let win = unsafeWindow || window;
|
|
5678
|
-
let mouseEvent =
|
|
5688
|
+
let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
5679
5689
|
mouseEvent.initMouseEvent(eventName, true, true, win, 0, offSetX, offSetY, offSetX, offSetY, false, false, false, false, 0, null);
|
|
5680
5690
|
return mouseEvent;
|
|
5681
5691
|
}
|
|
5682
5692
|
let sliderElement = typeof selector === "string"
|
|
5683
|
-
?
|
|
5693
|
+
? this.windowApi.document.querySelector(selector)
|
|
5684
5694
|
: selector;
|
|
5685
5695
|
if (!(sliderElement instanceof Node) ||
|
|
5686
5696
|
!(sliderElement instanceof Element)) {
|
|
@@ -5692,7 +5702,7 @@ class Utils {
|
|
|
5692
5702
|
sliderElement.dispatchEvent(initMouseEvent("mouseleave", x1, y1));
|
|
5693
5703
|
sliderElement.dispatchEvent(initMouseEvent("mouseout", x1, y1));
|
|
5694
5704
|
}
|
|
5695
|
-
enterFullScreen(element =
|
|
5705
|
+
enterFullScreen(element = this.windowApi.document.documentElement, options) {
|
|
5696
5706
|
try {
|
|
5697
5707
|
if (element.requestFullscreen) {
|
|
5698
5708
|
element.requestFullscreen(options);
|
|
@@ -5714,18 +5724,18 @@ class Utils {
|
|
|
5714
5724
|
console.error(err);
|
|
5715
5725
|
}
|
|
5716
5726
|
}
|
|
5717
|
-
exitFullScreen(element =
|
|
5718
|
-
if (
|
|
5719
|
-
return
|
|
5727
|
+
exitFullScreen(element = this.windowApi.document.documentElement) {
|
|
5728
|
+
if (this.windowApi.document.exitFullscreen) {
|
|
5729
|
+
return this.windowApi.document.exitFullscreen();
|
|
5720
5730
|
}
|
|
5721
|
-
else if (
|
|
5722
|
-
return
|
|
5731
|
+
else if (this.windowApi.document.msExitFullscreen) {
|
|
5732
|
+
return this.windowApi.document.msExitFullscreen();
|
|
5723
5733
|
}
|
|
5724
|
-
else if (
|
|
5725
|
-
return
|
|
5734
|
+
else if (this.windowApi.document.mozCancelFullScreen) {
|
|
5735
|
+
return this.windowApi.document.mozCancelFullScreen();
|
|
5726
5736
|
}
|
|
5727
|
-
else if (
|
|
5728
|
-
return
|
|
5737
|
+
else if (this.windowApi.document.webkitCancelFullScreen) {
|
|
5738
|
+
return this.windowApi.document.webkitCancelFullScreen();
|
|
5729
5739
|
}
|
|
5730
5740
|
else {
|
|
5731
5741
|
return new Promise((resolve, reject) => {
|
|
@@ -5820,7 +5830,8 @@ class Utils {
|
|
|
5820
5830
|
if (Array.isArray(data)) {
|
|
5821
5831
|
data.sort(sortFunc);
|
|
5822
5832
|
}
|
|
5823
|
-
else if (data instanceof NodeList ||
|
|
5833
|
+
else if (data instanceof NodeList ||
|
|
5834
|
+
UtilsContext.isJQuery(data)) {
|
|
5824
5835
|
sortNodeFunc(data, getDataFunc);
|
|
5825
5836
|
result = getDataFunc();
|
|
5826
5837
|
}
|
|
@@ -5901,7 +5912,7 @@ class Utils {
|
|
|
5901
5912
|
UtilsContext.tryCatch()
|
|
5902
5913
|
.error(() => {
|
|
5903
5914
|
try {
|
|
5904
|
-
result =
|
|
5915
|
+
result = UtilsContext.windowApi.window.eval("(" + data + ")");
|
|
5905
5916
|
}
|
|
5906
5917
|
catch (error2) {
|
|
5907
5918
|
if (typeof errorCallBack === "function") {
|
|
@@ -5978,11 +5989,11 @@ class Utils {
|
|
|
5978
5989
|
waitNode(...args) {
|
|
5979
5990
|
// 过滤掉undefined
|
|
5980
5991
|
args = args.filter((arg) => arg !== void 0);
|
|
5981
|
-
let
|
|
5992
|
+
let UtilsContext = this;
|
|
5982
5993
|
// 选择器
|
|
5983
5994
|
let selector = args[0];
|
|
5984
5995
|
// 父元素(监听的元素)
|
|
5985
|
-
let parent =
|
|
5996
|
+
let parent = UtilsContext.windowApi.document;
|
|
5986
5997
|
// 超时时间
|
|
5987
5998
|
let timeout = 0;
|
|
5988
5999
|
if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
|
|
@@ -6044,7 +6055,7 @@ class Utils {
|
|
|
6044
6055
|
return parent.querySelector(selector);
|
|
6045
6056
|
}
|
|
6046
6057
|
}
|
|
6047
|
-
var observer =
|
|
6058
|
+
var observer = UtilsContext.mutationObserver(parent, {
|
|
6048
6059
|
config: {
|
|
6049
6060
|
subtree: true,
|
|
6050
6061
|
childList: true,
|
|
@@ -6077,11 +6088,11 @@ class Utils {
|
|
|
6077
6088
|
waitAnyNode(...args) {
|
|
6078
6089
|
// 过滤掉undefined
|
|
6079
6090
|
args = args.filter((arg) => arg !== void 0);
|
|
6080
|
-
let
|
|
6091
|
+
let UtilsContext = this;
|
|
6081
6092
|
// 选择器
|
|
6082
6093
|
let selectorList = args[0];
|
|
6083
6094
|
// 父元素(监听的元素)
|
|
6084
|
-
let parent =
|
|
6095
|
+
let parent = UtilsContext.windowApi.document;
|
|
6085
6096
|
// 超时时间
|
|
6086
6097
|
let timeout = 0;
|
|
6087
6098
|
if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
|
|
@@ -6126,18 +6137,18 @@ class Utils {
|
|
|
6126
6137
|
throw new TypeError("Utils.waitAnyNode 参数个数错误");
|
|
6127
6138
|
}
|
|
6128
6139
|
let promiseList = selectorList.map((selector) => {
|
|
6129
|
-
return
|
|
6140
|
+
return UtilsContext.waitNode(selector, parent, timeout);
|
|
6130
6141
|
});
|
|
6131
6142
|
return Promise.any(promiseList);
|
|
6132
6143
|
}
|
|
6133
6144
|
waitNodeList(...args) {
|
|
6134
6145
|
// 过滤掉undefined
|
|
6135
6146
|
args = args.filter((arg) => arg !== void 0);
|
|
6136
|
-
let
|
|
6147
|
+
let UtilsContext = this;
|
|
6137
6148
|
// 选择器数组
|
|
6138
6149
|
let selector = args[0];
|
|
6139
6150
|
// 父元素(监听的元素)
|
|
6140
|
-
let parent =
|
|
6151
|
+
let parent = UtilsContext.windowApi.document;
|
|
6141
6152
|
// 超时时间
|
|
6142
6153
|
let timeout = 0;
|
|
6143
6154
|
if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
|
|
@@ -6202,7 +6213,7 @@ class Utils {
|
|
|
6202
6213
|
}
|
|
6203
6214
|
}
|
|
6204
6215
|
}
|
|
6205
|
-
var observer =
|
|
6216
|
+
var observer = UtilsContext.mutationObserver(parent, {
|
|
6206
6217
|
config: {
|
|
6207
6218
|
subtree: true,
|
|
6208
6219
|
childList: true,
|
|
@@ -6236,11 +6247,11 @@ class Utils {
|
|
|
6236
6247
|
waitAnyNodeList(...args) {
|
|
6237
6248
|
// 过滤掉undefined
|
|
6238
6249
|
args = args.filter((arg) => arg !== void 0);
|
|
6239
|
-
let
|
|
6250
|
+
let UtilsContext = this;
|
|
6240
6251
|
// 选择器数组
|
|
6241
6252
|
let selectorList = args[0];
|
|
6242
6253
|
// 父元素(监听的元素)
|
|
6243
|
-
let parent =
|
|
6254
|
+
let parent = UtilsContext.windowApi.document;
|
|
6244
6255
|
// 超时时间
|
|
6245
6256
|
let timeout = 0;
|
|
6246
6257
|
if (!Array.isArray(args[0])) {
|
|
@@ -6285,7 +6296,7 @@ class Utils {
|
|
|
6285
6296
|
throw new TypeError("Utils.waitAnyNodeList 参数个数错误");
|
|
6286
6297
|
}
|
|
6287
6298
|
let promiseList = selectorList.map((selector) => {
|
|
6288
|
-
return
|
|
6299
|
+
return UtilsContext.waitNodeList(selector, parent, timeout);
|
|
6289
6300
|
});
|
|
6290
6301
|
return Promise.any(promiseList);
|
|
6291
6302
|
}
|
|
@@ -6488,12 +6499,12 @@ class Utils {
|
|
|
6488
6499
|
if (text.startsWith("//")) {
|
|
6489
6500
|
/* //www.baidu.com/xxxxxxx */
|
|
6490
6501
|
/* 没有protocol,加上 */
|
|
6491
|
-
text =
|
|
6502
|
+
text = this.windowApi.globalThis.location.protocol + text;
|
|
6492
6503
|
}
|
|
6493
6504
|
else if (text.startsWith("/")) {
|
|
6494
6505
|
/* /xxx/info?xxx=xxx */
|
|
6495
6506
|
/* 没有Origin,加上 */
|
|
6496
|
-
text =
|
|
6507
|
+
text = this.windowApi.globalThis.location.origin + text;
|
|
6497
6508
|
}
|
|
6498
6509
|
return new URL(text);
|
|
6499
6510
|
}
|