@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.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 || []);
|
|
@@ -1474,40 +1507,55 @@ var Utils = (function () {
|
|
|
1474
1507
|
isNull(...args) {
|
|
1475
1508
|
let result = true;
|
|
1476
1509
|
const checkList = [...args];
|
|
1477
|
-
for (const
|
|
1478
|
-
let
|
|
1479
|
-
if (
|
|
1480
|
-
|
|
1510
|
+
for (const obj of checkList) {
|
|
1511
|
+
let flag = false;
|
|
1512
|
+
if (obj === null || obj === undefined) {
|
|
1513
|
+
// null undefined
|
|
1514
|
+
flag = true;
|
|
1481
1515
|
}
|
|
1482
1516
|
else {
|
|
1483
|
-
switch (typeof
|
|
1517
|
+
switch (typeof obj) {
|
|
1484
1518
|
case "object":
|
|
1485
|
-
if (typeof
|
|
1486
|
-
|
|
1487
|
-
|
|
1519
|
+
if (typeof obj[Symbol.iterator] === "function") {
|
|
1520
|
+
// 可迭代
|
|
1521
|
+
// Map Array NodeList HTMLCollection
|
|
1522
|
+
if (obj instanceof Map) {
|
|
1523
|
+
flag = obj.size === 0;
|
|
1524
|
+
}
|
|
1525
|
+
else {
|
|
1526
|
+
const length = obj.length;
|
|
1527
|
+
if (typeof length === "number") {
|
|
1528
|
+
flag = length === 0;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1488
1531
|
}
|
|
1489
1532
|
else {
|
|
1490
|
-
|
|
1533
|
+
if (obj?.toString() === "[object Object]") {
|
|
1534
|
+
// {}
|
|
1535
|
+
flag = Object.keys(obj).length === 0;
|
|
1536
|
+
}
|
|
1491
1537
|
}
|
|
1492
1538
|
break;
|
|
1493
1539
|
case "number":
|
|
1494
|
-
|
|
1540
|
+
flag = isNaN(obj) ? true : obj === 0;
|
|
1495
1541
|
break;
|
|
1496
|
-
case "string":
|
|
1497
|
-
|
|
1542
|
+
case "string": {
|
|
1543
|
+
const trimStr = obj.trim();
|
|
1544
|
+
flag = trimStr.trim() === "" || trimStr === "null" || trimStr === "undefined";
|
|
1498
1545
|
break;
|
|
1546
|
+
}
|
|
1499
1547
|
case "boolean":
|
|
1500
|
-
|
|
1548
|
+
flag = !obj;
|
|
1501
1549
|
break;
|
|
1502
1550
|
case "function": {
|
|
1503
|
-
const funcStr =
|
|
1551
|
+
const funcStr = obj.toString().replace(/\s/g, "");
|
|
1504
1552
|
/* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
|
|
1505
|
-
|
|
1553
|
+
flag = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
|
|
1506
1554
|
break;
|
|
1507
1555
|
}
|
|
1508
1556
|
}
|
|
1509
1557
|
}
|
|
1510
|
-
result = result &&
|
|
1558
|
+
result = result && flag;
|
|
1511
1559
|
}
|
|
1512
1560
|
return result;
|
|
1513
1561
|
}
|
|
@@ -1641,6 +1689,12 @@ var Utils = (function () {
|
|
|
1641
1689
|
this.set(key, value);
|
|
1642
1690
|
}
|
|
1643
1691
|
}
|
|
1692
|
+
[Symbol.dispose]() {
|
|
1693
|
+
this.clear();
|
|
1694
|
+
}
|
|
1695
|
+
async [Symbol.asyncDispose]() {
|
|
1696
|
+
this.clear();
|
|
1697
|
+
}
|
|
1644
1698
|
/**
|
|
1645
1699
|
* 获取字典的长度,同this.size
|
|
1646
1700
|
*/
|
|
@@ -2152,11 +2206,11 @@ var Utils = (function () {
|
|
|
2152
2206
|
return "";
|
|
2153
2207
|
}
|
|
2154
2208
|
try {
|
|
2155
|
-
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2156
|
-
let args = Array.prototype.slice.call(arguments, 0);
|
|
2157
|
-
let obj = this;
|
|
2158
|
-
hookFunc.apply(obj, args);
|
|
2159
|
-
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);
|
|
2160
2214
|
};`)(_context, _funcName, hookFunc);
|
|
2161
2215
|
_context[_funcName].prototype.isHooked = true;
|
|
2162
2216
|
return true;
|
|
@@ -4176,11 +4230,11 @@ var Utils = (function () {
|
|
|
4176
4230
|
this.constructors = [];
|
|
4177
4231
|
let options = {
|
|
4178
4232
|
target: window,
|
|
4179
|
-
entrypoint:
|
|
4233
|
+
entrypoint: "webpackJsonp",
|
|
4180
4234
|
debug: false,
|
|
4181
4235
|
strict: false,
|
|
4182
4236
|
};
|
|
4183
|
-
if (typeof opts ===
|
|
4237
|
+
if (typeof opts === "object") {
|
|
4184
4238
|
options = Object.assign(Object.assign({}, options), opts);
|
|
4185
4239
|
}
|
|
4186
4240
|
this.target = options.target;
|
|
@@ -4219,7 +4273,7 @@ var Utils = (function () {
|
|
|
4219
4273
|
* @internal
|
|
4220
4274
|
*/
|
|
4221
4275
|
fillModules() {
|
|
4222
|
-
if (typeof this.target[this.entrypoint] ===
|
|
4276
|
+
if (typeof this.target[this.entrypoint] === "function") {
|
|
4223
4277
|
this.functionArguments.forEach((argument, index) => {
|
|
4224
4278
|
try {
|
|
4225
4279
|
if (this.modules && Object.keys(this.modules).length > 0)
|
|
@@ -4246,8 +4300,9 @@ var Utils = (function () {
|
|
|
4246
4300
|
if (this.modules && Object.keys(this.modules).length == 0) {
|
|
4247
4301
|
let moduleEnd = false;
|
|
4248
4302
|
let moduleIterator = 0;
|
|
4249
|
-
if (typeof this.target[this.entrypoint] !=
|
|
4250
|
-
|
|
4303
|
+
if (typeof this.target[this.entrypoint] != "function" ||
|
|
4304
|
+
!this.target[this.entrypoint]([], [], [moduleIterator])) {
|
|
4305
|
+
throw Error("Unknown Webpack structure");
|
|
4251
4306
|
}
|
|
4252
4307
|
while (!moduleEnd) {
|
|
4253
4308
|
try {
|
|
@@ -4280,7 +4335,7 @@ var Utils = (function () {
|
|
|
4280
4335
|
const originalPush = this.target[this.entrypoint].push;
|
|
4281
4336
|
this.target[this.entrypoint].push = (...args) => {
|
|
4282
4337
|
const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
|
|
4283
|
-
document.dispatchEvent(new CustomEvent(
|
|
4338
|
+
document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
|
|
4284
4339
|
return result;
|
|
4285
4340
|
};
|
|
4286
4341
|
}
|
|
@@ -4303,13 +4358,15 @@ var Utils = (function () {
|
|
|
4303
4358
|
}
|
|
4304
4359
|
let windowObjects = Object.keys(this.target);
|
|
4305
4360
|
windowObjects = windowObjects
|
|
4306
|
-
.filter((object) => object.toLowerCase().includes(
|
|
4307
|
-
.
|
|
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]));
|
|
4308
4365
|
if (windowObjects.length > 1) {
|
|
4309
|
-
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(", ")}`);
|
|
4310
4367
|
}
|
|
4311
4368
|
if (windowObjects.length === 0) {
|
|
4312
|
-
throw Error(
|
|
4369
|
+
throw Error("No Webpack JSONP entrypoints could be detected");
|
|
4313
4370
|
}
|
|
4314
4371
|
this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
|
|
4315
4372
|
this.entrypoint = windowObjects[0];
|
|
@@ -4326,11 +4383,11 @@ var Utils = (function () {
|
|
|
4326
4383
|
for (const key in object) {
|
|
4327
4384
|
const value = object[key];
|
|
4328
4385
|
const lowerCaseQuery = query.toLowerCase();
|
|
4329
|
-
if (typeof value !=
|
|
4386
|
+
if (typeof value != "object") {
|
|
4330
4387
|
const lowerCaseKey = key.toString().toLowerCase();
|
|
4331
4388
|
if (lowerCaseKey.includes(lowerCaseQuery))
|
|
4332
4389
|
return true;
|
|
4333
|
-
if (typeof value !=
|
|
4390
|
+
if (typeof value != "object") {
|
|
4334
4391
|
const lowerCaseValue = value.toString().toLowerCase();
|
|
4335
4392
|
if (lowerCaseValue.includes(lowerCaseQuery))
|
|
4336
4393
|
return true;
|
|
@@ -4370,31 +4427,31 @@ var Utils = (function () {
|
|
|
4370
4427
|
const results = [];
|
|
4371
4428
|
const modules = Object.keys(this.modules);
|
|
4372
4429
|
if (modules.length === 0) {
|
|
4373
|
-
throw new Error(
|
|
4430
|
+
throw new Error("There are no modules to search through!");
|
|
4374
4431
|
}
|
|
4375
4432
|
modules.forEach((key) => {
|
|
4376
4433
|
const module = this.modules[key.toString()];
|
|
4377
4434
|
if (module === undefined)
|
|
4378
4435
|
return;
|
|
4379
4436
|
try {
|
|
4380
|
-
if (typeof query ===
|
|
4437
|
+
if (typeof query === "string") {
|
|
4381
4438
|
query = query.toLowerCase();
|
|
4382
4439
|
switch (typeof module) {
|
|
4383
|
-
case
|
|
4440
|
+
case "string":
|
|
4384
4441
|
if (module.toLowerCase().includes(query))
|
|
4385
4442
|
results.push(module);
|
|
4386
4443
|
break;
|
|
4387
|
-
case
|
|
4444
|
+
case "function":
|
|
4388
4445
|
if (module.toString().toLowerCase().includes(query))
|
|
4389
4446
|
results.push(module);
|
|
4390
4447
|
break;
|
|
4391
|
-
case
|
|
4448
|
+
case "object":
|
|
4392
4449
|
if (this.searchObject(module, query))
|
|
4393
4450
|
results.push(module);
|
|
4394
4451
|
break;
|
|
4395
4452
|
}
|
|
4396
4453
|
}
|
|
4397
|
-
else if (typeof query ===
|
|
4454
|
+
else if (typeof query === "function") {
|
|
4398
4455
|
if (query(module))
|
|
4399
4456
|
results.push(module);
|
|
4400
4457
|
}
|
|
@@ -4447,17 +4504,17 @@ var Utils = (function () {
|
|
|
4447
4504
|
const results = [];
|
|
4448
4505
|
const constructors = Object.keys(this.constructors);
|
|
4449
4506
|
if (constructors.length === 0) {
|
|
4450
|
-
throw new Error(
|
|
4507
|
+
throw new Error("There are no constructors to search through!");
|
|
4451
4508
|
}
|
|
4452
4509
|
constructors.forEach((key) => {
|
|
4453
4510
|
const constructor = this.constructors[key];
|
|
4454
4511
|
try {
|
|
4455
|
-
if (typeof query ===
|
|
4512
|
+
if (typeof query === "string") {
|
|
4456
4513
|
query = query.toLowerCase();
|
|
4457
4514
|
if (constructor.toString().toLowerCase().includes(query))
|
|
4458
4515
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4459
4516
|
}
|
|
4460
|
-
else if (typeof query ===
|
|
4517
|
+
else if (typeof query === "function") {
|
|
4461
4518
|
if (query(constructor))
|
|
4462
4519
|
results.push([this.constructors[key], this.modules[key]]);
|
|
4463
4520
|
}
|
|
@@ -5749,7 +5806,7 @@ var Utils = (function () {
|
|
|
5749
5806
|
}
|
|
5750
5807
|
return strFound ? true : false;
|
|
5751
5808
|
}
|
|
5752
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5809
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5753
5810
|
byteSize = parseInt(byteSize.toString());
|
|
5754
5811
|
if (isNaN(byteSize)) {
|
|
5755
5812
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5757,8 +5814,9 @@ var Utils = (function () {
|
|
|
5757
5814
|
let result = 0;
|
|
5758
5815
|
let resultType = "KB";
|
|
5759
5816
|
const sizeData = {};
|
|
5817
|
+
const unitNumber = Number(unit);
|
|
5760
5818
|
sizeData.B = 1;
|
|
5761
|
-
sizeData.KB =
|
|
5819
|
+
sizeData.KB = unitNumber;
|
|
5762
5820
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5763
5821
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5764
5822
|
sizeData.TB = sizeData.GB * sizeData.KB;
|