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