@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.esm.js
CHANGED
|
@@ -55,47 +55,7 @@ const LAST_NUMBER_WEAK_MAP = new WeakMap();
|
|
|
55
55
|
const cache = createCache(LAST_NUMBER_WEAK_MAP);
|
|
56
56
|
const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
|
|
57
57
|
|
|
58
|
-
const
|
|
59
|
-
return typeof sender.start === 'function';
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const PORT_MAP = new WeakMap();
|
|
63
|
-
|
|
64
|
-
const extendBrokerImplementation = (partialBrokerImplementation) => ({
|
|
65
|
-
...partialBrokerImplementation,
|
|
66
|
-
connect: ({ call }) => {
|
|
67
|
-
return async () => {
|
|
68
|
-
const { port1, port2 } = new MessageChannel();
|
|
69
|
-
const portId = await call('connect', { port: port1 }, [port1]);
|
|
70
|
-
PORT_MAP.set(port2, portId);
|
|
71
|
-
return port2;
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
disconnect: ({ call }) => {
|
|
75
|
-
return async (port) => {
|
|
76
|
-
const portId = PORT_MAP.get(port);
|
|
77
|
-
if (portId === undefined) {
|
|
78
|
-
throw new Error('The given port is not connected.');
|
|
79
|
-
}
|
|
80
|
-
await call('disconnect', { portId });
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
isSupported: ({ call }) => {
|
|
84
|
-
return () => call('isSupported');
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const ONGOING_REQUESTS = new WeakMap();
|
|
89
|
-
const createOrGetOngoingRequests = (sender) => {
|
|
90
|
-
if (ONGOING_REQUESTS.has(sender)) {
|
|
91
|
-
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
92
|
-
return ONGOING_REQUESTS.get(sender);
|
|
93
|
-
}
|
|
94
|
-
const ongoingRequests = new Map();
|
|
95
|
-
ONGOING_REQUESTS.set(sender, ongoingRequests);
|
|
96
|
-
return ongoingRequests;
|
|
97
|
-
};
|
|
98
|
-
const createBroker = (brokerImplementation) => {
|
|
58
|
+
const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
|
|
99
59
|
const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
|
|
100
60
|
return (sender) => {
|
|
101
61
|
const ongoingRequests = createOrGetOngoingRequests(sender);
|
|
@@ -138,6 +98,46 @@ const createBroker = (brokerImplementation) => {
|
|
|
138
98
|
};
|
|
139
99
|
};
|
|
140
100
|
|
|
101
|
+
const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
|
|
102
|
+
if (ongoingRequestsMap.has(sender)) {
|
|
103
|
+
// @todo TypeScript needs to be convinced that has() works as expected.
|
|
104
|
+
return ongoingRequestsMap.get(sender);
|
|
105
|
+
}
|
|
106
|
+
const ongoingRequests = new Map();
|
|
107
|
+
ongoingRequestsMap.set(sender, ongoingRequests);
|
|
108
|
+
return ongoingRequests;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
|
|
112
|
+
...partialBrokerImplementation,
|
|
113
|
+
connect: ({ call }) => {
|
|
114
|
+
return async () => {
|
|
115
|
+
const { port1, port2 } = new MessageChannel();
|
|
116
|
+
const portId = await call('connect', { port: port1 }, [port1]);
|
|
117
|
+
portMap.set(port2, portId);
|
|
118
|
+
return port2;
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
disconnect: ({ call }) => {
|
|
122
|
+
return async (port) => {
|
|
123
|
+
const portId = portMap.get(port);
|
|
124
|
+
if (portId === undefined) {
|
|
125
|
+
throw new Error('The given port is not connected.');
|
|
126
|
+
}
|
|
127
|
+
await call('disconnect', { portId });
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
isSupported: ({ call }) => {
|
|
131
|
+
return () => call('isSupported');
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const isMessagePort = (sender) => {
|
|
136
|
+
return typeof sender.start === 'function';
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
|
|
140
|
+
|
|
141
141
|
const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
|
|
142
142
|
if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
|
|
143
143
|
scheduledIntervalsState.set(timerId, null);
|
|
@@ -229,7 +229,7 @@ const createLoadOrReturnBroker = (loadBroker, worker) => {
|
|
|
229
229
|
};
|
|
230
230
|
|
|
231
231
|
// This is the minified and stringified code of the worker-timers-worker package.
|
|
232
|
-
const worker = `(()=>{var e={455
|
|
232
|
+
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
|
|
233
233
|
|
|
234
234
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
235
235
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
@@ -237,7 +237,7 @@ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
|
237
237
|
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
238
238
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
239
239
|
|
|
240
|
-
const version = "2.9.
|
|
240
|
+
const version = "2.9.13";
|
|
241
241
|
|
|
242
242
|
/* eslint-disable */
|
|
243
243
|
// ==UserScript==
|
|
@@ -277,7 +277,9 @@ const ajaxHooker = function () {
|
|
|
277
277
|
const emptyFn = () => { };
|
|
278
278
|
const errorFn = (e) => console.error(e);
|
|
279
279
|
function isThenable(obj) {
|
|
280
|
-
return
|
|
280
|
+
return (obj &&
|
|
281
|
+
["object", "function"].includes(typeof obj) &&
|
|
282
|
+
typeof obj.then === "function");
|
|
281
283
|
}
|
|
282
284
|
function catchError(fn, ...args) {
|
|
283
285
|
try {
|
|
@@ -318,7 +320,8 @@ const ajaxHooker = function () {
|
|
|
318
320
|
if (!value)
|
|
319
321
|
continue;
|
|
320
322
|
const lheader = header.toLowerCase();
|
|
321
|
-
headers[lheader] =
|
|
323
|
+
headers[lheader] =
|
|
324
|
+
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
322
325
|
}
|
|
323
326
|
break;
|
|
324
327
|
case "[object Headers]":
|
|
@@ -357,9 +360,11 @@ const ajaxHooker = function () {
|
|
|
357
360
|
!filters.find((obj) => {
|
|
358
361
|
switch (true) {
|
|
359
362
|
case obj.type && obj.type !== type:
|
|
360
|
-
case getType(obj.url) === "[object String]" &&
|
|
363
|
+
case getType(obj.url) === "[object String]" &&
|
|
364
|
+
!url.includes(obj.url):
|
|
361
365
|
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
362
|
-
case obj.method &&
|
|
366
|
+
case obj.method &&
|
|
367
|
+
obj.method.toUpperCase() !== method.toUpperCase():
|
|
363
368
|
case "async" in obj && obj.async !== async:
|
|
364
369
|
return false;
|
|
365
370
|
}
|
|
@@ -402,7 +407,8 @@ const ajaxHooker = function () {
|
|
|
402
407
|
if (getType(this.request.response) === "[object Function]") {
|
|
403
408
|
catchError(this.request.response, response);
|
|
404
409
|
responseKeys.forEach((key) => {
|
|
405
|
-
if ("get" in getDescriptor(response, key) ||
|
|
410
|
+
if ("get" in getDescriptor(response, key) ||
|
|
411
|
+
isThenable(response[key])) {
|
|
406
412
|
delete response[key];
|
|
407
413
|
}
|
|
408
414
|
});
|
|
@@ -423,7 +429,10 @@ const ajaxHooker = function () {
|
|
|
423
429
|
const proxyHandler = {
|
|
424
430
|
get(target, prop) {
|
|
425
431
|
const descriptor = getDescriptor(target, prop);
|
|
426
|
-
if (descriptor &&
|
|
432
|
+
if (descriptor &&
|
|
433
|
+
!descriptor.configurable &&
|
|
434
|
+
!descriptor.writable &&
|
|
435
|
+
!descriptor.get)
|
|
427
436
|
return target[prop];
|
|
428
437
|
const ah = target.__ajaxHooker;
|
|
429
438
|
if (ah && ah.proxyProps) {
|
|
@@ -442,7 +451,10 @@ const ajaxHooker = function () {
|
|
|
442
451
|
},
|
|
443
452
|
set(target, prop, value) {
|
|
444
453
|
const descriptor = getDescriptor(target, prop);
|
|
445
|
-
if (descriptor &&
|
|
454
|
+
if (descriptor &&
|
|
455
|
+
!descriptor.configurable &&
|
|
456
|
+
!descriptor.writable &&
|
|
457
|
+
!descriptor.set)
|
|
446
458
|
return true;
|
|
447
459
|
const ah = target.__ajaxHooker;
|
|
448
460
|
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
@@ -466,7 +478,9 @@ const ajaxHooker = function () {
|
|
|
466
478
|
proxyEvents: {},
|
|
467
479
|
});
|
|
468
480
|
xhr.addEventListener("readystatechange", (e) => {
|
|
469
|
-
if (ah.proxyXhr.readyState === 4 &&
|
|
481
|
+
if (ah.proxyXhr.readyState === 4 &&
|
|
482
|
+
ah.request &&
|
|
483
|
+
typeof ah.request.response === "function") {
|
|
470
484
|
const response = {
|
|
471
485
|
finalUrl: ah.proxyXhr.responseURL,
|
|
472
486
|
status: ah.proxyXhr.status,
|
|
@@ -485,7 +499,9 @@ const ajaxHooker = function () {
|
|
|
485
499
|
response[key] = val;
|
|
486
500
|
});
|
|
487
501
|
}
|
|
488
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
502
|
+
ah.resThenable = new AHRequest(ah.request)
|
|
503
|
+
.waitForResponseKeys(response)
|
|
504
|
+
.then(() => {
|
|
489
505
|
for (const key of xhrResponses) {
|
|
490
506
|
ah.proxyProps[key] = {
|
|
491
507
|
get: () => {
|
|
@@ -508,7 +524,13 @@ const ajaxHooker = function () {
|
|
|
508
524
|
set: (val) => ah.addEvent(onEvt, val),
|
|
509
525
|
};
|
|
510
526
|
}
|
|
511
|
-
for (const method of [
|
|
527
|
+
for (const method of [
|
|
528
|
+
"setRequestHeader",
|
|
529
|
+
"addEventListener",
|
|
530
|
+
"removeEventListener",
|
|
531
|
+
"open",
|
|
532
|
+
"send",
|
|
533
|
+
]) {
|
|
512
534
|
ah.proxyProps[method] = { value: ah[method] };
|
|
513
535
|
}
|
|
514
536
|
}
|
|
@@ -555,7 +577,8 @@ const ajaxHooker = function () {
|
|
|
555
577
|
if (!this.request)
|
|
556
578
|
return;
|
|
557
579
|
const headers = this.request.headers;
|
|
558
|
-
headers[header] =
|
|
580
|
+
headers[header] =
|
|
581
|
+
header in headers ? `${headers[header]}, ${value}` : value;
|
|
559
582
|
}
|
|
560
583
|
addEventListener(...args) {
|
|
561
584
|
if (xhrAsyncEvents.includes(args[0])) {
|
|
@@ -586,7 +609,13 @@ const ajaxHooker = function () {
|
|
|
586
609
|
};
|
|
587
610
|
this.openArgs = args;
|
|
588
611
|
this.resThenable = new SyncThenable();
|
|
589
|
-
[
|
|
612
|
+
[
|
|
613
|
+
"responseURL",
|
|
614
|
+
"readyState",
|
|
615
|
+
"status",
|
|
616
|
+
"statusText",
|
|
617
|
+
...xhrResponses,
|
|
618
|
+
].forEach((key) => {
|
|
590
619
|
delete this.proxyProps[key];
|
|
591
620
|
});
|
|
592
621
|
return this.originalXhr.open(method, url, async, ...args);
|
|
@@ -748,13 +777,17 @@ const ajaxHooker = function () {
|
|
|
748
777
|
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
749
778
|
class AHFunction extends Function {
|
|
750
779
|
call(thisArg, ...args) {
|
|
751
|
-
if (thisArg &&
|
|
780
|
+
if (thisArg &&
|
|
781
|
+
thisArg.__ajaxHooker &&
|
|
782
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
752
783
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
753
784
|
}
|
|
754
785
|
return Reflect.apply(this, thisArg, args);
|
|
755
786
|
}
|
|
756
787
|
apply(thisArg, args) {
|
|
757
|
-
if (thisArg &&
|
|
788
|
+
if (thisArg &&
|
|
789
|
+
thisArg.__ajaxHooker &&
|
|
790
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg) {
|
|
758
791
|
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
759
792
|
}
|
|
760
793
|
return Reflect.apply(this, thisArg, args || []);
|
|
@@ -1471,40 +1504,55 @@ class CommonUtil {
|
|
|
1471
1504
|
isNull(...args) {
|
|
1472
1505
|
let result = true;
|
|
1473
1506
|
const checkList = [...args];
|
|
1474
|
-
for (const
|
|
1475
|
-
let
|
|
1476
|
-
if (
|
|
1477
|
-
|
|
1507
|
+
for (const obj of checkList) {
|
|
1508
|
+
let flag = false;
|
|
1509
|
+
if (obj === null || obj === undefined) {
|
|
1510
|
+
// null undefined
|
|
1511
|
+
flag = true;
|
|
1478
1512
|
}
|
|
1479
1513
|
else {
|
|
1480
|
-
switch (typeof
|
|
1514
|
+
switch (typeof obj) {
|
|
1481
1515
|
case "object":
|
|
1482
|
-
if (typeof
|
|
1483
|
-
|
|
1484
|
-
|
|
1516
|
+
if (typeof obj[Symbol.iterator] === "function") {
|
|
1517
|
+
// 可迭代
|
|
1518
|
+
// Map Array NodeList HTMLCollection
|
|
1519
|
+
if (obj instanceof Map) {
|
|
1520
|
+
flag = obj.size === 0;
|
|
1521
|
+
}
|
|
1522
|
+
else {
|
|
1523
|
+
const length = obj.length;
|
|
1524
|
+
if (typeof length === "number") {
|
|
1525
|
+
flag = length === 0;
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1485
1528
|
}
|
|
1486
1529
|
else {
|
|
1487
|
-
|
|
1530
|
+
if (obj?.toString() === "[object Object]") {
|
|
1531
|
+
// {}
|
|
1532
|
+
flag = Object.keys(obj).length === 0;
|
|
1533
|
+
}
|
|
1488
1534
|
}
|
|
1489
1535
|
break;
|
|
1490
1536
|
case "number":
|
|
1491
|
-
|
|
1537
|
+
flag = isNaN(obj) ? true : obj === 0;
|
|
1492
1538
|
break;
|
|
1493
|
-
case "string":
|
|
1494
|
-
|
|
1539
|
+
case "string": {
|
|
1540
|
+
const trimStr = obj.trim();
|
|
1541
|
+
flag = trimStr.trim() === "" || trimStr === "null" || trimStr === "undefined";
|
|
1495
1542
|
break;
|
|
1543
|
+
}
|
|
1496
1544
|
case "boolean":
|
|
1497
|
-
|
|
1545
|
+
flag = !obj;
|
|
1498
1546
|
break;
|
|
1499
1547
|
case "function": {
|
|
1500
|
-
const funcStr =
|
|
1548
|
+
const funcStr = obj.toString().replace(/\s/g, "");
|
|
1501
1549
|
/* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
|
|
1502
|
-
|
|
1550
|
+
flag = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
|
|
1503
1551
|
break;
|
|
1504
1552
|
}
|
|
1505
1553
|
}
|
|
1506
1554
|
}
|
|
1507
|
-
result = result &&
|
|
1555
|
+
result = result && flag;
|
|
1508
1556
|
}
|
|
1509
1557
|
return result;
|
|
1510
1558
|
}
|
|
@@ -1638,6 +1686,12 @@ class UtilsDictionary {
|
|
|
1638
1686
|
this.set(key, value);
|
|
1639
1687
|
}
|
|
1640
1688
|
}
|
|
1689
|
+
[Symbol.dispose]() {
|
|
1690
|
+
this.clear();
|
|
1691
|
+
}
|
|
1692
|
+
async [Symbol.asyncDispose]() {
|
|
1693
|
+
this.clear();
|
|
1694
|
+
}
|
|
1641
1695
|
/**
|
|
1642
1696
|
* 获取字典的长度,同this.size
|
|
1643
1697
|
*/
|
|
@@ -2149,11 +2203,11 @@ class Hooks {
|
|
|
2149
2203
|
return "";
|
|
2150
2204
|
}
|
|
2151
2205
|
try {
|
|
2152
|
-
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2153
|
-
let args = Array.prototype.slice.call(arguments, 0);
|
|
2154
|
-
let obj = this;
|
|
2155
|
-
hookFunc.apply(obj, args);
|
|
2156
|
-
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2206
|
+
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2207
|
+
let args = Array.prototype.slice.call(arguments, 0);
|
|
2208
|
+
let obj = this;
|
|
2209
|
+
hookFunc.apply(obj, args);
|
|
2210
|
+
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2157
2211
|
};`)(_context, _funcName, hookFunc);
|
|
2158
2212
|
_context[_funcName].prototype.isHooked = true;
|
|
2159
2213
|
return true;
|
|
@@ -4173,11 +4227,11 @@ class ModuleRaid {
|
|
|
4173
4227
|
this.constructors = [];
|
|
4174
4228
|
let options = {
|
|
4175
4229
|
target: window,
|
|
4176
|
-
entrypoint:
|
|
4230
|
+
entrypoint: "webpackJsonp",
|
|
4177
4231
|
debug: false,
|
|
4178
4232
|
strict: false,
|
|
4179
4233
|
};
|
|
4180
|
-
if (typeof opts ===
|
|
4234
|
+
if (typeof opts === "object") {
|
|
4181
4235
|
options = Object.assign(Object.assign({}, options), opts);
|
|
4182
4236
|
}
|
|
4183
4237
|
this.target = options.target;
|
|
@@ -4216,7 +4270,7 @@ class ModuleRaid {
|
|
|
4216
4270
|
* @internal
|
|
4217
4271
|
*/
|
|
4218
4272
|
fillModules() {
|
|
4219
|
-
if (typeof this.target[this.entrypoint] ===
|
|
4273
|
+
if (typeof this.target[this.entrypoint] === "function") {
|
|
4220
4274
|
this.functionArguments.forEach((argument, index) => {
|
|
4221
4275
|
try {
|
|
4222
4276
|
if (this.modules && Object.keys(this.modules).length > 0)
|
|
@@ -4243,8 +4297,9 @@ class ModuleRaid {
|
|
|
4243
4297
|
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4244
4298
|
let moduleEnd = false;
|
|
4245
4299
|
let moduleIterator = 0;
|
|
4246
|
-
if (typeof this.target[this.entrypoint] !=
|
|
4247
|
-
|
|
4300
|
+
if (typeof this.target[this.entrypoint] != "function" ||
|
|
4301
|
+
!this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4302
|
+
throw Error("Unknown Webpack structure");
|
|
4248
4303
|
}
|
|
4249
4304
|
while (!moduleEnd) {
|
|
4250
4305
|
try {
|
|
@@ -4277,7 +4332,7 @@ class ModuleRaid {
|
|
|
4277
4332
|
const originalPush = this.target[this.entrypoint].push;
|
|
4278
4333
|
this.target[this.entrypoint].push = (...args) => {
|
|
4279
4334
|
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4280
|
-
document.dispatchEvent(new CustomEvent(
|
|
4335
|
+
document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
|
|
4281
4336
|
return result;
|
|
4282
4337
|
};
|
|
4283
4338
|
}
|
|
@@ -4300,13 +4355,15 @@ class ModuleRaid {
|
|
|
4300
4355
|
}
|
|
4301
4356
|
let windowObjects = Object.keys(this.target);
|
|
4302
4357
|
windowObjects = windowObjects
|
|
4303
|
-
.filter((object) => object.toLowerCase().includes(
|
|
4304
|
-
.
|
|
4358
|
+
.filter((object) => object.toLowerCase().includes("chunk") ||
|
|
4359
|
+
object.toLowerCase().includes("webpack"))
|
|
4360
|
+
.filter((object) => typeof this.target[object] === "function" ||
|
|
4361
|
+
Array.isArray(this.target[object]));
|
|
4305
4362
|
if (windowObjects.length > 1) {
|
|
4306
|
-
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(
|
|
4363
|
+
throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(", ")}`);
|
|
4307
4364
|
}
|
|
4308
4365
|
if (windowObjects.length === 0) {
|
|
4309
|
-
throw Error(
|
|
4366
|
+
throw Error("No Webpack JSONP entrypoints could be detected");
|
|
4310
4367
|
}
|
|
4311
4368
|
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4312
4369
|
this.entrypoint = windowObjects[0];
|
|
@@ -4323,11 +4380,11 @@ class ModuleRaid {
|
|
|
4323
4380
|
for (const key in object) {
|
|
4324
4381
|
const value = object[key];
|
|
4325
4382
|
const lowerCaseQuery = query.toLowerCase();
|
|
4326
|
-
if (typeof value !=
|
|
4383
|
+
if (typeof value != "object") {
|
|
4327
4384
|
const lowerCaseKey = key.toString().toLowerCase();
|
|
4328
4385
|
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4329
4386
|
return true;
|
|
4330
|
-
if (typeof value !=
|
|
4387
|
+
if (typeof value != "object") {
|
|
4331
4388
|
const lowerCaseValue = value.toString().toLowerCase();
|
|
4332
4389
|
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4333
4390
|
return true;
|
|
@@ -4367,31 +4424,31 @@ class ModuleRaid {
|
|
|
4367
4424
|
const results = [];
|
|
4368
4425
|
const modules = Object.keys(this.modules);
|
|
4369
4426
|
if (modules.length === 0) {
|
|
4370
|
-
throw new Error(
|
|
4427
|
+
throw new Error("There are no modules to search through!");
|
|
4371
4428
|
}
|
|
4372
4429
|
modules.forEach((key) => {
|
|
4373
4430
|
const module = this.modules[key.toString()];
|
|
4374
4431
|
if (module === undefined)
|
|
4375
4432
|
return;
|
|
4376
4433
|
try {
|
|
4377
|
-
if (typeof query ===
|
|
4434
|
+
if (typeof query === "string") {
|
|
4378
4435
|
query = query.toLowerCase();
|
|
4379
4436
|
switch (typeof module) {
|
|
4380
|
-
case
|
|
4437
|
+
case "string":
|
|
4381
4438
|
if (module.toLowerCase().includes(query))
|
|
4382
4439
|
results.push(module);
|
|
4383
4440
|
break;
|
|
4384
|
-
case
|
|
4441
|
+
case "function":
|
|
4385
4442
|
if (module.toString().toLowerCase().includes(query))
|
|
4386
4443
|
results.push(module);
|
|
4387
4444
|
break;
|
|
4388
|
-
case
|
|
4445
|
+
case "object":
|
|
4389
4446
|
if (this.searchObject(module, query))
|
|
4390
4447
|
results.push(module);
|
|
4391
4448
|
break;
|
|
4392
4449
|
}
|
|
4393
4450
|
}
|
|
4394
|
-
else if (typeof query ===
|
|
4451
|
+
else if (typeof query === "function") {
|
|
4395
4452
|
if (query(module))
|
|
4396
4453
|
results.push(module);
|
|
4397
4454
|
}
|
|
@@ -4444,17 +4501,17 @@ class ModuleRaid {
|
|
|
4444
4501
|
const results = [];
|
|
4445
4502
|
const constructors = Object.keys(this.constructors);
|
|
4446
4503
|
if (constructors.length === 0) {
|
|
4447
|
-
throw new Error(
|
|
4504
|
+
throw new Error("There are no constructors to search through!");
|
|
4448
4505
|
}
|
|
4449
4506
|
constructors.forEach((key) => {
|
|
4450
4507
|
const constructor = this.constructors[key];
|
|
4451
4508
|
try {
|
|
4452
|
-
if (typeof query ===
|
|
4509
|
+
if (typeof query === "string") {
|
|
4453
4510
|
query = query.toLowerCase();
|
|
4454
4511
|
if (constructor.toString().toLowerCase().includes(query))
|
|
4455
4512
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4456
4513
|
}
|
|
4457
|
-
else if (typeof query ===
|
|
4514
|
+
else if (typeof query === "function") {
|
|
4458
4515
|
if (query(constructor))
|
|
4459
4516
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4460
4517
|
}
|
|
@@ -5746,7 +5803,7 @@ class Utils {
|
|
|
5746
5803
|
}
|
|
5747
5804
|
return strFound ? true : false;
|
|
5748
5805
|
}
|
|
5749
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5806
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5750
5807
|
byteSize = parseInt(byteSize.toString());
|
|
5751
5808
|
if (isNaN(byteSize)) {
|
|
5752
5809
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5754,8 +5811,9 @@ class Utils {
|
|
|
5754
5811
|
let result = 0;
|
|
5755
5812
|
let resultType = "KB";
|
|
5756
5813
|
const sizeData = {};
|
|
5814
|
+
const unitNumber = Number(unit);
|
|
5757
5815
|
sizeData.B = 1;
|
|
5758
|
-
sizeData.KB =
|
|
5816
|
+
sizeData.KB = unitNumber;
|
|
5759
5817
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5760
5818
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5761
5819
|
sizeData.TB = sizeData.GB * sizeData.KB;
|