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