@whitesev/utils 2.9.12 → 2.10.0
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 +206 -117
- 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 +206 -117
- 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 +206 -117
- 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 +206 -117
- 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 +206 -117
- 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 +206 -117
- 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 +9 -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 +3907 -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,15 +231,15 @@ 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
|
-
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
237
|
+
const clearInterval$1 = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
238
238
|
const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
239
|
-
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
239
|
+
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
240
240
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
241
241
|
|
|
242
|
-
const version = "2.
|
|
242
|
+
const version = "2.10.0";
|
|
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
|
}
|
|
@@ -5678,8 +5720,8 @@ class Utils {
|
|
|
5678
5720
|
let timer = null;
|
|
5679
5721
|
const that = this;
|
|
5680
5722
|
return function (...args) {
|
|
5681
|
-
|
|
5682
|
-
timer =
|
|
5723
|
+
clearTimeout(timer);
|
|
5724
|
+
timer = setTimeout(function () {
|
|
5683
5725
|
fn.apply(that, args);
|
|
5684
5726
|
}, delay);
|
|
5685
5727
|
};
|
|
@@ -5698,7 +5740,6 @@ class Utils {
|
|
|
5698
5740
|
**/
|
|
5699
5741
|
Dictionary = UtilsDictionary;
|
|
5700
5742
|
downloadBase64(base64Data, fileName, isIFrame = false) {
|
|
5701
|
-
const that = this;
|
|
5702
5743
|
if (typeof base64Data !== "string") {
|
|
5703
5744
|
throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
|
|
5704
5745
|
}
|
|
@@ -5711,7 +5752,7 @@ class Utils {
|
|
|
5711
5752
|
$iframe.style.display = "none";
|
|
5712
5753
|
$iframe.src = base64Data;
|
|
5713
5754
|
(this.windowApi.document.body || this.windowApi.document.documentElement).appendChild($iframe);
|
|
5714
|
-
|
|
5755
|
+
setTimeout(() => {
|
|
5715
5756
|
$iframe.contentWindow.document.execCommand("SaveAs", true, fileName);
|
|
5716
5757
|
(this.windowApi.document.body || this.windowApi.document.documentElement).removeChild($iframe);
|
|
5717
5758
|
}, 100);
|
|
@@ -5763,7 +5804,7 @@ class Utils {
|
|
|
5763
5804
|
}
|
|
5764
5805
|
return strFound ? true : false;
|
|
5765
5806
|
}
|
|
5766
|
-
formatByteToSize(byteSize, addType = true) {
|
|
5807
|
+
formatByteToSize(byteSize, addType = true, unit = "1024") {
|
|
5767
5808
|
byteSize = parseInt(byteSize.toString());
|
|
5768
5809
|
if (isNaN(byteSize)) {
|
|
5769
5810
|
throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
|
|
@@ -5771,8 +5812,9 @@ class Utils {
|
|
|
5771
5812
|
let result = 0;
|
|
5772
5813
|
let resultType = "KB";
|
|
5773
5814
|
const sizeData = {};
|
|
5815
|
+
const unitNumber = Number(unit);
|
|
5774
5816
|
sizeData.B = 1;
|
|
5775
|
-
sizeData.KB =
|
|
5817
|
+
sizeData.KB = unitNumber;
|
|
5776
5818
|
sizeData.MB = sizeData.KB * sizeData.KB;
|
|
5777
5819
|
sizeData.GB = sizeData.MB * sizeData.KB;
|
|
5778
5820
|
sizeData.TB = sizeData.GB * sizeData.KB;
|
|
@@ -7609,7 +7651,6 @@ class Utils {
|
|
|
7609
7651
|
});
|
|
7610
7652
|
}
|
|
7611
7653
|
setTimeout(callback, delayTime = 0) {
|
|
7612
|
-
const that = this;
|
|
7613
7654
|
if (typeof callback !== "function" && typeof callback !== "string") {
|
|
7614
7655
|
throw new TypeError("Utils.setTimeout 参数 callback 必须为 function|string 类型");
|
|
7615
7656
|
}
|
|
@@ -7617,18 +7658,17 @@ class Utils {
|
|
|
7617
7658
|
throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
|
|
7618
7659
|
}
|
|
7619
7660
|
return new Promise((resolve) => {
|
|
7620
|
-
|
|
7621
|
-
resolve(
|
|
7661
|
+
setTimeout(() => {
|
|
7662
|
+
resolve(this.tryCatch().run(callback));
|
|
7622
7663
|
}, delayTime);
|
|
7623
7664
|
});
|
|
7624
7665
|
}
|
|
7625
7666
|
sleep(delayTime = 0) {
|
|
7626
|
-
const that = this;
|
|
7627
7667
|
if (typeof delayTime !== "number") {
|
|
7628
7668
|
throw new Error("Utils.sleep 参数 delayTime 必须为 number 类型");
|
|
7629
7669
|
}
|
|
7630
7670
|
return new Promise((resolve) => {
|
|
7631
|
-
|
|
7671
|
+
setTimeout(() => {
|
|
7632
7672
|
resolve(void 0);
|
|
7633
7673
|
}, delayTime);
|
|
7634
7674
|
});
|
|
@@ -7954,13 +7994,12 @@ class Utils {
|
|
|
7954
7994
|
});
|
|
7955
7995
|
}
|
|
7956
7996
|
waitPropertyByInterval(checkFn, propertyName, intervalTimer = 250, maxTime = -1) {
|
|
7957
|
-
const that = this;
|
|
7958
7997
|
if (checkFn == null) {
|
|
7959
7998
|
throw new TypeError("checkObj 不能为空对象 ");
|
|
7960
7999
|
}
|
|
7961
8000
|
let isResolve = false;
|
|
7962
8001
|
return new Promise((resolve, reject) => {
|
|
7963
|
-
const interval =
|
|
8002
|
+
const interval = setInterval(() => {
|
|
7964
8003
|
let inst = checkFn;
|
|
7965
8004
|
if (typeof checkFn === "function") {
|
|
7966
8005
|
inst = checkFn();
|
|
@@ -7973,14 +8012,14 @@ class Utils {
|
|
|
7973
8012
|
}
|
|
7974
8013
|
if ((typeof propertyName === "function" && propertyName(inst)) || Reflect.has(inst, propertyName)) {
|
|
7975
8014
|
isResolve = true;
|
|
7976
|
-
|
|
8015
|
+
clearInterval(interval);
|
|
7977
8016
|
resolve(inst[propertyName]);
|
|
7978
8017
|
}
|
|
7979
8018
|
}, intervalTimer);
|
|
7980
8019
|
if (maxTime !== -1) {
|
|
7981
|
-
|
|
8020
|
+
setTimeout(() => {
|
|
7982
8021
|
if (!isResolve) {
|
|
7983
|
-
|
|
8022
|
+
clearInterval(interval);
|
|
7984
8023
|
reject();
|
|
7985
8024
|
}
|
|
7986
8025
|
}, maxTime);
|
|
@@ -8202,9 +8241,8 @@ class Utils {
|
|
|
8202
8241
|
workerSetTimeout(callback, timeout = 0) {
|
|
8203
8242
|
try {
|
|
8204
8243
|
return setTimeout$1(callback, timeout);
|
|
8205
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8206
8244
|
}
|
|
8207
|
-
catch
|
|
8245
|
+
catch {
|
|
8208
8246
|
return this.windowApi.setTimeout(callback, timeout);
|
|
8209
8247
|
}
|
|
8210
8248
|
}
|
|
@@ -8217,12 +8255,8 @@ class Utils {
|
|
|
8217
8255
|
if (timeId != null) {
|
|
8218
8256
|
clearTimeout$1(timeId);
|
|
8219
8257
|
}
|
|
8220
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8221
|
-
}
|
|
8222
|
-
catch (error) {
|
|
8223
|
-
// console.log(error);
|
|
8224
8258
|
}
|
|
8225
|
-
|
|
8259
|
+
catch {
|
|
8226
8260
|
this.windowApi.clearTimeout(timeId);
|
|
8227
8261
|
}
|
|
8228
8262
|
}
|
|
@@ -8233,10 +8267,9 @@ class Utils {
|
|
|
8233
8267
|
*/
|
|
8234
8268
|
workerSetInterval(callback, timeout = 0) {
|
|
8235
8269
|
try {
|
|
8236
|
-
return setInterval(callback, timeout);
|
|
8237
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8270
|
+
return setInterval$1(callback, timeout);
|
|
8238
8271
|
}
|
|
8239
|
-
catch
|
|
8272
|
+
catch {
|
|
8240
8273
|
return this.windowApi.setInterval(callback, timeout);
|
|
8241
8274
|
}
|
|
8242
8275
|
}
|
|
@@ -8247,14 +8280,10 @@ class Utils {
|
|
|
8247
8280
|
workerClearInterval(timeId) {
|
|
8248
8281
|
try {
|
|
8249
8282
|
if (timeId != null) {
|
|
8250
|
-
clearInterval(timeId);
|
|
8283
|
+
clearInterval$1(timeId);
|
|
8251
8284
|
}
|
|
8252
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8253
|
-
}
|
|
8254
|
-
catch (error) {
|
|
8255
|
-
// console.log(error);
|
|
8256
8285
|
}
|
|
8257
|
-
|
|
8286
|
+
catch {
|
|
8258
8287
|
this.windowApi.clearInterval(timeId);
|
|
8259
8288
|
}
|
|
8260
8289
|
}
|
|
@@ -8275,6 +8304,66 @@ class Utils {
|
|
|
8275
8304
|
return new FunctionConstructor(...args);
|
|
8276
8305
|
}
|
|
8277
8306
|
}
|
|
8307
|
+
/**
|
|
8308
|
+
* 判断页面中是否存在`worker-src`的CSP规则
|
|
8309
|
+
*/
|
|
8310
|
+
hasWorkerCSP() {
|
|
8311
|
+
return new Promise((resolve) => {
|
|
8312
|
+
let flag = true;
|
|
8313
|
+
let workerBlobUrl = void 0;
|
|
8314
|
+
const workerJs = /*js*/ `
|
|
8315
|
+
(() => {
|
|
8316
|
+
this.addEventListener(
|
|
8317
|
+
"message",
|
|
8318
|
+
function () {
|
|
8319
|
+
this.postMessage({
|
|
8320
|
+
success: true,
|
|
8321
|
+
});
|
|
8322
|
+
},
|
|
8323
|
+
{
|
|
8324
|
+
capture: true,
|
|
8325
|
+
}
|
|
8326
|
+
);
|
|
8327
|
+
})();`;
|
|
8328
|
+
try {
|
|
8329
|
+
const workerScript = new Blob([workerJs], {
|
|
8330
|
+
type: "application/javascript",
|
|
8331
|
+
});
|
|
8332
|
+
workerBlobUrl = window.URL.createObjectURL(workerScript);
|
|
8333
|
+
// @ts-expect-error
|
|
8334
|
+
if (globalThis.trustedTypes && typeof globalThis.trustedTypes.createPolicy === "function") {
|
|
8335
|
+
// 使用这个后虽然不报错,但是仍会有blob错误
|
|
8336
|
+
// violates the following Content Security Policy directive: "worker-src 'self'". The action has been blocked.
|
|
8337
|
+
// 且这个错误无法使用try/catch捕捉,导致本该提醒使用手动匹配的结果并无提醒弹窗
|
|
8338
|
+
// @ts-expect-error
|
|
8339
|
+
const workerPolicy = globalThis.trustedTypes.createPolicy("workerPolicy", {
|
|
8340
|
+
createScriptURL: (url) => url,
|
|
8341
|
+
});
|
|
8342
|
+
workerBlobUrl = workerPolicy.createScriptURL(workerBlobUrl);
|
|
8343
|
+
}
|
|
8344
|
+
const worker = new Worker(workerBlobUrl);
|
|
8345
|
+
worker.onmessage = (data) => {
|
|
8346
|
+
if (data.data.success) {
|
|
8347
|
+
flag = false;
|
|
8348
|
+
}
|
|
8349
|
+
};
|
|
8350
|
+
setTimeout(() => {
|
|
8351
|
+
worker.terminate();
|
|
8352
|
+
resolve(flag);
|
|
8353
|
+
}, 500);
|
|
8354
|
+
worker.postMessage("test");
|
|
8355
|
+
}
|
|
8356
|
+
catch {
|
|
8357
|
+
flag = true;
|
|
8358
|
+
}
|
|
8359
|
+
finally {
|
|
8360
|
+
// 释放
|
|
8361
|
+
if (typeof workerBlobUrl === "string") {
|
|
8362
|
+
globalThis.URL.revokeObjectURL(workerBlobUrl);
|
|
8363
|
+
}
|
|
8364
|
+
}
|
|
8365
|
+
});
|
|
8366
|
+
}
|
|
8278
8367
|
}
|
|
8279
8368
|
const utils = new Utils();
|
|
8280
8369
|
|