@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.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,7 +232,7 @@ 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
238
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -240,7 +240,7 @@ var Utils = (function () {
|
|
|
240
240
|
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
241
241
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
242
242
|
|
|
243
|
-
const version = "2.9.
|
|
243
|
+
const version = "2.9.13";
|
|
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
|
}
|
|
@@ -5764,7 +5806,7 @@ var Utils = (function () {
|
|
|
5764
5806
|
}
|
|
5765
5807
|
return strFound ? true : false;
|
|
5766
5808
|
}
|
|
5767
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5809
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5768
5810
|
byteSize = parseInt(byteSize.toString());
|
|
5769
5811
|
if (isNaN(byteSize)) {
|
|
5770
5812
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5772,8 +5814,9 @@ var Utils = (function () {
|
|
|
5772
5814
|
let result = 0;
|
|
5773
5815
|
let resultType = "KB";
|
|
5774
5816
|
const sizeData = {};
|
|
5817
|
+
const unitNumber = Number(unit);
|
|
5775
5818
|
sizeData.B = 1;
|
|
5776
|
-
sizeData.KB =
|
|
5819
|
+
sizeData.KB = unitNumber;
|
|
5777
5820
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5778
5821
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5779
5822
|
sizeData.TB = sizeData.GB * sizeData.KB;
|