@whitesev/utils 2.11.0 → 2.11.2

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 CHANGED
@@ -239,7 +239,7 @@ define((function () { 'use strict';
239
239
  const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
240
240
  const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
241
241
 
242
- const version = "2.11.0";
242
+ const version = "2.11.2";
243
243
 
244
244
  /* eslint-disable */
245
245
  // ==UserScript==
@@ -7991,9 +7991,22 @@ define((function () { 'use strict';
7991
7991
  return result;
7992
7992
  }
7993
7993
  else {
7994
- return Array.from(uniqueArrayData).filter((item) => !Array.from(compareArrayData).some(function (item2) {
7995
- return compareFun(item, item2);
7996
- }));
7994
+ const compareSet = new Set(compareArrayData);
7995
+ const result = [];
7996
+ for (let i = 0; i < uniqueArrayData.length; i++) {
7997
+ const item = uniqueArrayData[i];
7998
+ let flag = false;
7999
+ for (const compareItem of compareSet) {
8000
+ if (compareFun(item, compareItem)) {
8001
+ flag = true;
8002
+ break;
8003
+ }
8004
+ }
8005
+ if (!flag) {
8006
+ result.push(item);
8007
+ }
8008
+ }
8009
+ return result;
7997
8010
  }
7998
8011
  }
7999
8012
  /**
@@ -8373,10 +8386,13 @@ define((function () { 'use strict';
8373
8386
  }
8374
8387
  /**
8375
8388
  * 判断页面中是否存在`worker-src`的CSP规则
8389
+ * @param timeout 超时时间,默认为`1500ms`
8376
8390
  */
8377
- hasWorkerCSP() {
8391
+ hasWorkerCSP(timeout = 1500) {
8378
8392
  return new Promise((resolve) => {
8379
8393
  let flag = true;
8394
+ let timeId = void 0;
8395
+ let worker = void 0;
8380
8396
  let workerBlobUrl = void 0;
8381
8397
  const workerJs = /*js*/ `
8382
8398
  (() => {
@@ -8392,11 +8408,26 @@ define((function () { 'use strict';
8392
8408
  }
8393
8409
  );
8394
8410
  })();`;
8411
+ /**
8412
+ * 返回结果
8413
+ */
8414
+ const finishCallBack = () => {
8415
+ clearTimeout(timeId);
8416
+ if (worker != null) {
8417
+ worker.terminate();
8418
+ }
8419
+ // 释放
8420
+ if (typeof workerBlobUrl === "string") {
8421
+ globalThis.URL.revokeObjectURL(workerBlobUrl);
8422
+ workerBlobUrl = void 0;
8423
+ }
8424
+ resolve(flag);
8425
+ };
8395
8426
  try {
8396
8427
  const workerScript = new Blob([workerJs], {
8397
8428
  type: "application/javascript",
8398
8429
  });
8399
- workerBlobUrl = window.URL.createObjectURL(workerScript);
8430
+ workerBlobUrl = globalThis.URL.createObjectURL(workerScript);
8400
8431
  // @ts-expect-error
8401
8432
  if (globalThis.trustedTypes && typeof globalThis.trustedTypes.createPolicy === "function") {
8402
8433
  // 使用这个后虽然不报错,但是仍会有blob错误
@@ -8408,25 +8439,27 @@ define((function () { 'use strict';
8408
8439
  });
8409
8440
  workerBlobUrl = workerPolicy.createScriptURL(workerBlobUrl);
8410
8441
  }
8411
- const worker = new Worker(workerBlobUrl);
8442
+ worker = new Worker(workerBlobUrl);
8412
8443
  worker.onmessage = (data) => {
8413
8444
  if (data.data.success) {
8414
8445
  flag = false;
8446
+ finishCallBack();
8415
8447
  }
8416
8448
  };
8417
- setTimeout(() => {
8418
- worker.terminate();
8419
- resolve(flag);
8420
- }, 500);
8449
+ timeId = setTimeout(() => {
8450
+ finishCallBack();
8451
+ }, timeout);
8421
8452
  worker.postMessage("test");
8422
8453
  }
8423
8454
  catch {
8424
8455
  flag = true;
8456
+ finishCallBack();
8425
8457
  }
8426
8458
  finally {
8427
8459
  // 释放
8428
8460
  if (typeof workerBlobUrl === "string") {
8429
8461
  globalThis.URL.revokeObjectURL(workerBlobUrl);
8462
+ workerBlobUrl = void 0;
8430
8463
  }
8431
8464
  }
8432
8465
  });