@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.
Files changed (73) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +128 -85
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +1 -1
  5. package/dist/index.amd.min.js.map +1 -1
  6. package/dist/index.cjs.js +128 -85
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +1 -1
  9. package/dist/index.cjs.min.js.map +1 -1
  10. package/dist/index.esm.js +128 -85
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +1 -1
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.iife.js +128 -85
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +1 -1
  17. package/dist/index.iife.min.js.map +1 -1
  18. package/dist/index.system.js +128 -85
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +1 -1
  21. package/dist/index.system.min.js.map +1 -1
  22. package/dist/index.umd.js +128 -85
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/index.umd.min.js.map +1 -1
  26. package/dist/types/src/Dictionary.d.ts +2 -0
  27. package/dist/types/src/Utils.d.ts +5 -2
  28. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  29. package/dist/types/src/types/Log.d.ts +19 -19
  30. package/dist/types/src/types/Progress.d.ts +20 -20
  31. package/dist/types/src/types/React.d.ts +119 -119
  32. package/dist/types/src/types/TryCatch.d.ts +9 -9
  33. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  34. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  35. package/dist/types/src/types/Vue2.d.ts +166 -166
  36. package/dist/types/src/types/WindowApi.d.ts +14 -14
  37. package/dist/types/src/types/ajaxHooker.d.ts +155 -155
  38. package/dist/types/src/types/env.d.ts +7 -7
  39. package/dist/types/src/types/global.d.ts +31 -31
  40. package/package.json +26 -24
  41. package/src/ColorConversion.ts +118 -118
  42. package/src/CommonUtil.ts +301 -301
  43. package/src/DOMUtils.ts +251 -251
  44. package/src/Dictionary.ts +205 -199
  45. package/src/GBKEncoder.ts +108 -108
  46. package/src/Hooks.ts +73 -73
  47. package/src/Httpx.ts +1457 -1457
  48. package/src/LockFunction.ts +65 -62
  49. package/src/Log.ts +233 -233
  50. package/src/ModuleRaid.js +378 -360
  51. package/src/Progress.ts +108 -108
  52. package/src/TryCatch.ts +86 -86
  53. package/src/Utils.ts +3860 -3852
  54. package/src/UtilsCommon.ts +14 -14
  55. package/src/UtilsGMCookie.ts +273 -273
  56. package/src/UtilsGMMenu.ts +460 -460
  57. package/src/Vue.ts +233 -233
  58. package/src/WindowApi.ts +59 -59
  59. package/src/ajaxHooker/ajaxHooker.js +606 -538
  60. package/src/ajaxHooker/ajaxHooker1.2.4.js +440 -438
  61. package/src/indexedDB.ts +497 -497
  62. package/src/types/Httpx.d.ts +1344 -1344
  63. package/src/types/Log.d.ts +19 -19
  64. package/src/types/Progress.d.ts +20 -20
  65. package/src/types/React.d.ts +119 -119
  66. package/src/types/TryCatch.d.ts +9 -9
  67. package/src/types/UtilsGMCookie.d.ts +93 -93
  68. package/src/types/UtilsGMMenu.d.ts +77 -77
  69. package/src/types/Vue2.d.ts +166 -166
  70. package/src/types/WindowApi.d.ts +14 -14
  71. package/src/types/ajaxHooker.d.ts +155 -155
  72. package/src/types/env.d.ts +7 -7
  73. 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 isMessagePort = (sender) => {
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:function(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)},f=(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])})},m=new Map,h=d(globalThis.clearTimeout,m),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=f(m,performance,globalThis.setTimeout,w),T=f(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
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.12";
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 obj && ["object", "function"].includes(typeof obj) && typeof obj.then === "function";
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] = lheader in headers ? `${headers[lheader]}, ${value}` : value;
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]" && !url.includes(obj.url):
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 && obj.method.toUpperCase() !== method.toUpperCase():
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) || isThenable(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 && !descriptor.configurable && !descriptor.writable && !descriptor.get)
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 && !descriptor.configurable && !descriptor.writable && !descriptor.set)
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 && ah.request && typeof ah.request.response === "function") {
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).waitForResponseKeys(response).then(() => {
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 ["setRequestHeader", "addEventListener", "removeEventListener", "open", "send"]) {
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] = header in headers ? `${headers[header]}, ${value}` : value;
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
- ["responseURL", "readyState", "status", "statusText", ...xhrResponses].forEach((key) => {
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 && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === 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 && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === 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 || []);
@@ -1653,6 +1686,12 @@ class UtilsDictionary {
1653
1686
  this.set(key, value);
1654
1687
  }
1655
1688
  }
1689
+ [Symbol.dispose]() {
1690
+ this.clear();
1691
+ }
1692
+ async [Symbol.asyncDispose]() {
1693
+ this.clear();
1694
+ }
1656
1695
  /**
1657
1696
  * 获取字典的长度,同this.size
1658
1697
  */
@@ -2164,11 +2203,11 @@ class Hooks {
2164
2203
  return "";
2165
2204
  }
2166
2205
  try {
2167
- new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2168
- let args = Array.prototype.slice.call(arguments, 0);
2169
- let obj = this;
2170
- hookFunc.apply(obj, args);
2171
- 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);
2172
2211
  };`)(_context, _funcName, hookFunc);
2173
2212
  _context[_funcName].prototype.isHooked = true;
2174
2213
  return true;
@@ -4188,11 +4227,11 @@ class ModuleRaid {
4188
4227
  this.constructors = [];
4189
4228
  let options = {
4190
4229
  target: window,
4191
- entrypoint: 'webpackJsonp',
4230
+ entrypoint: "webpackJsonp",
4192
4231
  debug: false,
4193
4232
  strict: false,
4194
4233
  };
4195
- if (typeof opts === 'object') {
4234
+ if (typeof opts === "object") {
4196
4235
  options = Object.assign(Object.assign({}, options), opts);
4197
4236
  }
4198
4237
  this.target = options.target;
@@ -4231,7 +4270,7 @@ class ModuleRaid {
4231
4270
  * @internal
4232
4271
  */
4233
4272
  fillModules() {
4234
- if (typeof this.target[this.entrypoint] === 'function') {
4273
+ if (typeof this.target[this.entrypoint] === "function") {
4235
4274
  this.functionArguments.forEach((argument, index) => {
4236
4275
  try {
4237
4276
  if (this.modules && Object.keys(this.modules).length > 0)
@@ -4258,8 +4297,9 @@ class ModuleRaid {
4258
4297
  if (this.modules && Object.keys(this.modules).length == 0) {
4259
4298
  let moduleEnd = false;
4260
4299
  let moduleIterator = 0;
4261
- if (typeof this.target[this.entrypoint] != 'function' || !this.target[this.entrypoint]([], [], [moduleIterator])) {
4262
- throw Error('Unknown Webpack structure');
4300
+ if (typeof this.target[this.entrypoint] != "function" ||
4301
+ !this.target[this.entrypoint]([], [], [moduleIterator])) {
4302
+ throw Error("Unknown Webpack structure");
4263
4303
  }
4264
4304
  while (!moduleEnd) {
4265
4305
  try {
@@ -4292,7 +4332,7 @@ class ModuleRaid {
4292
4332
  const originalPush = this.target[this.entrypoint].push;
4293
4333
  this.target[this.entrypoint].push = (...args) => {
4294
4334
  const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
4295
- document.dispatchEvent(new CustomEvent('moduleraid:webpack-push', { detail: args }));
4335
+ document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
4296
4336
  return result;
4297
4337
  };
4298
4338
  }
@@ -4315,13 +4355,15 @@ class ModuleRaid {
4315
4355
  }
4316
4356
  let windowObjects = Object.keys(this.target);
4317
4357
  windowObjects = windowObjects
4318
- .filter((object) => object.toLowerCase().includes('chunk') || object.toLowerCase().includes('webpack'))
4319
- .filter((object) => typeof this.target[object] === 'function' || Array.isArray(this.target[object]));
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]));
4320
4362
  if (windowObjects.length > 1) {
4321
- 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(", ")}`);
4322
4364
  }
