@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.cjs.js
CHANGED
|
@@ -57,47 +57,7 @@ const LAST_NUMBER_WEAK_MAP = new WeakMap();
|
|
|
57
57
|
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
58
58
|
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
return typeof sender.start === 'function';
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const PORT_MAP = new WeakMap();
|
|
65
|
-
|
|
66
|
-
const extendBrokerImplementation = (partialBrokerImplementation) => ({
|
|
67
|
-
...partialBrokerImplementation,
|
|
68
|
-
connect: ({ call }) => {
|
|
69
|
-
return async () => {
|
|
70
|
-
const { port1, port2 } = new MessageChannel();
|
|
71
|
-
const portId = await call('connect', { port: port1 }, [port1]);
|
|
72
|
-
PORT_MAP.set(port2, portId);
|
|
73
|
-
return port2;
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
disconnect: ({ call }) => {
|
|
77
|
-
return async (port) => {
|
|
78
|
-
const portId = PORT_MAP.get(port);
|
|
79
|
-
if (portId === undefined) {
|
|
80
|
-
throw new Error('The given port is not connected.');
|
|
81
|
-
}
|
|
82
|
-
await call('disconnect', { portId });
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
isSupported: ({ call }) => {
|
|
86
|
-
return () => call('isSupported');
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const ONGOING_REQUESTS = new WeakMap();
|
|
91
|
-
const createOrGetOngoingRequests = (sender) => {
|
|
92
|
-
if (ONGOING_REQUESTS.has(sender)) {
|
|
93
|
-
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
94
|
-
return ONGOING_REQUESTS.get(sender);
|
|
95
|
-
}
|
|
96
|
-
const ongoingRequests = new Map();
|
|
97
|
-
ONGOING_REQUESTS.set(sender, ongoingRequests);
|
|
98
|
-
return ongoingRequests;
|
|
99
|
-
};
|
|
100
|
-
const createBroker = (brokerImplementation) => {
|
|
60
|
+
const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
|
|
101
61
|
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
102
62
|
return (sender) => {
|
|
103
63
|
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
@@ -140,6 +100,46 @@ const createBroker = (brokerImplementation) => {
|
|
|
140
100
|
};
|
|
141
101
|
};
|
|
142
102
|
|
|
103
|
+
const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
|
|
104
|
+
if (ongoingRequestsMap.has(sender)) {
|
|
105
|
+
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
106
|
+
return ongoingRequestsMap.get(sender);
|
|
107
|
+
}
|
|
108
|
+
const ongoingRequests = new Map();
|
|
109
|
+
ongoingRequestsMap.set(sender, ongoingRequests);
|
|
110
|
+
return ongoingRequests;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
|
|
114
|
+
...partialBrokerImplementation,
|
|
115
|
+
connect: ({ call }) => {
|
|
116
|
+
return async () => {
|
|
117
|
+
const { port1, port2 } = new MessageChannel();
|
|
118
|
+
const portId = await call('connect', { port: port1 }, [port1]);
|
|
119
|
+
portMap.set(port2, portId);
|
|
120
|
+
return port2;
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
disconnect: ({ call }) => {
|
|
124
|
+
return async (port) => {
|
|
125
|
+
const portId = portMap.get(port);
|
|
126
|
+
if (portId === undefined) {
|
|
127
|
+
throw new Error('The given port is not connected.');
|
|
128
|
+
}
|
|
129
|
+
await call('disconnect', { portId });
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
isSupported: ({ call }) => {
|
|
133
|
+
return () => call('isSupported');
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const isMessagePort = (sender) => {
|
|
138
|
+
return typeof sender.start === 'function';
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
|
|
142
|
+
|
|
143
143
|
const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
|
|
144
144
|
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
145
145
|
scheduledIntervalsState.set(timerId, null);
|
|
@@ -231,7 +231,7 @@ const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
|
231
231
|
};
|
|
232
232
|
|
|
233
233
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
234
|
-
const worker = `(()=>{var e={455
|
|
234
|
+
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
|
|
235
235
|
|
|
236
236
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
237
237
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -239,7 +239,7 @@ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
|
239
239
|
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
240
240
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
241
241
|
|
|
242
|
-
const version = "2.9.
|
|
242
|
+
const version = "2.9.13";
|
|
243
243
|
|
|
244
244
|
/* eslint-disable */
|
|
245
245
|
// ==UserScript==
|
|
@@ -279,7 +279,9 @@ const ajaxHooker = function () {
|
|
|
279
279
|
const emptyFn = () => { };
|
|
280
280
|
const errorFn = (e) => console.error(e);
|
|
281
281
|
function isThenable(obj) {
|
|
282
|
-
return
|
|
282
|
+
return (obj &&
|
|
283
|
+
["object", "function"].includes(typeof obj) &&
|
|
284
|
+
typeof obj.then === "function");
|
|
283
285
|
}
|
|
284
286
|
function catchError(fn, ...args) {
|
|
285
287
|
try {
|
|
@@ -320,7 +322,8 @@ const ajaxHooker = function () {
|
|
|
320
322
|
if (!value)
|
|
321
323
|
continue;
|
|
322
324
|
const lheader = header.toLowerCase();
|
|
323
|
-
headers[lheader] =
|
|
325
|
+
headers[lheader] =
|
|
326
|
+
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
324
327
|
}
|
|
325
328
|
break;
|
|
326
329
|
case "[object Headers]":
|
|
@@ -359,9 +362,11 @@ const ajaxHooker = function () {
|
|
|
359
362
|
!filters.find((obj) => {
|
|
360
363
|
switch (true) {
|
|
361
364
|
case obj.type && obj.type !== type:
|
|
362
|
-
case getType(obj.url) === "[object String]" &&
|
|
365
|
+
case getType(obj.url) === "[object String]" &&
|
|
366
|
+
!url.includes(obj.url):
|
|
363
367
|
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
364
|
-
case obj.method &&
|
|
368
|
+
case obj.method &&
|
|
369
|
+
obj.method.toUpperCase() !== method.toUpperCase():
|
|
365
370
|
case "async" in obj && obj.async !== async:
|
|
366
371
|
return false;
|
|
367
372
|
}
|
|
@@ -404,7 +409,8 @@ const ajaxHooker = function () {
|
|
|
404
409
|
if (getType(this.request.response) === "[object Function]") {
|
|
405
410
|
catchError(this.request.response, response);
|
|
406
411
|
responseKeys.forEach((key) => {
|
|
407
|
-
if ("get" in getDescriptor(response, key) ||
|
|
412
|
+
if ("get" in getDescriptor(response, key) ||
|
|
413
|
+
isThenable(response[key])) {
|
|
408
414
|
delete response[key];
|
|
409
415
|
}
|
|
410
416
|
});
|
|
@@ -425,7 +431,10 @@ const ajaxHooker = function () {
|
|
|
425
431
|
const proxyHandler = {
|
|
426
432
|
get(target, prop) {
|
|
427
433
|
const descriptor = getDescriptor(target, prop);
|
|
428
|
-
if (descriptor &&
|
|
434
|
+
if (descriptor &&
|
|
435
|
+
!descriptor.configurable &&
|
|
436
|
+
!descriptor.writable &&
|
|
437
|
+
!descriptor.get)
|
|
429
438
|
return target[prop];
|
|
430
439
|
const ah = target.__ajaxHooker;
|
|
431
440
|
if (ah && ah.proxyProps) {
|
|
@@ -444,7 +453,10 @@ const ajaxHooker = function () {
|
|
|
444
453
|
},
|
|
445
454
|
set(target, prop, value) {
|
|
446
455
|
const descriptor = getDescriptor(target, prop);
|
|
447
|
-
if (descriptor &&
|
|
456
|
+
if (descriptor &&
|
|
457
|
+
!descriptor.configurable &&
|
|
458
|
+
!descriptor.writable &&
|
|
459
|
+
!descriptor.set)
|
|
448
460
|
return true;
|
|
449
461
|
const ah = target.__ajaxHooker;
|
|
450
462
|
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
@@ -468,7 +480,9 @@ const ajaxHooker = function () {
|
|
|
468
480
|
proxyEvents: {},
|
|
469
481
|
});
|
|
470
482
|
xhr.addEventListener("readystatechange", (e) => {
|
|
471
|
-
if (ah.proxyXhr.readyState === 4 &&
|
|
483
|
+
if (ah.proxyXhr.readyState === 4 &&
|
|
484
|
+
ah.request &&
|
|
485
|
+
typeof ah.request.response === "function") {
|
|
472
486
|
const response = {
|
|
473
487
|
finalUrl: ah.proxyXhr.responseURL,
|
|
474
488
|
status: ah.proxyXhr.status,
|
|
@@ -487,7 +501,9 @@ const ajaxHooker = function () {
|
|
|
487
501
|
response[key] = val;
|
|
488
502
|
});
|
|
489
503
|
}
|
|
490
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
504
|
+
ah.resThenable = new AHRequest(ah.request)
|
|
505
|
+
.waitForResponseKeys(response)
|
|
506
|
+
.then(() => {
|
|
491
507
|
for (const key of xhrResponses) {
|
|
492
508
|
ah.proxyProps[key] = {
|
|
493
509
|
get: () => {
|
|
@@ -510,7 +526,13 @@ const ajaxHooker = function () {
|
|
|
510
526
|
set: (val) => ah.addEvent(onEvt, val),
|
|
511
527
|
};
|
|
512
528
|
}
|
|
513
|
-
for (const method of [
|
|
529
|
+
for (const method of [
|
|
530
|
+
"setRequestHeader",
|
|
531
|
+
"addEventListener",
|
|
532
|
+
"removeEventListener",
|
|
533
|
+
"open",
|
|
534
|
+
"send",
|
|
535
|
+
]) {
|
|
514
536
|
ah.proxyProps[method] = { value: ah[method] };
|
|
515
537
|
}
|
|
516
538
|
}
|
|
@@ -557,7 +579,8 @@ const ajaxHooker = function () {
|
|
|
557
579
|
if (!this.request)
|
|
558
580
|
return;
|
|
559
581
|
const headers = this.request.headers;
|
|
560
|
-
headers[header] =
|
|
582
|
+
headers[header] =
|
|
583
|
+
header in headers ? `${headers[header]}, ${value}` : value;
|
|
561
584
|
}
|
|
562
585
|
addEventListener(...args) {
|
|
563
586
|
if (xhrAsyncEvents.includes(args[0])) {
|
|
@@ -588,7 +611,13 @@ const ajaxHooker = function () {
|
|
|
588
611
|
};
|
|
589
612
|
this.openArgs = args;
|
|
590
613
|
this.resThenable = new SyncThenable();
|
|
591
|
-
[
|
|
614
|
+
[
|
|
615
|
+
"responseURL",
|
|
616
|
+
"readyState",
|
|
617
|
+
"status",
|
|
618
|
+
"statusText",
|
|
619
|
+
...xhrResponses,
|
|
620
|
+
].forEach((key) => {
|
|
592
621
|
delete this.proxyProps[key];
|
|
593
622
|
});
|
|
594
623
|
return this.originalXhr.open(method, url, async, ...args);
|
|
@@ -750,13 +779,17 @@ const ajaxHooker = function () {
|
|
|
750
779
|
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
751
780
|
class AHFunction extends Function {
|
|
752
781
|
call(thisArg, ...args) {
|
|
753
|
-
if (thisArg &&
|
|
782
|
+
if (thisArg &&
|
|
783
|
+
thisArg.__ajaxHooker &&
|
|
784
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
754
785
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
755
786
|
}
|
|
756
787
|
return Reflect.apply(this, thisArg, args);
|
|
757
788
|
}
|
|
758
789
|
apply(thisArg, args) {
|
|
759
|
-
if (thisArg &&
|
|
790
|
+
if (thisArg &&
|
|
791
|
+
thisArg.__ajaxHooker &&
|
|
792
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
760
793
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
761
794
|
}
|
|
762
795
|
return Reflect.apply(this, thisArg, args || []);
|
|
@@ -1655,6 +1688,12 @@ class UtilsDictionary {
|
|
|
1655
1688
|
this.set(key, value);
|
|
1656
1689
|
}
|
|
1657
1690
|
}
|
|
1691
|
+
[Symbol.dispose]() {
|
|
1692
|
+
this.clear();
|
|
1693
|
+
}
|
|
1694
|
+
async [Symbol.asyncDispose]() {
|
|
1695
|
+
this.clear();
|
|
1696
|
+
}
|
|
1658
1697
|
/**
|
|
1659
1698
|
* 获取字典的长度,同this.size
|
|
1660
1699
|
*/
|
|
@@ -2166,11 +2205,11 @@ class Hooks {
|
|
|
2166
2205
|
return "";
|
|
2167
2206
|
}
|
|
2168
2207
|
try {
|
|
2169
|
-
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2170
|
-
let args = Array.prototype.slice.call(arguments, 0);
|
|
2171
|
-
let obj = this;
|
|
2172
|
-
hookFunc.apply(obj, args);
|
|
2173
|
-
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2208
|
+
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2209
|
+
let args = Array.prototype.slice.call(arguments, 0);
|
|
2210
|
+
let obj = this;
|
|
2211
|
+
hookFunc.apply(obj, args);
|
|
2212
|
+
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2174
2213
|
};`)(_context, _funcName, hookFunc);
|
|
2175
2214
|
_context[_funcName].prototype.isHooked = true;
|
|
2176
2215
|
return true;
|
|
@@ -4190,11 +4229,11 @@ class ModuleRaid {
|
|
|
4190
4229
|
this.constructors = [];
|
|
4191
4230
|
let options = {
|
|
4192
4231
|
target: window,
|
|
4193
|
-
entrypoint:
|
|
4232
|
+
entrypoint: "webpackJsonp",
|
|
4194
4233
|
debug: false,
|
|
4195
4234
|
strict: false,
|
|
4196
4235
|
};
|
|
4197
|
-
if (typeof opts ===
|
|
4236
|
+
if (typeof opts === "object") {
|
|
4198
4237
|
options = Object.assign(Object.assign({}, options), opts);
|
|
4199
4238
|
}
|
|
4200
4239
|
this.target = options.target;
|
|
@@ -4233,7 +4272,7 @@ class ModuleRaid {
|
|
|
4233
4272
|
* @internal
|
|
4234
4273
|
*/
|
|
4235
4274
|
fillModules() {
|
|
4236
|
-
if (typeof this.target[this.entrypoint] ===
|
|
4275
|
+
if (typeof this.target[this.entrypoint] === "function") {
|
|
4237
4276
|
this.functionArguments.forEach((argument, index) => {
|
|
4238
4277
|
try {
|
|
4239
4278
|
if (this.modules && Object.keys(this.modules).length > 0)
|
|
@@ -4260,8 +4299,9 @@ class ModuleRaid {
|
|
|
4260
4299
|
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4261
4300
|
let moduleEnd = false;
|
|
4262
4301
|
let moduleIterator = 0;
|
|
4263
|
-
if (typeof this.target[this.entrypoint] !=
|
|
4264
|
-
|
|
4302
|
+
if (typeof this.target[this.entrypoint] != "function" ||
|
|
4303
|
+
!this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4304
|
+
throw Error("Unknown Webpack structure");
|
|
4265
4305
|
}
|
|
4266
4306
|
while (!moduleEnd) {
|
|
4267
4307
|
try {
|
|
@@ -4294,7 +4334,7 @@ class ModuleRaid {
|
|
|
4294
4334
|
const originalPush = this.target[this.entrypoint].push;
|
|
4295
4335
|
this.target[this.entrypoint].push = (...args) => {
|
|
4296
4336
|
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4297
|
-
document.dispatchEvent(new CustomEvent(
|
|
4337
|
+
document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
|
|
4298
4338
|
return result;
|
|
4299
4339
|
};
|
|
4300
4340
|
}
|
|
@@ -4317,13 +4357,15 @@ class ModuleRaid {
|
|
|
4317
4357
|
}
|
|
4318
4358
|
let windowObjects = Object.keys(this.target);
|
|
4319
4359
|
windowObjects = windowObjects
|
|
4320
|
-
.filter((object) => object.toLowerCase().includes(
|
|
4321
|
-
.
|
|
4360
|
+
.filter((object) => object.toLowerCase().includes("chunk") ||
|
|
4361
|
+
object.toLowerCase().includes("webpack"))
|
|
4362
|
+
.filter((object) => typeof this.target[object] === "function" ||
|
|
4363
|
+
Array.isArray(this.target[object]));
|
|
4322
4364
|
if (windowObjects.length > 1) {
|
|
4323
|
-
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(
|
|
4365
|
+
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(", ")}`);
|
|
4324
4366
|
}
|
|
4325
4367
|
if (windowObjects.length === 0) {
|
|
4326
|
-
throw Error(
|
|
4368
|
+
throw Error("No Webpack JSONP entrypoints could be detected");
|
|
4327
4369
|
}
|
|
4328
4370
|
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4329
4371
|
this.entrypoint = windowObjects[0];
|
|
@@ -4340,11 +4382,11 @@ class ModuleRaid {
|
|
|
4340
4382
|
for (const key in object) {
|
|
4341
4383
|
const value = object[key];
|
|
4342
4384
|
const lowerCaseQuery = query.toLowerCase();
|
|
4343
|
-
if (typeof value !=
|
|
4385
|
+
if (typeof value != "object") {
|
|
4344
4386
|
const lowerCaseKey = key.toString().toLowerCase();
|
|
4345
4387
|
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4346
4388
|
return true;
|
|
4347
|
-
if (typeof value !=
|
|
4389
|
+
if (typeof value != "object") {
|
|
4348
4390
|
const lowerCaseValue = value.toString().toLowerCase();
|
|
4349
4391
|
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4350
4392
|
return true;
|
|
@@ -4384,31 +4426,31 @@ class ModuleRaid {
|
|
|
4384
4426
|
const results = [];
|
|
4385
4427
|
const modules = Object.keys(this.modules);
|
|
4386
4428
|
if (modules.length === 0) {
|
|
4387
|
-
throw new Error(
|
|
4429
|
+
throw new Error("There are no modules to search through!");
|
|
4388
4430
|
}
|
|
4389
4431
|
modules.forEach((key) => {
|
|
4390
4432
|
const module = this.modules[key.toString()];
|
|
4391
4433
|
if (module === undefined)
|
|
4392
4434
|
return;
|
|
4393
4435
|
try {
|
|
4394
|
-
if (typeof query ===
|
|
4436
|
+
if (typeof query === "string") {
|
|
4395
4437
|
query = query.toLowerCase();
|
|
4396
4438
|
switch (typeof module) {
|
|
4397
|
-
case
|
|
4439
|
+
case "string":
|
|
4398
4440
|
if (module.toLowerCase().includes(query))
|
|
4399
4441
|
results.push(module);
|
|
4400
4442
|
break;
|
|
4401
|
-
case
|
|
4443
|
+
case "function":
|
|
4402
4444
|
if (module.toString().toLowerCase().includes(query))
|
|
4403
4445
|
results.push(module);
|
|
4404
4446
|
break;
|
|
4405
|
-
case
|
|
4447
|
+
case "object":
|
|
4406
4448
|
if (this.searchObject(module, query))
|
|
4407
4449
|
results.push(module);
|
|
4408
4450
|
break;
|
|
4409
4451
|
}
|
|
4410
4452
|
}
|
|
4411
|
-
else if (typeof query ===
|
|
4453
|
+
else if (typeof query === "function") {
|
|
4412
4454
|
if (query(module))
|
|
4413
4455
|
results.push(module);
|
|
4414
4456
|
}
|
|
@@ -4461,17 +4503,17 @@ class ModuleRaid {
|
|
|
4461
4503
|
const results = [];
|
|
4462
4504
|
const constructors = Object.keys(this.constructors);
|
|
4463
4505
|
if (constructors.length === 0) {
|
|
4464
|
-
throw new Error(
|
|
4506
|
+
throw new Error("There are no constructors to search through!");
|
|
4465
4507
|
}
|
|
4466
4508
|
constructors.forEach((key) => {
|
|
4467
4509
|
const constructor = this.constructors[key];
|
|
4468
4510
|
try {
|
|
4469
|
-
if (typeof query ===
|
|
4511
|
+
if (typeof query === "string") {
|
|
4470
4512
|
query = query.toLowerCase();
|
|
4471
4513
|
if (constructor.toString().toLowerCase().includes(query))
|
|
4472
4514
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4473
4515
|
}
|
|
4474
|
-
else if (typeof query ===
|
|
4516
|
+
else if (typeof query === "function") {
|
|
4475
4517
|
if (query(constructor))
|
|
4476
4518
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4477
4519
|
}
|
|
@@ -5763,7 +5805,7 @@ class Utils {
|
|
|
5763
5805
|
}
|
|
5764
5806
|
return strFound ? true : false;
|
|
5765
5807
|
}
|
|
5766
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5808
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5767
5809
|
byteSize = parseInt(byteSize.toString());
|
|
5768
5810
|
if (isNaN(byteSize)) {
|
|
5769
5811
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5771,8 +5813,9 @@ class Utils {
|
|
|
5771
5813
|
let result = 0;
|
|
5772
5814
|
let resultType = "KB";
|
|
5773
5815
|
const sizeData = {};
|
|
5816
|
+
const unitNumber = Number(unit);
|
|
5774
5817
|
sizeData.B = 1;
|
|
5775
|
-
sizeData.KB =
|
|
5818
|
+
sizeData.KB = unitNumber;
|
|
5776
5819
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5777
5820
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5778
5821
|
sizeData.TB = sizeData.GB * sizeData.KB;
|