@whitesev/utils 2.9.12 → 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 +128 -85
- 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 +128 -85
- 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 +128 -85
- 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 +128 -85
- 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 +128 -85
- 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 +128 -85
- 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 -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 +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 || []);
|
|
@@ -1658,6 +1691,12 @@ System.register('Utils', [], (function (exports) {
|
|
|
1658
1691
|
this.set(key, value);
|
|
1659
1692
|
}
|
|
1660
1693
|
}
|
|
1694
|
+
[Symbol.dispose]() {
|
|
1695
|
+
this.clear();
|
|
1696
|
+
}
|
|
1697
|
+
async [Symbol.asyncDispose]() {
|
|
1698
|
+
this.clear();
|
|
1699
|
+
}
|
|
1661
1700
|
/**
|
|
1662
1701
|
* 获取字典的长度,同this.size
|
|
1663
1702
|
*/
|
|
@@ -2169,11 +2208,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
2169
2208
|
return "";
|
|
2170
2209
|
}
|
|
2171
2210
|
try {
|
|
2172
|
-
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2173
|
-
let args = Array.prototype.slice.call(arguments, 0);
|
|
2174
|
-
let obj = this;
|
|
2175
|
-
hookFunc.apply(obj, args);
|
|
2176
|
-
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);
|
|
2177
2216
|
};`)(_context, _funcName, hookFunc);
|
|
2178
2217
|
_context[_funcName].prototype.isHooked = true;
|
|
2179
2218
|
return true;
|
|
@@ -4193,11 +4232,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
4193
4232
|
this.constructors = [];
|
|
4194
4233
|
let options = {
|
|
4195
4234
|
target: window,
|
|
4196
|
-
entrypoint:
|
|
4235
|
+
entrypoint: "webpackJsonp",
|
|
4197
4236
|
debug: false,
|
|
4198
4237
|
strict: false,
|
|
4199
4238
|
};
|
|
4200
|
-
if (typeof opts ===
|
|
4239
|
+
if (typeof opts === "object") {
|
|
4201
4240
|
options = Object.assign(Object.assign({}, options), opts);
|
|
4202
4241
|
}
|
|
4203
4242
|
this.target = options.target;
|
|
@@ -4236,7 +4275,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4236
4275
|
* @internal
|
|
4237
4276
|
*/
|
|
4238
4277
|
fillModules() {
|
|
4239
|
-
if (typeof this.target[this.entrypoint] ===
|
|
4278
|
+
if (typeof this.target[this.entrypoint] === "function") {
|
|
4240
4279
|
this.functionArguments.forEach((argument, index) => {
|
|
4241
4280
|
try {
|
|
4242
4281
|
if (this.modules && Object.keys(this.modules).length > 0)
|
|
@@ -4263,8 +4302,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
4263
4302
|
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4264
4303
|
let moduleEnd = false;
|
|
4265
4304
|
let moduleIterator = 0;
|
|
4266
|
-
if (typeof this.target[this.entrypoint] !=
|
|
4267
|
-
|
|
4305
|
+
if (typeof this.target[this.entrypoint] != "function" ||
|
|
4306
|
+
!this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4307
|
+
throw Error("Unknown Webpack structure");
|
|
4268
4308
|
}
|
|
4269
4309
|
while (!moduleEnd) {
|
|
4270
4310
|
try {
|
|
@@ -4297,7 +4337,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4297
4337
|
const originalPush = this.target[this.entrypoint].push;
|
|
4298
4338
|
this.target[this.entrypoint].push = (...args) => {
|
|
4299
4339
|
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4300
|
-
document.dispatchEvent(new CustomEvent(
|
|
4340
|
+
document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
|
|
4301
4341
|
return result;
|
|
4302
4342
|
};
|
|
4303
4343
|
}
|
|
@@ -4320,13 +4360,15 @@ System.register('Utils', [], (function (exports) {
|
|
|
4320
4360
|
}
|
|
4321
4361
|
let windowObjects = Object.keys(this.target);
|
|
4322
4362
|
windowObjects = windowObjects
|
|
4323
|
-
.filter((object) => object.toLowerCase().includes(
|
|
4324
|
-
.
|
|
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]));
|
|
4325
4367
|
if (windowObjects.length > 1) {
|
|
4326
|
-
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(", ")}`);
|
|
4327
4369
|
}
|
|
4328
4370
|
if (windowObjects.length === 0) {
|
|
4329
|
-
throw Error(
|
|
4371
|
+
throw Error("No Webpack JSONP entrypoints could be detected");
|
|
4330
4372
|
}
|
|
4331
4373
|
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4332
4374
|
this.entrypoint = windowObjects[0];
|
|
@@ -4343,11 +4385,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
4343
4385
|
for (const key in object) {
|
|
4344
4386
|
const value = object[key];
|
|
4345
4387
|
const lowerCaseQuery = query.toLowerCase();
|
|
4346
|
-
if (typeof value !=
|
|
4388
|
+
if (typeof value != "object") {
|
|
4347
4389
|
const lowerCaseKey = key.toString().toLowerCase();
|
|
4348
4390
|
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4349
4391
|
return true;
|
|
4350
|
-
if (typeof value !=
|
|
4392
|
+
if (typeof value != "object") {
|
|
4351
4393
|
const lowerCaseValue = value.toString().toLowerCase();
|
|
4352
4394
|
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4353
4395
|
return true;
|
|
@@ -4387,31 +4429,31 @@ System.register('Utils', [], (function (exports) {
|
|
|
4387
4429
|
const results = [];
|
|
4388
4430
|
const modules = Object.keys(this.modules);
|
|
4389
4431
|
if (modules.length === 0) {
|
|
4390
|
-
throw new Error(
|
|
4432
|
+
throw new Error("There are no modules to search through!");
|
|
4391
4433
|
}
|
|
4392
4434
|
modules.forEach((key) => {
|
|
4393
4435
|
const module = this.modules[key.toString()];
|
|
4394
4436
|
if (module === undefined)
|
|
4395
4437
|
return;
|
|
4396
4438
|
try {
|
|
4397
|
-
if (typeof query ===
|
|
4439
|
+
if (typeof query === "string") {
|
|
4398
4440
|
query = query.toLowerCase();
|
|
4399
4441
|
switch (typeof module) {
|
|
4400
|
-
case
|
|
4442
|
+
case "string":
|
|
4401
4443
|
if (module.toLowerCase().includes(query))
|
|
4402
4444
|
results.push(module);
|
|
4403
4445
|
break;
|
|
4404
|
-
case
|
|
4446
|
+
case "function":
|
|
4405
4447
|
if (module.toString().toLowerCase().includes(query))
|
|
4406
4448
|
results.push(module);
|
|
4407
4449
|
break;
|
|
4408
|
-
case
|
|
4450
|
+
case "object":
|
|
4409
4451
|
if (this.searchObject(module, query))
|
|
4410
4452
|
results.push(module);
|
|
4411
4453
|
break;
|
|
4412
4454
|
}
|
|
4413
4455
|
}
|
|
4414
|
-
else if (typeof query ===
|
|
4456
|
+
else if (typeof query === "function") {
|
|
4415
4457
|
if (query(module))
|
|
4416
4458
|
results.push(module);
|
|
4417
4459
|
}
|
|
@@ -4464,17 +4506,17 @@ System.register('Utils', [], (function (exports) {
|
|
|
4464
4506
|
const results = [];
|
|
4465
4507
|
const constructors = Object.keys(this.constructors);
|
|
4466
4508
|
if (constructors.length === 0) {
|
|
4467
|
-
throw new Error(
|
|
4509
|
+
throw new Error("There are no constructors to search through!");
|
|
4468
4510
|
}
|
|
4469
4511
|
constructors.forEach((key) => {
|
|
4470
4512
|
const constructor = this.constructors[key];
|
|
4471
4513
|
try {
|
|
4472
|
-
if (typeof query ===
|
|
4514
|
+
if (typeof query === "string") {
|
|
4473
4515
|
query = query.toLowerCase();
|
|
4474
4516
|
if (constructor.toString().toLowerCase().includes(query))
|
|
4475
4517
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4476
4518
|
}
|
|
4477
|
-
else if (typeof query ===
|
|
4519
|
+
else if (typeof query === "function") {
|
|
4478
4520
|
if (query(constructor))
|
|
4479
4521
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4480
4522
|
}
|
|
@@ -5766,7 +5808,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5766
5808
|
}
|
|
5767
5809
|
return strFound ? true : false;
|
|
5768
5810
|
}
|
|
5769
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5811
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5770
5812
|
byteSize = parseInt(byteSize.toString());
|
|
5771
5813
|
if (isNaN(byteSize)) {
|
|
5772
5814
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5774,8 +5816,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
5774
5816
|
let result = 0;
|
|
5775
5817
|
let resultType = "KB";
|
|
5776
5818
|
const sizeData = {};
|
|
5819
|
+
const unitNumber = Number(unit);
|
|
5777
5820
|
sizeData.B = 1;
|
|
5778
|
-
sizeData.KB =
|
|
5821
|
+
sizeData.KB = unitNumber;
|
|
5779
5822
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5780
5823
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5781
5824
|
sizeData.TB = sizeData.GB * sizeData.KB;
|