@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 +44 -11
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +44 -11
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +44 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +44 -11
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +44 -11
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +44 -11
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +2 -1
- package/package.json +1 -1
- package/src/Utils.ts +47 -13
package/dist/index.system.js
CHANGED
|
@@ -242,7 +242,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
242
242
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
243
243
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
244
244
|
|
|
245
|
-
const version = "2.11.
|
|
245
|
+
const version = "2.11.2";
|
|
246
246
|
|
|
247
247
|
/* eslint-disable */
|
|
248
248
|
// ==UserScript==
|
|
@@ -7994,9 +7994,22 @@ System.register('Utils', [], (function (exports) {
|
|
|
7994
7994
|
return result;
|
|
7995
7995
|
}
|
|
7996
7996
|
else {
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
7997
|
+
const compareSet = new Set(compareArrayData);
|
|
7998
|
+
const result = [];
|
|
7999
|
+
for (let i = 0; i < uniqueArrayData.length; i++) {
|
|
8000
|
+
const item = uniqueArrayData[i];
|
|
8001
|
+
let flag = false;
|
|
8002
|
+
for (const compareItem of compareSet) {
|
|
8003
|
+
if (compareFun(item, compareItem)) {
|
|
8004
|
+
flag = true;
|
|
8005
|
+
break;
|
|
8006
|
+
}
|
|
8007
|
+
}
|
|
8008
|
+
if (!flag) {
|
|
8009
|
+
result.push(item);
|
|
8010
|
+
}
|
|
8011
|
+
}
|
|
8012
|
+
return result;
|
|
8000
8013
|
}
|
|
8001
8014
|
}
|
|
8002
8015
|
/**
|
|
@@ -8376,10 +8389,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
8376
8389
|
}
|
|
8377
8390
|
/**
|
|
8378
8391
|
* 判断页面中是否存在`worker-src`的CSP规则
|
|
8392
|
+
* @param timeout 超时时间,默认为`1500ms`
|
|
8379
8393
|
*/
|
|
8380
|
-
hasWorkerCSP() {
|
|
8394
|
+
hasWorkerCSP(timeout = 1500) {
|
|
8381
8395
|
return new Promise((resolve) => {
|
|
8382
8396
|
let flag = true;
|
|
8397
|
+
let timeId = void 0;
|
|
8398
|
+
let worker = void 0;
|
|
8383
8399
|
let workerBlobUrl = void 0;
|
|
8384
8400
|
const workerJs = /*js*/ `
|
|
8385
8401
|
(() => {
|
|
@@ -8395,11 +8411,26 @@ System.register('Utils', [], (function (exports) {
|
|
|
8395
8411
|
}
|
|
8396
8412
|
);
|
|
8397
8413
|
})();`;
|
|
8414
|
+
/**
|
|
8415
|
+
* 返回结果
|
|
8416
|
+
*/
|
|
8417
|
+
const finishCallBack = () => {
|
|
8418
|
+
clearTimeout(timeId);
|
|
8419
|
+
if (worker != null) {
|
|
8420
|
+
worker.terminate();
|
|
8421
|
+
}
|
|
8422
|
+
// 释放
|
|
8423
|
+
if (typeof workerBlobUrl === "string") {
|
|
8424
|
+
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
8425
|
+
workerBlobUrl = void 0;
|
|
8426
|
+
}
|
|
8427
|
+
resolve(flag);
|
|
8428
|
+
};
|
|
8398
8429
|
try {
|
|
8399
8430
|
const workerScript = new Blob([workerJs], {
|
|
8400
8431
|
type: "application/javascript",
|
|
8401
8432
|
});
|
|
8402
|
-
workerBlobUrl =
|
|
8433
|
+
workerBlobUrl = globalThis.URL.createObjectURL(workerScript);
|
|
8403
8434
|
// @ts-expect-error
|
|
8404
8435
|
if (globalThis.trustedTypes && typeof globalThis.trustedTypes.createPolicy === "function") {
|
|
8405
8436
|
// 使用这个后虽然不报错,但是仍会有blob错误
|
|
@@ -8411,25 +8442,27 @@ System.register('Utils', [], (function (exports) {
|
|
|
8411
8442
|
});
|
|
8412
8443
|
workerBlobUrl = workerPolicy.createScriptURL(workerBlobUrl);
|
|
8413
8444
|
}
|
|
8414
|
-
|
|
8445
|
+
worker = new Worker(workerBlobUrl);
|
|
8415
8446
|
worker.onmessage = (data) => {
|
|
8416
8447
|
if (data.data.success) {
|
|
8417
8448
|
flag = false;
|
|
8449
|
+
finishCallBack();
|
|
8418
8450
|
}
|
|
8419
8451
|
};
|
|
8420
|
-
setTimeout(() => {
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
}, 500);
|
|
8452
|
+
timeId = setTimeout(() => {
|
|
8453
|
+
finishCallBack();
|
|
8454
|
+
}, timeout);
|
|
8424
8455
|
worker.postMessage("test");
|
|
8425
8456
|
}
|
|
8426
8457
|
catch {
|
|
8427
8458
|
flag = true;
|
|
8459
|
+
finishCallBack();
|
|
8428
8460
|
}
|
|
8429
8461
|
finally {
|
|
8430
8462
|
// 释放
|
|
8431
8463
|
if (typeof workerBlobUrl === "string") {
|
|
8432
8464
|
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
8465
|
+
workerBlobUrl = void 0;
|
|
8433
8466
|
}
|
|
8434
8467
|
}
|
|
8435
8468
|
});
|