@whitesev/utils 2.9.12 → 2.10.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.
- package/README.md +176 -176
- package/dist/index.amd.js +206 -117
- 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 +206 -117
- 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 +206 -117
- 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 +206 -117
- 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 +206 -117
- 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 +206 -117
- 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/Dictionary.d.ts +2 -0
- package/dist/types/src/Utils.d.ts +9 -2
- package/dist/types/src/types/Httpx.d.ts +1344 -1344
- package/dist/types/src/types/Log.d.ts +19 -19
- package/dist/types/src/types/Progress.d.ts +20 -20
- package/dist/types/src/types/React.d.ts +119 -119
- package/dist/types/src/types/TryCatch.d.ts +9 -9
- package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
- package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
- package/dist/types/src/types/Vue2.d.ts +166 -166
- package/dist/types/src/types/WindowApi.d.ts +14 -14
- package/dist/types/src/types/ajaxHooker.d.ts +155 -155
- package/dist/types/src/types/env.d.ts +7 -7
- package/dist/types/src/types/global.d.ts +31 -31
- package/package.json +26 -24
- package/src/ColorConversion.ts +118 -118
- package/src/CommonUtil.ts +301 -301
- package/src/DOMUtils.ts +251 -251
- package/src/Dictionary.ts +205 -199
- package/src/GBKEncoder.ts +108 -108
- package/src/Hooks.ts +73 -73
- package/src/Httpx.ts +1457 -1457
- package/src/LockFunction.ts +65 -62
- package/src/Log.ts +233 -233
- package/src/ModuleRaid.js +378 -360
- package/src/Progress.ts +108 -108
- package/src/TryCatch.ts +86 -86
- package/src/Utils.ts +3907 -3852
- package/src/UtilsCommon.ts +14 -14
- package/src/UtilsGMCookie.ts +273 -273
- package/src/UtilsGMMenu.ts +460 -460
- package/src/Vue.ts +233 -233
- package/src/WindowApi.ts +59 -59
- package/src/ajaxHooker/ajaxHooker.js +606 -538
- package/src/ajaxHooker/ajaxHooker1.2.4.js +440 -438
- package/src/indexedDB.ts +497 -497
- package/src/types/Httpx.d.ts +1344 -1344
- package/src/types/Log.d.ts +19 -19
- package/src/types/Progress.d.ts +20 -20
- package/src/types/React.d.ts +119 -119
- package/src/types/TryCatch.d.ts +9 -9
- package/src/types/UtilsGMCookie.d.ts +93 -93
- package/src/types/UtilsGMMenu.d.ts +77 -77
- package/src/types/Vue2.d.ts +166 -166
- package/src/types/WindowApi.d.ts +14 -14
- package/src/types/ajaxHooker.d.ts +155 -155
- package/src/types/env.d.ts +7 -7
- package/src/types/global.d.ts +31 -31
package/dist/index.iife.js
CHANGED
|
@@ -58,47 +58,7 @@ var Utils = (function () {
|
|
|
58
58
|
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
59
59
|
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
60
60
|
|
|
61
|
-
const
|
|
62
|
-
return typeof sender.start === 'function';
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const PORT_MAP = new WeakMap();
|
|
66
|
-
|
|
67
|
-
const extendBrokerImplementation = (partialBrokerImplementation) => ({
|
|
68
|
-
...partialBrokerImplementation,
|
|
69
|
-
connect: ({ call }) => {
|
|
70
|
-
return async () => {
|
|
71
|
-
const { port1, port2 } = new MessageChannel();
|
|
72
|
-
const portId = await call('connect', { port: port1 }, [port1]);
|
|
73
|
-
PORT_MAP.set(port2, portId);
|
|
74
|
-
return port2;
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
disconnect: ({ call }) => {
|
|
78
|
-
return async (port) => {
|
|
79
|
-
const portId = PORT_MAP.get(port);
|
|
80
|
-
if (portId === undefined) {
|
|
81
|
-
throw new Error('The given port is not connected.');
|
|
82
|
-
}
|
|
83
|
-
await call('disconnect', { portId });
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
isSupported: ({ call }) => {
|
|
87
|
-
return () => call('isSupported');
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const ONGOING_REQUESTS = new WeakMap();
|
|
92
|
-
const createOrGetOngoingRequests = (sender) => {
|
|
93
|
-
if (ONGOING_REQUESTS.has(sender)) {
|
|
94
|
-
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
95
|
-
return ONGOING_REQUESTS.get(sender);
|
|
96
|
-
}
|
|
97
|
-
const ongoingRequests = new Map();
|
|
98
|
-
ONGOING_REQUESTS.set(sender, ongoingRequests);
|
|
99
|
-
return ongoingRequests;
|
|
100
|
-
};
|
|
101
|
-
const createBroker = (brokerImplementation) => {
|
|
61
|
+
const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
|
|
102
62
|
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
103
63
|
return (sender) => {
|
|
104
64
|
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
@@ -141,6 +101,46 @@ var Utils = (function () {
|
|
|
141
101
|
};
|
|
142
102
|
};
|
|
143
103
|
|
|
104
|
+
const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
|
|
105
|
+
if (ongoingRequestsMap.has(sender)) {
|
|
106
|
+
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
107
|
+
return ongoingRequestsMap.get(sender);
|
|
108
|
+
}
|
|
109
|
+
const ongoingRequests = new Map();
|
|
110
|
+
ongoingRequestsMap.set(sender, ongoingRequests);
|
|
111
|
+
return ongoingRequests;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
|
|
115
|
+
...partialBrokerImplementation,
|
|
116
|
+
connect: ({ call }) => {
|
|
117
|
+
return async () => {
|
|
118
|
+
const { port1, port2 } = new MessageChannel();
|
|
119
|
+
const portId = await call('connect', { port: port1 }, [port1]);
|
|
120
|
+
portMap.set(port2, portId);
|
|
121
|
+
return port2;
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
disconnect: ({ call }) => {
|
|
125
|
+
return async (port) => {
|
|
126
|
+
const portId = portMap.get(port);
|
|
127
|
+
if (portId === undefined) {
|
|
128
|
+
throw new Error('The given port is not connected.');
|
|
129
|
+
}
|
|
130
|
+
await call('disconnect', { portId });
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
isSupported: ({ call }) => {
|
|
134
|
+
return () => call('isSupported');
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const isMessagePort = (sender) => {
|
|
139
|
+
return typeof sender.start === 'function';
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
|
|
143
|
+
|
|
144
144
|
const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
|
|
145
145
|
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
146
146
|
scheduledIntervalsState.set(timerId, null);
|
|
@@ -232,15 +232,15 @@ var Utils = (function () {
|
|
|
232
232
|
};
|
|
233
233
|
|
|
234
234
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
235
|
-
const worker = `(()=>{var e={455
|
|
235
|
+
const worker = `(()=>{var e={455(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),l=t(c);e.addUniqueNumber=l,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o('The handler of the method called "'.concat(t,'" returned an unexpected result.'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o('The requested method called "'.concat(e,'" is not supported.'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o('The handler of the method called "'.concat(t,'" returned no required result.'),e))(i);const l=r instanceof Promise?await r:r;if(null===a){if(void 0!==l.result)throw s(i)}else{if(void 0===l.result)throw s(i);const{result:e,transferables:r=[]}=l;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,()=>{n(),t.close(),u.delete(o)}),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise(e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])})){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),l=(e,t,r=()=>!0)=>{const n=c(l,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},d=(e,t)=>r=>{const n=t.get(r);if(void 0===n)return Promise.resolve(!1);const[o,s]=n;return e(o),t.delete(r),s(!1),Promise.resolve(!0)},m=(e,t,r,n)=>(o,s,a)=>{const i=o+s-t.timeOrigin,u=i-t.now();return new Promise(t=>{e.set(a,[r(n,u,i,e,t,a),t])})},f=new Map,h=d(globalThis.clearTimeout,f),p=new Map,v=d(globalThis.clearTimeout,p),w=((e,t)=>{const r=(n,o,s,a)=>{const i=n-e.now();i>0?o.set(a,[t(r,i,n,o,s,a),s]):(o.delete(a),s(!0))};return r})(performance,globalThis.setTimeout),g=m(f,performance,globalThis.setTimeout,w),T=m(p,performance,globalThis.setTimeout,w);l(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?h(e):v(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?g:T)(e,t,r)})})})()})();`; // tslint:disable-line:max-line-length
|
|
236
236
|
|
|
237
237
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
238
|
-
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
238
|
+
const clearInterval$1 = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
239
239
|
const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
240
|
-
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
240
|
+
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
241
241
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
242
242
|
|
|
243
|
-
const version = "2.
|
|
243
|
+
const version = "2.10.0";
|
|
244
244
|
|
|
245
245
|
/* eslint-disable */
|
|
246
246
|
// ==UserScript==
|
|
@@ -280,7 +280,9 @@ var Utils = (function () {
|
|
|
280
280
|
const emptyFn = () => { };
|
|
281
281
|
const errorFn = (e) => console.error(e);
|
|
282
282
|
function isThenable(obj) {
|
|
283
|
-
return
|
|
283
|
+
return (obj &&
|
|
284
|
+
["object", "function"].includes(typeof obj) &&
|
|
285
|
+
typeof obj.then === "function");
|
|
284
286
|
}
|
|
285
287
|
function catchError(fn, ...args) {
|
|
286
288
|
try {
|
|
@@ -321,7 +323,8 @@ var Utils = (function () {
|
|
|
321
323
|
if (!value)
|
|
322
324
|
continue;
|
|
323
325
|
const lheader = header.toLowerCase();
|
|
324
|
-
headers[lheader] =
|
|
326
|
+
headers[lheader] =
|
|
327
|
+
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
325
328
|
}
|
|
326
329
|
break;
|
|
327
330
|
case "[object Headers]":
|
|
@@ -360,9 +363,11 @@ var Utils = (function () {
|
|
|
360
363
|
!filters.find((obj) => {
|
|
361
364
|
switch (true) {
|
|
362
365
|
case obj.type && obj.type !== type:
|
|
363
|
-
case getType(obj.url) === "[object String]" &&
|
|
366
|
+
case getType(obj.url) === "[object String]" &&
|
|
367
|
+
!url.includes(obj.url):
|
|
364
368
|
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
365
|
-
case obj.method &&
|
|
369
|
+
case obj.method &&
|
|
370
|
+
obj.method.toUpperCase() !== method.toUpperCase():
|
|
366
371
|
case "async" in obj && obj.async !== async:
|
|
367
372
|
return false;
|
|
368
373
|
}
|
|
@@ -405,7 +410,8 @@ var Utils = (function () {
|
|
|
405
410
|
if (getType(this.request.response) === "[object Function]") {
|
|
406
411
|
catchError(this.request.response, response);
|
|
407
412
|
responseKeys.forEach((key) => {
|
|
408
|
-
if ("get" in getDescriptor(response, key) ||
|
|
413
|
+
if ("get" in getDescriptor(response, key) ||
|
|
414
|
+
isThenable(response[key])) {
|
|
409
415
|
delete response[key];
|
|
410
416
|
}
|
|
411
417
|
});
|
|
@@ -426,7 +432,10 @@ var Utils = (function () {
|
|
|
426
432
|
const proxyHandler = {
|
|
427
433
|
get(target, prop) {
|
|
428
434
|
const descriptor = getDescriptor(target, prop);
|
|
429
|
-
if (descriptor &&
|
|
435
|
+
if (descriptor &&
|
|
436
|
+
!descriptor.configurable &&
|
|
437
|
+
!descriptor.writable &&
|
|
438
|
+
!descriptor.get)
|
|
430
439
|
return target[prop];
|
|
431
440
|
const ah = target.__ajaxHooker;
|
|
432
441
|
if (ah && ah.proxyProps) {
|
|
@@ -445,7 +454,10 @@ var Utils = (function () {
|
|
|
445
454
|
},
|
|
446
455
|
set(target, prop, value) {
|
|
447
456
|
const descriptor = getDescriptor(target, prop);
|
|
448
|
-
if (descriptor &&
|
|
457
|
+
if (descriptor &&
|
|
458
|
+
!descriptor.configurable &&
|
|
459
|
+
!descriptor.writable &&
|
|
460
|
+
!descriptor.set)
|
|
449
461
|
return true;
|
|
450
462
|
const ah = target.__ajaxHooker;
|
|
451
463
|
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
@@ -469,7 +481,9 @@ var Utils = (function () {
|
|
|
469
481
|
proxyEvents: {},
|
|
470
482
|
});
|
|
471
483
|
xhr.addEventListener("readystatechange", (e) => {
|
|
472
|
-
if (ah.proxyXhr.readyState === 4 &&
|
|
484
|
+
if (ah.proxyXhr.readyState === 4 &&
|
|
485
|
+
ah.request &&
|
|
486
|
+
typeof ah.request.response === "function") {
|
|
473
487
|
const response = {
|
|
474
488
|
finalUrl: ah.proxyXhr.responseURL,
|
|
475
489
|
status: ah.proxyXhr.status,
|
|
@@ -488,7 +502,9 @@ var Utils = (function () {
|
|
|
488
502
|
response[key] = val;
|
|
489
503
|
});
|
|
490
504
|
}
|
|
491
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
505
|
+
ah.resThenable = new AHRequest(ah.request)
|
|
506
|
+
.waitForResponseKeys(response)
|
|
507
|
+
.then(() => {
|
|
492
508
|
for (const key of xhrResponses) {
|
|
493
509
|
ah.proxyProps[key] = {
|
|
494
510
|
get: () => {
|
|
@@ -511,7 +527,13 @@ var Utils = (function () {
|
|
|
511
527
|
set: (val) => ah.addEvent(onEvt, val),
|
|
512
528
|
};
|
|
513
529
|
}
|
|
514
|
-
for (const method of [
|
|
530
|
+
for (const method of [
|
|
531
|
+
"setRequestHeader",
|
|
532
|
+
"addEventListener",
|
|
533
|
+
"removeEventListener",
|
|
534
|
+
"open",
|
|
535
|
+
"send",
|
|
536
|
+
]) {
|
|
515
537
|
ah.proxyProps[method] = { value: ah[method] };
|
|
516
538
|
}
|
|
517
539
|
}
|
|
@@ -558,7 +580,8 @@ var Utils = (function () {
|
|
|
558
580
|
if (!this.request)
|
|
559
581
|
return;
|
|
560
582
|
const headers = this.request.headers;
|
|
561
|
-
headers[header] =
|
|
583
|
+
headers[header] =
|
|
584
|
+
header in headers ? `${headers[header]}, ${value}` : value;
|
|
562
585
|
}
|
|
563
586
|
addEventListener(...args) {
|
|
564
587
|
if (xhrAsyncEvents.includes(args[0])) {
|
|
@@ -589,7 +612,13 @@ var Utils = (function () {
|
|
|
589
612
|
};
|
|
590
613
|
this.openArgs = args;
|
|
591
614
|
this.resThenable = new SyncThenable();
|
|
592
|
-
[
|
|
615
|
+
[
|
|
616
|
+
"responseURL",
|
|
617
|
+
"readyState",
|
|
618
|
+
"status",
|
|
619
|
+
"statusText",
|
|
620
|
+
...xhrResponses,
|
|
621
|
+
].forEach((key) => {
|
|
593
622
|
delete this.proxyProps[key];
|
|
594
623
|
});
|
|
595
624
|
return this.originalXhr.open(method, url, async, ...args);
|
|
@@ -751,13 +780,17 @@ var Utils = (function () {
|
|
|
751
780
|
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
752
781
|
class AHFunction extends Function {
|
|
753
782
|
call(thisArg, ...args) {
|
|
754
|
-
if (thisArg &&
|
|
783
|
+
if (thisArg &&
|
|
784
|
+
thisArg.__ajaxHooker &&
|
|
785
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
755
786
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
756
787
|
}
|
|
757
788
|
return Reflect.apply(this, thisArg, args);
|
|
758
789
|
}
|
|
759
790
|
apply(thisArg, args) {
|
|
760
|
-
if (thisArg &&
|
|
791
|
+
if (thisArg &&
|
|
792
|
+
thisArg.__ajaxHooker &&
|
|
793
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
761
794
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
762
795
|
}
|
|
763
796
|
return Reflect.apply(this, thisArg, args || []);
|
|
@@ -1656,6 +1689,12 @@ var Utils = (function () {
|
|
|
1656
1689
|
this.set(key, value);
|
|
1657
1690
|
}
|
|
1658
1691
|
}
|
|
1692
|
+
[Symbol.dispose]() {
|
|
1693
|
+
this.clear();
|
|
1694
|
+
}
|
|
1695
|
+
async [Symbol.asyncDispose]() {
|
|
1696
|
+
this.clear();
|
|
1697
|
+
}
|
|
1659
1698
|
/**
|
|
1660
1699
|
* 获取字典的长度,同this.size
|
|
1661
1700
|
*/
|
|
@@ -2167,11 +2206,11 @@ var Utils = (function () {
|
|
|
2167
2206
|
return "";
|
|
2168
2207
|
}
|
|
2169
2208
|
try {
|
|
2170
|
-
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2171
|
-
let args = Array.prototype.slice.call(arguments, 0);
|
|
2172
|
-
let obj = this;
|
|
2173
|
-
hookFunc.apply(obj, args);
|
|
2174
|
-
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2209
|
+
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2210
|
+
let args = Array.prototype.slice.call(arguments, 0);
|
|
2211
|
+
let obj = this;
|
|
2212
|
+
hookFunc.apply(obj, args);
|
|
2213
|
+
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2175
2214
|
};`)(_context, _funcName, hookFunc);
|
|
2176
2215
|
_context[_funcName].prototype.isHooked = true;
|
|
2177
2216
|
return true;
|
|
@@ -4191,11 +4230,11 @@ var Utils = (function () {
|
|
|
4191
4230
|
this.constructors = [];
|
|
4192
4231
|
let options = {
|
|
4193
4232
|
target: window,
|
|
4194
|
-
entrypoint:
|
|
4233
|
+
entrypoint: "webpackJsonp",
|
|
4195
4234
|
debug: false,
|
|
4196
4235
|
strict: false,
|
|
4197
4236
|
};
|
|
4198
|
-
if (typeof opts ===
|
|
4237
|
+
if (typeof opts === "object") {
|
|
4199
4238
|
options = Object.assign(Object.assign({}, options), opts);
|
|
4200
4239
|
}
|
|
4201
4240
|
this.target = options.target;
|
|
@@ -4234,7 +4273,7 @@ var Utils = (function () {
|
|
|
4234
4273
|
* @internal
|
|
4235
4274
|
*/
|
|
4236
4275
|
fillModules() {
|
|
4237
|
-
if (typeof this.target[this.entrypoint] ===
|
|
4276
|
+
if (typeof this.target[this.entrypoint] === "function") {
|
|
4238
4277
|
this.functionArguments.forEach((argument, index) => {
|
|
4239
4278
|
try {
|
|
4240
4279
|
if (this.modules && Object.keys(this.modules).length > 0)
|
|
@@ -4261,8 +4300,9 @@ var Utils = (function () {
|
|
|
4261
4300
|
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4262
4301
|
let moduleEnd = false;
|
|
4263
4302
|
let moduleIterator = 0;
|
|
4264
|
-
if (typeof this.target[this.entrypoint] !=
|
|
4265
|
-
|
|
4303
|
+
if (typeof this.target[this.entrypoint] != "function" ||
|
|
4304
|
+
!this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4305
|
+
throw Error("Unknown Webpack structure");
|
|
4266
4306
|
}
|
|
4267
4307
|
while (!moduleEnd) {
|
|
4268
4308
|
try {
|
|
@@ -4295,7 +4335,7 @@ var Utils = (function () {
|
|
|
4295
4335
|
const originalPush = this.target[this.entrypoint].push;
|
|
4296
4336
|
this.target[this.entrypoint].push = (...args) => {
|
|
4297
4337
|
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4298
|
-
document.dispatchEvent(new CustomEvent(
|
|
4338
|
+
document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
|
|
4299
4339
|
return result;
|
|
4300
4340
|
};
|
|
4301
4341
|
}
|
|
@@ -4318,13 +4358,15 @@ var Utils = (function () {
|
|
|
4318
4358
|
}
|
|
4319
4359
|
let windowObjects = Object.keys(this.target);
|
|
4320
4360
|
windowObjects = windowObjects
|
|
4321
|
-
.filter((object) => object.toLowerCase().includes(
|
|
4322
|
-
.
|
|
4361
|
+
.filter((object) => object.toLowerCase().includes("chunk") ||
|
|
4362
|
+
object.toLowerCase().includes("webpack"))
|
|
4363
|
+
.filter((object) => typeof this.target[object] === "function" ||
|
|
4364
|
+
Array.isArray(this.target[object]));
|
|
4323
4365
|
if (windowObjects.length > 1) {
|
|
4324
|
-
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(
|
|
4366
|
+
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(", ")}`);
|
|
4325
4367
|
}
|
|
4326
4368
|
if (windowObjects.length === 0) {
|
|
4327
|
-
throw Error(
|
|
4369
|
+
throw Error("No Webpack JSONP entrypoints could be detected");
|
|
4328
4370
|
}
|
|
4329
4371
|
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4330
4372
|
this.entrypoint = windowObjects[0];
|
|
@@ -4341,11 +4383,11 @@ var Utils = (function () {
|
|
|
4341
4383
|
for (const key in object) {
|
|
4342
4384
|
const value = object[key];
|
|
4343
4385
|
const lowerCaseQuery = query.toLowerCase();
|
|
4344
|
-
if (typeof value !=
|
|
4386
|
+
if (typeof value != "object") {
|
|
4345
4387
|
const lowerCaseKey = key.toString().toLowerCase();
|
|
4346
4388
|
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4347
4389
|
return true;
|
|
4348
|
-
if (typeof value !=
|
|
4390
|
+
if (typeof value != "object") {
|
|
4349
4391
|
const lowerCaseValue = value.toString().toLowerCase();
|
|
4350
4392
|
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4351
4393
|
return true;
|
|
@@ -4385,31 +4427,31 @@ var Utils = (function () {
|
|
|
4385
4427
|
const results = [];
|
|
4386
4428
|
const modules = Object.keys(this.modules);
|
|
4387
4429
|
if (modules.length === 0) {
|
|
4388
|
-
throw new Error(
|
|
4430
|
+
throw new Error("There are no modules to search through!");
|
|
4389
4431
|
}
|
|
4390
4432
|
modules.forEach((key) => {
|
|
4391
4433
|
const module = this.modules[key.toString()];
|
|
4392
4434
|
if (module === undefined)
|
|
4393
4435
|
return;
|
|
4394
4436
|
try {
|
|
4395
|
-
if (typeof query ===
|
|
4437
|
+
if (typeof query === "string") {
|
|
4396
4438
|
query = query.toLowerCase();
|
|
4397
4439
|
switch (typeof module) {
|
|
4398
|
-
case
|
|
4440
|
+
case "string":
|
|
4399
4441
|
if (module.toLowerCase().includes(query))
|
|
4400
4442
|
results.push(module);
|
|
4401
4443
|
break;
|
|
4402
|
-
case
|
|
4444
|
+
case "function":
|
|
4403
4445
|
if (module.toString().toLowerCase().includes(query))
|
|
4404
4446
|
results.push(module);
|
|
4405
4447
|
break;
|
|
4406
|
-
case
|
|
4448
|
+
case "object":
|
|
4407
4449
|
if (this.searchObject(module, query))
|
|
4408
4450
|
results.push(module);
|
|
4409
4451
|
break;
|
|
4410
4452
|
}
|
|
4411
4453
|
}
|
|
4412
|
-
else if (typeof query ===
|
|
4454
|
+
else if (typeof query === "function") {
|
|
4413
4455
|
if (query(module))
|
|
4414
4456
|
results.push(module);
|
|
4415
4457
|
}
|
|
@@ -4462,17 +4504,17 @@ var Utils = (function () {
|
|
|
4462
4504
|
const results = [];
|
|
4463
4505
|
const constructors = Object.keys(this.constructors);
|
|
4464
4506
|
if (constructors.length === 0) {
|
|
4465
|
-
throw new Error(
|
|
4507
|
+
throw new Error("There are no constructors to search through!");
|
|
4466
4508
|
}
|
|
4467
4509
|
constructors.forEach((key) => {
|
|
4468
4510
|
const constructor = this.constructors[key];
|
|
4469
4511
|
try {
|
|
4470
|
-
if (typeof query ===
|
|
4512
|
+
if (typeof query === "string") {
|
|
4471
4513
|
query = query.toLowerCase();
|
|
4472
4514
|
if (constructor.toString().toLowerCase().includes(query))
|
|
4473
4515
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4474
4516
|
}
|
|
4475
|
-
else if (typeof query ===
|
|
4517
|
+
else if (typeof query === "function") {
|
|
4476
4518
|
if (query(constructor))
|
|
4477
4519
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4478
4520
|
}
|
|
@@ -5679,8 +5721,8 @@ var Utils = (function () {
|
|
|
5679
5721
|
let timer = null;
|
|
5680
5722
|
const that = this;
|
|
5681
5723
|
return function (...args) {
|
|
5682
|
-
|
|
5683
|
-
timer =
|
|
5724
|
+
clearTimeout(timer);
|
|
5725
|
+
timer = setTimeout(function () {
|
|
5684
5726
|
fn.apply(that, args);
|
|
5685
5727
|
}, delay);
|
|
5686
5728
|
};
|
|
@@ -5699,7 +5741,6 @@ var Utils = (function () {
|
|
|
5699
5741
|
**/
|
|
5700
5742
|
Dictionary = UtilsDictionary;
|
|
5701
5743
|
downloadBase64(base64Data, fileName, isIFrame = false) {
|
|
5702
|
-
const that = this;
|
|
5703
5744
|
if (typeof base64Data !== "string") {
|
|
5704
5745
|
throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
|
|
5705
5746
|
}
|
|
@@ -5712,7 +5753,7 @@ var Utils = (function () {
|
|
|
5712
5753
|
$iframe.style.display = "none";
|
|
5713
5754
|
$iframe.src = base64Data;
|
|
5714
5755
|
(this.windowApi.document.body || this.windowApi.document.documentElement).appendChild($iframe);
|
|
5715
|
-
|
|
5756
|
+
setTimeout(() => {
|
|
5716
5757
|
$iframe.contentWindow.document.execCommand("SaveAs", true, fileName);
|
|
5717
5758
|
(this.windowApi.document.body || this.windowApi.document.documentElement).removeChild($iframe);
|
|
5718
5759
|
}, 100);
|
|
@@ -5764,7 +5805,7 @@ var Utils = (function () {
|
|
|
5764
5805
|
}
|
|
5765
5806
|
return strFound ? true : false;
|
|
5766
5807
|
}
|
|
5767
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5808
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5768
5809
|
byteSize = parseInt(byteSize.toString());
|
|
5769
5810
|
if (isNaN(byteSize)) {
|
|
5770
5811
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5772,8 +5813,9 @@ var Utils = (function () {
|
|
|
5772
5813
|
let result = 0;
|
|
5773
5814
|
let resultType = "KB";
|
|
5774
5815
|
const sizeData = {};
|
|
5816
|
+
const unitNumber = Number(unit);
|
|
5775
5817
|
sizeData.B = 1;
|
|
5776
|
-
sizeData.KB =
|
|
5818
|
+
sizeData.KB = unitNumber;
|
|
5777
5819
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5778
5820
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5779
5821
|
sizeData.TB = sizeData.GB * sizeData.KB;
|
|
@@ -7610,7 +7652,6 @@ var Utils = (function () {
|
|
|
7610
7652
|
});
|
|
7611
7653
|
}
|
|
7612
7654
|
setTimeout(callback, delayTime = 0) {
|
|
7613
|
-
const that = this;
|
|
7614
7655
|
if (typeof callback !== "function" && typeof callback !== "string") {
|
|
7615
7656
|
throw new TypeError("Utils.setTimeout 参数 callback 必须为 function|string 类型");
|
|
7616
7657
|
}
|
|
@@ -7618,18 +7659,17 @@ var Utils = (function () {
|
|
|
7618
7659
|
throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
|
|
7619
7660
|
}
|
|
7620
7661
|
return new Promise((resolve) => {
|
|
7621
|
-
|
|
7622
|
-
resolve(
|
|
7662
|
+
setTimeout(() => {
|
|
7663
|
+
resolve(this.tryCatch().run(callback));
|
|
7623
7664
|
}, delayTime);
|
|
7624
7665
|
});
|
|
7625
7666
|
}
|
|
7626
7667
|
sleep(delayTime = 0) {
|
|
7627
|
-
const that = this;
|
|
7628
7668
|
if (typeof delayTime !== "number") {
|
|
7629
7669
|
throw new Error("Utils.sleep 参数 delayTime 必须为 number 类型");
|
|
7630
7670
|
}
|
|
7631
7671
|
return new Promise((resolve) => {
|
|
7632
|
-
|
|
7672
|
+
setTimeout(() => {
|
|
7633
7673
|
resolve(void 0);
|
|
7634
7674
|
}, delayTime);
|
|
7635
7675
|
});
|
|
@@ -7955,13 +7995,12 @@ var Utils = (function () {
|
|
|
7955
7995
|
});
|
|
7956
7996
|
}
|
|
7957
7997
|
waitPropertyByInterval(checkFn, propertyName, intervalTimer = 250, maxTime = -1) {
|
|
7958
|
-
const that = this;
|
|
7959
7998
|
if (checkFn == null) {
|
|
7960
7999
|
throw new TypeError("checkObj 不能为空对象 ");
|
|
7961
8000
|
}
|
|
7962
8001
|
let isResolve = false;
|
|
7963
8002
|
return new Promise((resolve, reject) => {
|
|
7964
|
-
const interval =
|
|
8003
|
+
const interval = setInterval(() => {
|
|
7965
8004
|
let inst = checkFn;
|
|
7966
8005
|
if (typeof checkFn === "function") {
|
|
7967
8006
|
inst = checkFn();
|
|
@@ -7974,14 +8013,14 @@ var Utils = (function () {
|
|
|
7974
8013
|
}
|
|
7975
8014
|
if ((typeof propertyName === "function" && propertyName(inst)) || Reflect.has(inst, propertyName)) {
|
|
7976
8015
|
isResolve = true;
|
|
7977
|
-
|
|
8016
|
+
clearInterval(interval);
|
|
7978
8017
|
resolve(inst[propertyName]);
|
|
7979
8018
|
}
|
|
7980
8019
|
}, intervalTimer);
|
|
7981
8020
|
if (maxTime !== -1) {
|
|
7982
|
-
|
|
8021
|
+
setTimeout(() => {
|
|
7983
8022
|
if (!isResolve) {
|
|
7984
|
-
|
|
8023
|
+
clearInterval(interval);
|
|
7985
8024
|
reject();
|
|
7986
8025
|
}
|
|
7987
8026
|
}, maxTime);
|
|
@@ -8203,9 +8242,8 @@ var Utils = (function () {
|
|
|
8203
8242
|
workerSetTimeout(callback, timeout = 0) {
|
|
8204
8243
|
try {
|
|
8205
8244
|
return setTimeout$1(callback, timeout);
|
|
8206
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8207
8245
|
}
|
|
8208
|
-
catch
|
|
8246
|
+
catch {
|
|
8209
8247
|
return this.windowApi.setTimeout(callback, timeout);
|
|
8210
8248
|
}
|
|
8211
8249
|
}
|
|
@@ -8218,12 +8256,8 @@ var Utils = (function () {
|
|
|
8218
8256
|
if (timeId != null) {
|
|
8219
8257
|
clearTimeout$1(timeId);
|
|
8220
8258
|
}
|
|
8221
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8222
|
-
}
|
|
8223
|
-
catch (error) {
|
|
8224
|
-
// console.log(error);
|
|
8225
8259
|
}
|
|
8226
|
-
|
|
8260
|
+
catch {
|
|
8227
8261
|
this.windowApi.clearTimeout(timeId);
|
|
8228
8262
|
}
|
|
8229
8263
|
}
|
|
@@ -8234,10 +8268,9 @@ var Utils = (function () {
|
|
|
8234
8268
|
*/
|
|
8235
8269
|
workerSetInterval(callback, timeout = 0) {
|
|
8236
8270
|
try {
|
|
8237
|
-
return setInterval(callback, timeout);
|
|
8238
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8271
|
+
return setInterval$1(callback, timeout);
|
|
8239
8272
|
}
|
|
8240
|
-
catch
|
|
8273
|
+
catch {
|
|
8241
8274
|
return this.windowApi.setInterval(callback, timeout);
|
|
8242
8275
|
}
|
|
8243
8276
|
}
|
|
@@ -8248,14 +8281,10 @@ var Utils = (function () {
|
|
|
8248
8281
|
workerClearInterval(timeId) {
|
|
8249
8282
|
try {
|
|
8250
8283
|
if (timeId != null) {
|
|
8251
|
-
clearInterval(timeId);
|
|
8284
|
+
clearInterval$1(timeId);
|
|
8252
8285
|
}
|
|
8253
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8254
|
-
}
|
|
8255
|
-
catch (error) {
|
|
8256
|
-
// console.log(error);
|
|
8257
8286
|
}
|
|
8258
|
-
|
|
8287
|
+
catch {
|
|
8259
8288
|
this.windowApi.clearInterval(timeId);
|
|
8260
8289
|
}
|
|
8261
8290
|
}
|
|
@@ -8276,6 +8305,66 @@ var Utils = (function () {
|
|
|
8276
8305
|
return new FunctionConstructor(...args);
|
|
8277
8306
|
}
|
|
8278
8307
|
}
|
|
8308
|
+
/**
|
|
8309
|
+
* 判断页面中是否存在`worker-src`的CSP规则
|
|
8310
|
+
*/
|
|
8311
|
+
hasWorkerCSP() {
|
|
8312
|
+
return new Promise((resolve) => {
|
|
8313
|
+
let flag = true;
|
|
8314
|
+
let workerBlobUrl = void 0;
|
|
8315
|
+
const workerJs = /*js*/ `
|
|
8316
|
+
(() => {
|
|
8317
|
+
this.addEventListener(
|
|
8318
|
+
"message",
|
|
8319
|
+
function () {
|
|
8320
|
+
this.postMessage({
|
|
8321
|
+
success: true,
|
|
8322
|
+
});
|
|
8323
|
+
},
|
|
8324
|
+
{
|
|
8325
|
+
capture: true,
|
|
8326
|
+
}
|
|
8327
|
+
);
|
|
8328
|
+
})();`;
|
|
8329
|
+
try {
|
|
8330
|
+
const workerScript = new Blob([workerJs], {
|
|
8331
|
+
type: "application/javascript",
|
|
8332
|
+
});
|
|
8333
|
+
workerBlobUrl = window.URL.createObjectURL(workerScript);
|
|
8334
|
+
// @ts-expect-error
|
|
8335
|
+
if (globalThis.trustedTypes && typeof globalThis.trustedTypes.createPolicy === "function") {
|
|
8336
|
+
// 使用这个后虽然不报错,但是仍会有blob错误
|
|
8337
|
+
// violates the following Content Security Policy directive: "worker-src 'self'". The action has been blocked.
|
|
8338
|
+
// 且这个错误无法使用try/catch捕捉,导致本该提醒使用手动匹配的结果并无提醒弹窗
|
|
8339
|
+
// @ts-expect-error
|
|
8340
|
+
const workerPolicy = globalThis.trustedTypes.createPolicy("workerPolicy", {
|
|
8341
|
+
createScriptURL: (url) => url,
|
|
8342
|
+
});
|
|
8343
|
+
workerBlobUrl = workerPolicy.createScriptURL(workerBlobUrl);
|
|
8344
|
+
}
|
|
8345
|
+
const worker = new Worker(workerBlobUrl);
|
|
8346
|
+
worker.onmessage = (data) => {
|
|
8347
|
+
if (data.data.success) {
|
|
8348
|
+
flag = false;
|
|
8349
|
+
}
|
|
8350
|
+
};
|
|
8351
|
+
setTimeout(() => {
|
|
8352
|
+
worker.terminate();
|
|
8353
|
+
resolve(flag);
|
|
8354
|
+
}, 500);
|
|
8355
|
+
worker.postMessage("test");
|
|
8356
|
+
}
|
|
8357
|
+
catch {
|
|
8358
|
+
flag = true;
|
|
8359
|
+
}
|
|
8360
|
+
finally {
|
|
8361
|
+
// 释放
|
|
8362
|
+
if (typeof workerBlobUrl === "string") {
|
|
8363
|
+
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
8364
|
+
}
|
|
8365
|
+
}
|
|
8366
|
+
});
|
|
8367
|
+
}
|
|
8279
8368
|
}
|
|
8280
8369
|
const utils = new Utils();
|
|
8281
8370
|
|