@whitesev/utils 2.9.11 → 2.9.13
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 +159 -101
- 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 +159 -101
- 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 +159 -101
- 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 +159 -101
- 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 +159 -101
- 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 +159 -101
- 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 +5 -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 -285
- 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 +3860 -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.system.js
CHANGED
|
@@ -60,47 +60,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
60
60
|
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
61
61
|
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
62
62
|
|
|
63
|
-
const
|
|
64
|
-
return typeof sender.start === 'function';
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const PORT_MAP = new WeakMap();
|
|
68
|
-
|
|
69
|
-
const extendBrokerImplementation = (partialBrokerImplementation) => ({
|
|
70
|
-
...partialBrokerImplementation,
|
|
71
|
-
connect: ({ call }) => {
|
|
72
|
-
return async () => {
|
|
73
|
-
const { port1, port2 } = new MessageChannel();
|
|
74
|
-
const portId = await call('connect', { port: port1 }, [port1]);
|
|
75
|
-
PORT_MAP.set(port2, portId);
|
|
76
|
-
return port2;
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
disconnect: ({ call }) => {
|
|
80
|
-
return async (port) => {
|
|
81
|
-
const portId = PORT_MAP.get(port);
|
|
82
|
-
if (portId === undefined) {
|
|
83
|
-
throw new Error('The given port is not connected.');
|
|
84
|
-
}
|
|
85
|
-
await call('disconnect', { portId });
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
isSupported: ({ call }) => {
|
|
89
|
-
return () => call('isSupported');
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const ONGOING_REQUESTS = new WeakMap();
|
|
94
|
-
const createOrGetOngoingRequests = (sender) => {
|
|
95
|
-
if (ONGOING_REQUESTS.has(sender)) {
|
|
96
|
-
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
97
|
-
return ONGOING_REQUESTS.get(sender);
|
|
98
|
-
}
|
|
99
|
-
const ongoingRequests = new Map();
|
|
100
|
-
ONGOING_REQUESTS.set(sender, ongoingRequests);
|
|
101
|
-
return ongoingRequests;
|
|
102
|
-
};
|
|
103
|
-
const createBroker = (brokerImplementation) => {
|
|
63
|
+
const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
|
|
104
64
|
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
105
65
|
return (sender) => {
|
|
106
66
|
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
@@ -143,6 +103,46 @@ System.register('Utils', [], (function (exports) {
|
|
|
143
103
|
};
|
|
144
104
|
};
|
|
145
105
|
|
|
106
|
+
const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
|
|
107
|
+
if (ongoingRequestsMap.has(sender)) {
|
|
108
|
+
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
109
|
+
return ongoingRequestsMap.get(sender);
|
|
110
|
+
}
|
|
111
|
+
const ongoingRequests = new Map();
|
|
112
|
+
ongoingRequestsMap.set(sender, ongoingRequests);
|
|
113
|
+
return ongoingRequests;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
|
|
117
|
+
...partialBrokerImplementation,
|
|
118
|
+
connect: ({ call }) => {
|
|
119
|
+
return async () => {
|
|
120
|
+
const { port1, port2 } = new MessageChannel();
|
|
121
|
+
const portId = await call('connect', { port: port1 }, [port1]);
|
|
122
|
+
portMap.set(port2, portId);
|
|
123
|
+
return port2;
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
disconnect: ({ call }) => {
|
|
127
|
+
return async (port) => {
|
|
128
|
+
const portId = portMap.get(port);
|
|
129
|
+
if (portId === undefined) {
|
|
130
|
+
throw new Error('The given port is not connected.');
|
|
131
|
+
}
|
|
132
|
+
await call('disconnect', { portId });
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
isSupported: ({ call }) => {
|
|
136
|
+
return () => call('isSupported');
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const isMessagePort = (sender) => {
|
|
141
|
+
return typeof sender.start === 'function';
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
|
|
145
|
+
|
|
146
146
|
const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
|
|
147
147
|
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
148
148
|
scheduledIntervalsState.set(timerId, null);
|
|
@@ -234,7 +234,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
234
234
|
};
|
|
235
235
|
|
|
236
236
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
237
|
-
const worker = `(()=>{var e={455
|
|
237
|
+
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
|
|
238
238
|
|
|
239
239
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
240
240
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -242,7 +242,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
242
242
|
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
243
243
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
244
244
|
|
|
245
|
-
const version = "2.9.
|
|
245
|
+
const version = "2.9.13";
|
|
246
246
|
|
|
247
247
|
/* eslint-disable */
|
|
248
248
|
// ==UserScript==
|
|
@@ -282,7 +282,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
282
282
|
const emptyFn = () => { };
|
|
283
283
|
const errorFn = (e) => console.error(e);
|
|
284
284
|
function isThenable(obj) {
|
|
285
|
-
return
|
|
285
|
+
return (obj &&
|
|
286
|
+
["object", "function"].includes(typeof obj) &&
|
|
287
|
+
typeof obj.then === "function");
|
|
286
288
|
}
|
|
287
289
|
function catchError(fn, ...args) {
|
|
288
290
|
try {
|
|
@@ -323,7 +325,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
323
325
|
if (!value)
|
|
324
326
|
continue;
|
|
325
327
|
const lheader = header.toLowerCase();
|
|
326
|
-
headers[lheader] =
|
|
328
|
+
headers[lheader] =
|
|
329
|
+
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
327
330
|
}
|
|
328
331
|
break;
|
|
329
332
|
case "[object Headers]":
|
|
@@ -362,9 +365,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
362
365
|
!filters.find((obj) => {
|
|
363
366
|
switch (true) {
|
|
364
367
|
case obj.type && obj.type !== type:
|
|
365
|
-
case getType(obj.url) === "[object String]" &&
|
|
368
|
+
case getType(obj.url) === "[object String]" &&
|
|
369
|
+
!url.includes(obj.url):
|
|
366
370
|
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
367
|
-
case obj.method &&
|
|
371
|
+
case obj.method &&
|
|
372
|
+
obj.method.toUpperCase() !== method.toUpperCase():
|
|
368
373
|
case "async" in obj && obj.async !== async:
|
|
369
374
|
return false;
|
|
370
375
|
}
|
|
@@ -407,7 +412,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
407
412
|
if (getType(this.request.response) === "[object Function]") {
|
|
408
413
|
catchError(this.request.response, response);
|
|
409
414
|
responseKeys.forEach((key) => {
|
|
410
|
-
if ("get" in getDescriptor(response, key) ||
|
|
415
|
+
if ("get" in getDescriptor(response, key) ||
|
|
416
|
+
isThenable(response[key])) {
|
|
411
417
|
delete response[key];
|
|
412
418
|
}
|
|
413
419
|
});
|
|
@@ -428,7 +434,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
428
434
|
const proxyHandler = {
|
|
429
435
|
get(target, prop) {
|
|
430
436
|
const descriptor = getDescriptor(target, prop);
|
|
431
|
-
if (descriptor &&
|
|
437
|
+
if (descriptor &&
|
|
438
|
+
!descriptor.configurable &&
|
|
439
|
+
!descriptor.writable &&
|
|
440
|
+
!descriptor.get)
|
|
432
441
|
return target[prop];
|
|
433
442
|
const ah = target.__ajaxHooker;
|
|
434
443
|
if (ah && ah.proxyProps) {
|
|
@@ -447,7 +456,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
447
456
|
},
|
|
448
457
|
set(target, prop, value) {
|
|
449
458
|
const descriptor = getDescriptor(target, prop);
|
|
450
|
-
if (descriptor &&
|
|
459
|
+
if (descriptor &&
|
|
460
|
+
!descriptor.configurable &&
|
|
461
|
+
!descriptor.writable &&
|
|
462
|
+
!descriptor.set)
|
|
451
463
|
return true;
|
|
452
464
|
const ah = target.__ajaxHooker;
|
|
453
465
|
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
@@ -471,7 +483,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
471
483
|
proxyEvents: {},
|
|
472
484
|
});
|
|
473
485
|
xhr.addEventListener("readystatechange", (e) => {
|
|
474
|
-
if (ah.proxyXhr.readyState === 4 &&
|
|
486
|
+
if (ah.proxyXhr.readyState === 4 &&
|
|
487
|
+
ah.request &&
|
|
488
|
+
typeof ah.request.response === "function") {
|
|
475
489
|
const response = {
|
|
476
490
|
finalUrl: ah.proxyXhr.responseURL,
|
|
477
491
|
status: ah.proxyXhr.status,
|
|
@@ -490,7 +504,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
490
504
|
response[key] = val;
|
|
491
505
|
});
|
|
492
506
|
}
|
|
493
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
507
|
+
ah.resThenable = new AHRequest(ah.request)
|
|
508
|
+
.waitForResponseKeys(response)
|
|
509
|
+
.then(() => {
|
|
494
510
|
for (const key of xhrResponses) {
|
|
495
511
|
ah.proxyProps[key] = {
|
|
496
512
|
get: () => {
|
|
@@ -513,7 +529,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
513
529
|
set: (val) => ah.addEvent(onEvt, val),
|
|
514
530
|
};
|
|
515
531
|
}
|
|
516
|
-
for (const method of [
|
|
532
|
+
for (const method of [
|
|
533
|
+
"setRequestHeader",
|
|
534
|
+
"addEventListener",
|
|
535
|
+
"removeEventListener",
|
|
536
|
+
"open",
|
|
537
|
+
"send",
|
|
538
|
+
]) {
|
|
517
539
|
ah.proxyProps[method] = { value: ah[method] };
|
|
518
540
|
}
|
|
519
541
|
}
|
|
@@ -560,7 +582,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
560
582
|
if (!this.request)
|
|
561
583
|
return;
|
|
562
584
|
const headers = this.request.headers;
|
|
563
|
-
headers[header] =
|
|
585
|
+
headers[header] =
|
|
586
|
+
header in headers ? `${headers[header]}, ${value}` : value;
|
|
564
587
|
}
|
|
565
588
|
addEventListener(...args) {
|
|
566
589
|
if (xhrAsyncEvents.includes(args[0])) {
|
|
@@ -591,7 +614,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
591
614
|
};
|
|
592
615
|
this.openArgs = args;
|
|
593
616
|
this.resThenable = new SyncThenable();
|
|
594
|
-
[
|
|
617
|
+
[
|
|
618
|
+
"responseURL",
|
|
619
|
+
"readyState",
|
|
620
|
+
"status",
|
|
621
|
+
"statusText",
|
|
622
|
+
...xhrResponses,
|
|
623
|
+
].forEach((key) => {
|
|
595
624
|
delete this.proxyProps[key];
|
|
596
625
|
});
|
|
597
626
|
return this.originalXhr.open(method, url, async, ...args);
|
|
@@ -753,13 +782,17 @@ System.register('Utils', [], (function (exports) {
|
|
|
753
782
|
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
754
783
|
class AHFunction extends Function {
|
|
755
784
|
call(thisArg, ...args) {
|
|
756
|
-
if (thisArg &&
|
|
785
|
+
if (thisArg &&
|
|
786
|
+
thisArg.__ajaxHooker &&
|
|
787
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
757
788
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
758
789
|
}
|
|
759
790
|
return Reflect.apply(this, thisArg, args);
|
|
760
791
|
}
|
|
761
792
|
apply(thisArg, args) {
|
|
762
|
-
if (thisArg &&
|
|
793
|
+
if (thisArg &&
|
|
794
|
+
thisArg.__ajaxHooker &&
|
|
795
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
763
796
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
764
797
|
}
|
|
765
798
|
return Reflect.apply(this, thisArg, args || []);
|
|
@@ -1476,40 +1509,55 @@ System.register('Utils', [], (function (exports) {
|
|
|
1476
1509
|
isNull(...args) {
|
|
1477
1510
|
let result = true;
|
|
1478
1511
|
const checkList = [...args];
|
|
1479
|
-
for (const
|
|
1480
|
-
let
|
|
1481
|
-
if (
|
|
1482
|
-
|
|
1512
|
+
for (const obj of checkList) {
|
|
1513
|
+
let flag = false;
|
|
1514
|
+
if (obj === null || obj === undefined) {
|
|
1515
|
+
// null undefined
|
|
1516
|
+
flag = true;
|
|
1483
1517
|
}
|
|
1484
1518
|
else {
|
|
1485
|
-
switch (typeof
|
|
1519
|
+
switch (typeof obj) {
|
|
1486
1520
|
case "object":
|
|
1487
|
-
if (typeof
|
|
1488
|
-
|
|
1489
|
-
|
|
1521
|
+
if (typeof obj[Symbol.iterator] === "function") {
|
|
1522
|
+
// 可迭代
|
|
1523
|
+
// Map Array NodeList HTMLCollection
|
|
1524
|
+
if (obj instanceof Map) {
|
|
1525
|
+
flag = obj.size === 0;
|
|
1526
|
+
}
|
|
1527
|
+
else {
|
|
1528
|
+
const length = obj.length;
|
|
1529
|
+
if (typeof length === "number") {
|
|
1530
|
+
flag = length === 0;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1490
1533
|
}
|
|
1491
1534
|
else {
|
|
1492
|
-
|
|
1535
|
+
if (obj?.toString() === "[object Object]") {
|
|
1536
|
+
// {}
|
|
1537
|
+
flag = Object.keys(obj).length === 0;
|
|
1538
|
+
}
|
|
1493
1539
|
}
|
|
1494
1540
|
break;
|
|
1495
1541
|
case "number":
|
|
1496
|
-
|
|
1542
|
+
flag = isNaN(obj) ? true : obj === 0;
|
|
1497
1543
|
break;
|
|
1498
|
-
case "string":
|
|
1499
|
-
|
|
1544
|
+
case "string": {
|
|
1545
|
+
const trimStr = obj.trim();
|
|
1546
|
+
flag = trimStr.trim() === "" || trimStr === "null" || trimStr === "undefined";
|
|
1500
1547
|
break;
|
|
1548
|
+
}
|
|
1501
1549
|
case "boolean":
|
|
1502
|
-
|
|
1550
|
+
flag = !obj;
|
|
1503
1551
|
break;
|
|
1504
1552
|
case "function": {
|
|
1505
|
-
const funcStr =
|
|
1553
|
+
const funcStr = obj.toString().replace(/\s/g, "");
|
|
1506
1554
|
/* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
|
|
1507
|
-
|
|
1555
|
+
flag = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
|
|
1508
1556
|
break;
|
|
1509
1557
|
}
|
|
1510
1558
|
}
|
|
1511
1559
|
}
|
|
1512
|
-
result = result &&
|
|
1560
|
+
result = result && flag;
|
|
1513
1561
|
}
|
|
1514
1562
|
return result;
|
|
1515
1563
|
}
|
|
@@ -1643,6 +1691,12 @@ System.register('Utils', [], (function (exports) {
|
|
|
1643
1691
|
this.set(key, value);
|
|
1644
1692
|
}
|
|
1645
1693
|
}
|
|
1694
|
+
[Symbol.dispose]() {
|
|
1695
|
+
this.clear();
|
|
1696
|
+
}
|
|
1697
|
+
async [Symbol.asyncDispose]() {
|
|
1698
|
+
this.clear();
|
|
1699
|
+
}
|
|
1646
1700
|
/**
|
|
1647
1701
|
* 获取字典的长度,同this.size
|
|
1648
1702
|
*/
|
|
@@ -2154,11 +2208,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
2154
2208
|
return "";
|
|
2155
2209
|
}
|
|
2156
2210
|
try {
|
|
2157
|
-
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2158
|
-
let args = Array.prototype.slice.call(arguments, 0);
|
|
2159
|
-
let obj = this;
|
|
2160
|
-
hookFunc.apply(obj, args);
|
|
2161
|
-
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2211
|
+
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2212
|
+
let args = Array.prototype.slice.call(arguments, 0);
|
|
2213
|
+
let obj = this;
|
|
2214
|
+
hookFunc.apply(obj, args);
|
|
2215
|
+
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2162
2216
|
};`)(_context, _funcName, hookFunc);
|
|
2163
2217
|
_context[_funcName].prototype.isHooked = true;
|
|
2164
2218
|
return true;
|
|
@@ -4178,11 +4232,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
4178
4232
|
this.constructors = [];
|
|
4179
4233
|
let options = {
|
|
4180
4234
|
target: window,
|
|
4181
|
-
entrypoint:
|
|
4235
|
+
entrypoint: "webpackJsonp",
|
|
4182
4236
|
debug: false,
|
|
4183
4237
|
strict: false,
|
|
4184
4238
|
};
|
|
4185
|
-
if (typeof opts ===
|
|
4239
|
+
if (typeof opts === "object") {
|
|
4186
4240
|
options = Object.assign(Object.assign({}, options), opts);
|
|
4187
4241
|
}
|
|
4188
4242
|
this.target = options.target;
|
|
@@ -4221,7 +4275,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4221
4275
|
* @internal
|
|
4222
4276
|
*/
|
|
4223
4277
|
fillModules() {
|
|
4224
|
-
if (typeof this.target[this.entrypoint] ===
|
|
4278
|
+
if (typeof this.target[this.entrypoint] === "function") {
|
|
4225
4279
|
this.functionArguments.forEach((argument, index) => {
|
|
4226
4280
|
try {
|
|
4227
4281
|
if (this.modules && Object.keys(this.modules).length > 0)
|
|
@@ -4248,8 +4302,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
4248
4302
|
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4249
4303
|
let moduleEnd = false;
|
|
4250
4304
|
let moduleIterator = 0;
|
|
4251
|
-
if (typeof this.target[this.entrypoint] !=
|
|
4252
|
-
|
|
4305
|
+
if (typeof this.target[this.entrypoint] != "function" ||
|
|
4306
|
+
!this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4307
|
+
throw Error("Unknown Webpack structure");
|
|
4253
4308
|
}
|
|
4254
4309
|
while (!moduleEnd) {
|
|
4255
4310
|
try {
|
|
@@ -4282,7 +4337,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4282
4337
|
const originalPush = this.target[this.entrypoint].push;
|
|
4283
4338
|
this.target[this.entrypoint].push = (...args) => {
|
|
4284
4339
|
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4285
|
-
document.dispatchEvent(new CustomEvent(
|
|
4340
|
+
document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
|
|
4286
4341
|
return result;
|
|
4287
4342
|
};
|
|
4288
4343
|
}
|
|
@@ -4305,13 +4360,15 @@ System.register('Utils', [], (function (exports) {
|
|
|
4305
4360
|
}
|
|
4306
4361
|
let windowObjects = Object.keys(this.target);
|
|
4307
4362
|
windowObjects = windowObjects
|
|
4308
|
-
.filter((object) => object.toLowerCase().includes(
|
|
4309
|
-
.
|
|
4363
|
+
.filter((object) => object.toLowerCase().includes("chunk") ||
|
|
4364
|
+
object.toLowerCase().includes("webpack"))
|
|
4365
|
+
.filter((object) => typeof this.target[object] === "function" ||
|
|
4366
|
+
Array.isArray(this.target[object]));
|
|
4310
4367
|
if (windowObjects.length > 1) {
|
|
4311
|
-
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(
|
|
4368
|
+
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(", ")}`);
|
|
4312
4369
|
}
|
|
4313
4370
|
if (windowObjects.length === 0) {
|
|
4314
|
-
throw Error(
|
|
4371
|
+
throw Error("No Webpack JSONP entrypoints could be detected");
|
|
4315
4372
|
}
|
|
4316
4373
|
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4317
4374
|
this.entrypoint = windowObjects[0];
|
|
@@ -4328,11 +4385,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
4328
4385
|
for (const key in object) {
|
|
4329
4386
|
const value = object[key];
|
|
4330
4387
|
const lowerCaseQuery = query.toLowerCase();
|
|
4331
|
-
if (typeof value !=
|
|
4388
|
+
if (typeof value != "object") {
|
|
4332
4389
|
const lowerCaseKey = key.toString().toLowerCase();
|
|
4333
4390
|
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4334
4391
|
return true;
|
|
4335
|
-
if (typeof value !=
|
|
4392
|
+
if (typeof value != "object") {
|
|
4336
4393
|
const lowerCaseValue = value.toString().toLowerCase();
|
|
4337
4394
|
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4338
4395
|
return true;
|
|
@@ -4372,31 +4429,31 @@ System.register('Utils', [], (function (exports) {
|
|
|
4372
4429
|
const results = [];
|
|
4373
4430
|
const modules = Object.keys(this.modules);
|
|
4374
4431
|
if (modules.length === 0) {
|
|
4375
|
-
throw new Error(
|
|
4432
|
+
throw new Error("There are no modules to search through!");
|
|
4376
4433
|
}
|
|
4377
4434
|
modules.forEach((key) => {
|
|
4378
4435
|
const module = this.modules[key.toString()];
|
|
4379
4436
|
if (module === undefined)
|
|
4380
4437
|
return;
|
|
4381
4438
|
try {
|
|
4382
|
-
if (typeof query ===
|
|
4439
|
+
if (typeof query === "string") {
|
|
4383
4440
|
query = query.toLowerCase();
|
|
4384
4441
|
switch (typeof module) {
|
|
4385
|
-
case
|
|
4442
|
+
case "string":
|
|
4386
4443
|
if (module.toLowerCase().includes(query))
|
|
4387
4444
|
results.push(module);
|
|
4388
4445
|
break;
|
|
4389
|
-
case
|
|
4446
|
+
case "function":
|
|
4390
4447
|
if (module.toString().toLowerCase().includes(query))
|
|
4391
4448
|
results.push(module);
|
|
4392
4449
|
break;
|
|
4393
|
-
case
|
|
4450
|
+
case "object":
|
|
4394
4451
|
if (this.searchObject(module, query))
|
|
4395
4452
|
results.push(module);
|
|
4396
4453
|
break;
|
|
4397
4454
|
}
|
|
4398
4455
|
}
|
|
4399
|
-
else if (typeof query ===
|
|
4456
|
+
else if (typeof query === "function") {
|
|
4400
4457
|
if (query(module))
|
|
4401
4458
|
results.push(module);
|
|
4402
4459
|
}
|
|
@@ -4449,17 +4506,17 @@ System.register('Utils', [], (function (exports) {
|
|
|
4449
4506
|
const results = [];
|
|
4450
4507
|
const constructors = Object.keys(this.constructors);
|
|
4451
4508
|
if (constructors.length === 0) {
|
|
4452
|
-
throw new Error(
|
|
4509
|
+
throw new Error("There are no constructors to search through!");
|
|
4453
4510
|
}
|
|
4454
4511
|
constructors.forEach((key) => {
|
|
4455
4512
|
const constructor = this.constructors[key];
|
|
4456
4513
|
try {
|
|
4457
|
-
if (typeof query ===
|
|
4514
|
+
if (typeof query === "string") {
|
|
4458
4515
|
query = query.toLowerCase();
|
|
4459
4516
|
if (constructor.toString().toLowerCase().includes(query))
|
|
4460
4517
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4461
4518
|
}
|
|
4462
|
-
else if (typeof query ===
|
|
4519
|
+
else if (typeof query === "function") {
|
|
4463
4520
|
if (query(constructor))
|
|
4464
4521
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4465
4522
|
}
|
|
@@ -5751,7 +5808,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5751
5808
|
}
|
|
5752
5809
|
return strFound ? true : false;
|
|
5753
5810
|
}
|
|
5754
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5811
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5755
5812
|
byteSize = parseInt(byteSize.toString());
|
|
5756
5813
|
if (isNaN(byteSize)) {
|
|
5757
5814
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5759,8 +5816,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
5759
5816
|
let result = 0;
|
|
5760
5817
|
let resultType = "KB";
|
|
5761
5818
|
const sizeData = {};
|
|
5819
|
+
const unitNumber = Number(unit);
|
|
5762
5820
|
sizeData.B = 1;
|
|
5763
|
-
sizeData.KB =
|
|
5821
|
+
sizeData.KB = unitNumber;
|
|
5764
5822
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5765
5823
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5766
5824
|
sizeData.TB = sizeData.GB * sizeData.KB;
|