4323
4365
  if (windowObjects.length === 0) {
4324
- throw Error('No Webpack JSONP entrypoints could be detected');
4366
+ throw Error("No Webpack JSONP entrypoints could be detected");
4325
4367
  }
4326
4368
  this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
4327
4369
  this.entrypoint = windowObjects[0];
@@ -4338,11 +4380,11 @@ class ModuleRaid {
4338
4380
  for (const key in object) {
4339
4381
  const value = object[key];
4340
4382
  const lowerCaseQuery = query.toLowerCase();
4341
- if (typeof value != 'object') {
4383
+ if (typeof value != "object") {
4342
4384
  const lowerCaseKey = key.toString().toLowerCase();
4343
4385
  if (lowerCaseKey.includes(lowerCaseQuery))
4344
4386
  return true;
4345
- if (typeof value != 'object') {
4387
+ if (typeof value != "object") {
4346
4388
  const lowerCaseValue = value.toString().toLowerCase();
4347
4389
  if (lowerCaseValue.includes(lowerCaseQuery))
4348
4390
  return true;
@@ -4382,31 +4424,31 @@ class ModuleRaid {
4382
4424
  const results = [];
4383
4425
  const modules = Object.keys(this.modules);
4384
4426
  if (modules.length === 0) {
4385
- throw new Error('There are no modules to search through!');
4427
+ throw new Error("There are no modules to search through!");
4386
4428
  }
4387
4429
  modules.forEach((key) => {
4388
4430
  const module = this.modules[key.toString()];
4389
4431
  if (module === undefined)
4390
4432
  return;
4391
4433
  try {
4392
- if (typeof query === 'string') {
4434
+ if (typeof query === "string") {
4393
4435
  query = query.toLowerCase();
4394
4436
  switch (typeof module) {
4395
- case 'string':
4437
+ case "string":
4396
4438
  if (module.toLowerCase().includes(query))
4397
4439
  results.push(module);
4398
4440
  break;
4399
- case 'function':
4441
+ case "function":
4400
4442
  if (module.toString().toLowerCase().includes(query))
4401
4443
  results.push(module);
4402
4444
  break;
4403
- case 'object':
4445
+ case "object":
4404
4446
  if (this.searchObject(module, query))
4405
4447
  results.push(module);
4406
4448
  break;
4407
4449
  }
4408
4450
  }
4409
- else if (typeof query === 'function') {
4451
+ else if (typeof query === "function") {
4410
4452
  if (query(module))
4411
4453
  results.push(module);
4412
4454
  }
@@ -4459,17 +4501,17 @@ class ModuleRaid {
4459
4501
  const results = [];
4460
4502
  const constructors = Object.keys(this.constructors);
4461
4503
  if (constructors.length === 0) {
4462
- throw new Error('There are no constructors to search through!');
4504
+ throw new Error("There are no constructors to search through!");
4463
4505
  }
4464
4506
  constructors.forEach((key) => {
4465
4507
  const constructor = this.constructors[key];
4466
4508
  try {
4467
- if (typeof query === 'string') {
4509
+ if (typeof query === "string") {
4468
4510
  query = query.toLowerCase();
4469
4511
  if (constructor.toString().toLowerCase().includes(query))
4470
4512
  results.push([this.constructors[key], this.modules[key]]);
4471
4513
  }
4472
- else if (typeof query === 'function') {
4514
+ else if (typeof query === "function") {
4473
4515
  if (query(constructor))
4474
4516
  results.push([this.constructors[key], this.modules[key]]);
4475
4517
  }
@@ -5761,7 +5803,7 @@ class Utils {
5761
5803
  }
5762
5804
  return strFound ? true : false;
5763
5805
  }
5764
- formatByteToSize(byteSize, addType = true) {
5806
+ formatByteToSize(byteSize, addType = true, unit = "1024") {
5765
5807
  byteSize = parseInt(byteSize.toString());
5766
5808
  if (isNaN(byteSize)) {
5767
5809
  throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
@@ -5769,8 +5811,9 @@ class Utils {
5769
5811
  let result = 0;
5770
5812
  let resultType = "KB";
5771
5813
  const sizeData = {};
5814
+ const unitNumber = Number(unit);
5772
5815
  sizeData.B = 1;
5773
- sizeData.KB = 1024;
5816
+ sizeData.KB = unitNumber;
5774
5817
  sizeData.MB = sizeData.KB * sizeData.KB;
5775
5818
  sizeData.GB = sizeData.MB * sizeData.KB;
5776
5819
  sizeData.TB = sizeData.GB * sizeData.KB;