@whitesev/utils 2.6.8 → 2.7.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/dist/index.amd.js +1173 -901
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +1173 -901
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1173 -901
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +1173 -901
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +1173 -901
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +1173 -901
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/CommonUtil.d.ts +109 -0
- package/dist/types/src/DOMUtils.d.ts +95 -0
- package/dist/types/src/Utils.d.ts +14 -10
- package/dist/types/src/ajaxHooker/ajaxHooker.d.ts +1 -1
- package/package.json +11 -8
- package/src/CommonUtil.ts +302 -0
- package/src/DOMUtils.ts +287 -0
- package/src/Dictionary.ts +2 -2
- package/src/Hooks.ts +11 -12
- package/src/Httpx.ts +22 -16
- package/src/LockFunction.ts +4 -7
- package/src/Progress.ts +2 -2
- package/src/TryCatch.ts +6 -9
- package/src/Utils.ts +23 -216
- package/src/UtilsGMCookie.ts +7 -7
- package/src/UtilsGMMenu.ts +2 -2
- package/src/ajaxHooker/ajaxHooker.js +536 -554
package/dist/index.system.js
CHANGED
|
@@ -229,6 +229,273 @@ System.register('Utils', [], (function (exports) {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
const TryCatch = function (...args) {
|
|
233
|
+
/* 定义变量和函数 */
|
|
234
|
+
let callbackFunction = null;
|
|
235
|
+
let context = null;
|
|
236
|
+
let handleError = (error) => { };
|
|
237
|
+
let defaultDetails = {
|
|
238
|
+
log: true,
|
|
239
|
+
};
|
|
240
|
+
const TryCatchCore = {
|
|
241
|
+
/**
|
|
242
|
+
*
|
|
243
|
+
* @param paramDetails 配置
|
|
244
|
+
* @returns
|
|
245
|
+
*/
|
|
246
|
+
config(paramDetails) {
|
|
247
|
+
defaultDetails = Object.assign(defaultDetails, paramDetails);
|
|
248
|
+
return TryCatchCore;
|
|
249
|
+
},
|
|
250
|
+
/**
|
|
251
|
+
* 处理错误
|
|
252
|
+
* @param handler
|
|
253
|
+
*/
|
|
254
|
+
error(handler) {
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
handleError = handler;
|
|
257
|
+
return TryCatchCore;
|
|
258
|
+
},
|
|
259
|
+
/**
|
|
260
|
+
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
261
|
+
* @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
262
|
+
* @param __context__ 待执行函数的作用域,用于apply指定
|
|
263
|
+
* @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
|
|
264
|
+
* @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
|
|
265
|
+
*/
|
|
266
|
+
run(callback, __context__) {
|
|
267
|
+
callbackFunction = callback;
|
|
268
|
+
context = __context__ || this;
|
|
269
|
+
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
270
|
+
// @ts-ignore
|
|
271
|
+
return result !== void 0 ? result : TryCatchCore;
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
276
|
+
* @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
277
|
+
* @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
278
|
+
* @param funcThis - 待执行函数的作用域,用于apply指定
|
|
279
|
+
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
280
|
+
*/
|
|
281
|
+
function executeTryCatch(callback, handleErrorFunc, funcThis) {
|
|
282
|
+
let result = void 0;
|
|
283
|
+
try {
|
|
284
|
+
if (typeof callback === "string") {
|
|
285
|
+
result = new Function(callback).apply(funcThis, args);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
result = callback.apply(funcThis, args);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
if (defaultDetails.log) {
|
|
293
|
+
callback = callback;
|
|
294
|
+
console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
|
|
295
|
+
console.log(`%c 错误原因:${error}`, "color: #f20000");
|
|
296
|
+
console.trace(callback);
|
|
297
|
+
}
|
|
298
|
+
if (handleErrorFunc) {
|
|
299
|
+
if (typeof handleErrorFunc === "string") {
|
|
300
|
+
result = new Function(handleErrorFunc).apply(funcThis, [
|
|
301
|
+
...args,
|
|
302
|
+
error,
|
|
303
|
+
]);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
result = handleErrorFunc.apply(funcThis, [...args, error]);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
return TryCatchCore;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
class CommonUtil {
|
|
316
|
+
assign(target = {}, source = {}, isAdd = false) {
|
|
317
|
+
let UtilsContext = this;
|
|
318
|
+
if (Array.isArray(source)) {
|
|
319
|
+
let canTraverse = source.filter((item) => {
|
|
320
|
+
return typeof item === "object";
|
|
321
|
+
});
|
|
322
|
+
if (!canTraverse.length) {
|
|
323
|
+
return source;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (source == null) {
|
|
327
|
+
return target;
|
|
328
|
+
}
|
|
329
|
+
if (target == null) {
|
|
330
|
+
target = {};
|
|
331
|
+
}
|
|
332
|
+
if (isAdd) {
|
|
333
|
+
for (const sourceKeyName in source) {
|
|
334
|
+
const targetKeyName = sourceKeyName;
|
|
335
|
+
let targetValue = target[targetKeyName];
|
|
336
|
+
let sourceValue = source[sourceKeyName];
|
|
337
|
+
if (typeof sourceValue === "object" &&
|
|
338
|
+
sourceValue != null &&
|
|
339
|
+
sourceKeyName in target &&
|
|
340
|
+
!UtilsContext.isDOM(sourceValue)) {
|
|
341
|
+
/* 源端的值是object类型,且不是元素节点 */
|
|
342
|
+
target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
target[sourceKeyName] = sourceValue;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
for (const targetKeyName in target) {
|
|
350
|
+
if (targetKeyName in source) {
|
|
351
|
+
let targetValue = target[targetKeyName];
|
|
352
|
+
let sourceValue = source[targetKeyName];
|
|
353
|
+
if (typeof sourceValue === "object" &&
|
|
354
|
+
sourceValue != null &&
|
|
355
|
+
!UtilsContext.isDOM(sourceValue) &&
|
|
356
|
+
Object.keys(sourceValue).length) {
|
|
357
|
+
/* 源端的值是object类型,且不是元素节点 */
|
|
358
|
+
target[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
/* 直接赋值 */
|
|
362
|
+
target[targetKeyName] = sourceValue;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return target;
|
|
367
|
+
}
|
|
368
|
+
isNull(...args) {
|
|
369
|
+
let result = true;
|
|
370
|
+
let checkList = [...args];
|
|
371
|
+
for (const objItem of checkList) {
|
|
372
|
+
let itemResult = false;
|
|
373
|
+
if (objItem === null || objItem === undefined) {
|
|
374
|
+
itemResult = true;
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
switch (typeof objItem) {
|
|
378
|
+
case "object":
|
|
379
|
+
if (typeof objItem[Symbol.iterator] === "function") {
|
|
380
|
+
/* 可迭代 */
|
|
381
|
+
itemResult = objItem.length === 0;
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
itemResult = Object.keys(objItem).length === 0;
|
|
385
|
+
}
|
|
386
|
+
break;
|
|
387
|
+
case "number":
|
|
388
|
+
itemResult = objItem === 0;
|
|
389
|
+
break;
|
|
390
|
+
case "string":
|
|
391
|
+
itemResult =
|
|
392
|
+
objItem.trim() === "" ||
|
|
393
|
+
objItem === "null" ||
|
|
394
|
+
objItem === "undefined";
|
|
395
|
+
break;
|
|
396
|
+
case "boolean":
|
|
397
|
+
itemResult = !objItem;
|
|
398
|
+
break;
|
|
399
|
+
case "function":
|
|
400
|
+
let funcStr = objItem.toString().replace(/\s/g, "");
|
|
401
|
+
/* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
|
|
402
|
+
itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
result = result && itemResult;
|
|
407
|
+
}
|
|
408
|
+
return result;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 判断对象是否是元素
|
|
412
|
+
* @param target
|
|
413
|
+
* @returns
|
|
414
|
+
* + true 是元素
|
|
415
|
+
* + false 不是元素
|
|
416
|
+
* @example
|
|
417
|
+
* Utils.isDOM(document.querySelector("a"))
|
|
418
|
+
* > true
|
|
419
|
+
*/
|
|
420
|
+
isDOM(target) {
|
|
421
|
+
return target instanceof Node;
|
|
422
|
+
}
|
|
423
|
+
isNotNull(...args) {
|
|
424
|
+
let UtilsContext = this;
|
|
425
|
+
return !UtilsContext.isNull.apply(this, args);
|
|
426
|
+
}
|
|
427
|
+
deepClone(obj) {
|
|
428
|
+
let UtilsContext = this;
|
|
429
|
+
if (obj === void 0)
|
|
430
|
+
return void 0;
|
|
431
|
+
if (obj === null)
|
|
432
|
+
return null;
|
|
433
|
+
let clone = obj instanceof Array ? [] : {};
|
|
434
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
435
|
+
clone[key] =
|
|
436
|
+
typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
437
|
+
}
|
|
438
|
+
return clone;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* 覆盖对象中的函数this指向
|
|
442
|
+
* @param target 需要覆盖的对象
|
|
443
|
+
* @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
|
|
444
|
+
*/
|
|
445
|
+
coverObjectFunctionThis(target, objectThis) {
|
|
446
|
+
if (typeof target !== "object" || target === null) {
|
|
447
|
+
throw new Error("target must be object");
|
|
448
|
+
}
|
|
449
|
+
objectThis = objectThis || target;
|
|
450
|
+
Object.keys(target).forEach((key) => {
|
|
451
|
+
if (typeof target[key] === "function") {
|
|
452
|
+
target[key] = target[key].bind(objectThis);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
toJSON(data, errorCallBack) {
|
|
457
|
+
let result = {};
|
|
458
|
+
if (typeof data === "object") {
|
|
459
|
+
return data;
|
|
460
|
+
}
|
|
461
|
+
TryCatch()
|
|
462
|
+
.config({ log: false })
|
|
463
|
+
.error((error) => {
|
|
464
|
+
TryCatch()
|
|
465
|
+
.error(() => {
|
|
466
|
+
try {
|
|
467
|
+
result = new Function("return " + data)();
|
|
468
|
+
}
|
|
469
|
+
catch (error2) {
|
|
470
|
+
if (typeof errorCallBack === "function") {
|
|
471
|
+
errorCallBack(error2);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
})
|
|
475
|
+
.run(() => {
|
|
476
|
+
if (data &&
|
|
477
|
+
/^[\],:{}\s]*$/.test(data
|
|
478
|
+
.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
|
|
479
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
|
|
480
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
|
|
481
|
+
result = new Function("return " + data)();
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
if (typeof errorCallBack === "function") {
|
|
485
|
+
errorCallBack(new Error("target is not a JSON"));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
})
|
|
490
|
+
.run(() => {
|
|
491
|
+
data = data.trim();
|
|
492
|
+
result = JSON.parse(data);
|
|
493
|
+
});
|
|
494
|
+
return result;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
let commonUtil = new CommonUtil();
|
|
498
|
+
|
|
232
499
|
class UtilsGMCookie {
|
|
233
500
|
windowApi = {
|
|
234
501
|
window: window,
|
|
@@ -257,7 +524,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
257
524
|
throw new TypeError("Utils.GMCookie.get 参数cookieName 必须为字符串");
|
|
258
525
|
}
|
|
259
526
|
let cookies = this.getCookiesList();
|
|
260
|
-
let findValue =
|
|
527
|
+
let findValue = void 0;
|
|
261
528
|
for (const cookieItem of cookies) {
|
|
262
529
|
let item = cookieItem.trim();
|
|
263
530
|
let itemSplit = item.split("=");
|
|
@@ -301,7 +568,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
301
568
|
name: "",
|
|
302
569
|
path: "/",
|
|
303
570
|
};
|
|
304
|
-
defaultOption =
|
|
571
|
+
defaultOption = commonUtil.assign(defaultOption, option);
|
|
305
572
|
let cookies = this.getCookiesList();
|
|
306
573
|
cookies.forEach((item) => {
|
|
307
574
|
item = item.trim();
|
|
@@ -352,7 +619,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
352
619
|
name: "",
|
|
353
620
|
path: "/",
|
|
354
621
|
};
|
|
355
|
-
defaultOption =
|
|
622
|
+
defaultOption = commonUtil.assign(defaultOption, option);
|
|
356
623
|
let cookies = this.getCookiesList();
|
|
357
624
|
cookies.forEach((item) => {
|
|
358
625
|
item = item.trim();
|
|
@@ -401,7 +668,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
401
668
|
*/
|
|
402
669
|
expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
|
|
403
670
|
};
|
|
404
|
-
defaultOption =
|
|
671
|
+
defaultOption = commonUtil.assign(defaultOption, option);
|
|
405
672
|
let life = defaultOption.expirationDate
|
|
406
673
|
? defaultOption.expirationDate
|
|
407
674
|
: Math.floor(Date.now()) + 60 * 60 * 24 * 30;
|
|
@@ -411,7 +678,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
411
678
|
";expires=" +
|
|
412
679
|
new Date(life).toGMTString() +
|
|
413
680
|
"; path=/";
|
|
414
|
-
if (
|
|
681
|
+
if (commonUtil.isNull(defaultOption.domain)) {
|
|
415
682
|
cookieStr += "; domain=" + defaultOption.domain;
|
|
416
683
|
}
|
|
417
684
|
this.windowApi.document.cookie = cookieStr;
|
|
@@ -439,9 +706,9 @@ System.register('Utils', [], (function (exports) {
|
|
|
439
706
|
path: "/",
|
|
440
707
|
firstPartyDomain: "",
|
|
441
708
|
};
|
|
442
|
-
defaultOption =
|
|
709
|
+
defaultOption = commonUtil.assign(defaultOption, option);
|
|
443
710
|
let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}`;
|
|
444
|
-
if (
|
|
711
|
+
if (commonUtil.isNull(defaultOption.firstPartyDomain)) {
|
|
445
712
|
cookieStr += `; domain=${defaultOption.firstPartyDomain};`;
|
|
446
713
|
}
|
|
447
714
|
this.windowApi.document.cookie = cookieStr;
|
|
@@ -481,189 +748,189 @@ System.register('Utils', [], (function (exports) {
|
|
|
481
748
|
}
|
|
482
749
|
}
|
|
483
750
|
|
|
751
|
+
// ==UserScript==
|
|
484
752
|
// @name ajaxHooker
|
|
485
753
|
// @author cxxjackie
|
|
486
|
-
// @version 1.4.
|
|
487
|
-
// @updateLog 修复头条、抖音部分站点下this引用错误的问题。
|
|
754
|
+
// @version 1.4.6
|
|
488
755
|
// @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
756
|
+
// @license GNU LGPL-3.0
|
|
757
|
+
// ==/UserScript==
|
|
489
758
|
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
console.error(err);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
function defineProp(obj, prop, getter, setter) {
|
|
539
|
-
Object.defineProperty(obj, prop, {
|
|
540
|
-
configurable: true,
|
|
541
|
-
enumerable: true,
|
|
542
|
-
get: getter,
|
|
543
|
-
set: setter,
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
function readonly(obj, prop, value = obj[prop]) {
|
|
547
|
-
defineProp(obj, prop, () => value, emptyFn);
|
|
548
|
-
}
|
|
549
|
-
function writable(obj, prop, value = obj[prop]) {
|
|
550
|
-
Object.defineProperty(obj, prop, {
|
|
551
|
-
configurable: true,
|
|
552
|
-
enumerable: true,
|
|
553
|
-
writable: true,
|
|
554
|
-
value: value,
|
|
555
|
-
});
|
|
759
|
+
const ajaxHooker = function () {
|
|
760
|
+
const version = "1.4.6";
|
|
761
|
+
const hookInst = {
|
|
762
|
+
hookFns: [],
|
|
763
|
+
filters: [],
|
|
764
|
+
};
|
|
765
|
+
const win = window.unsafeWindow || document.defaultView || window;
|
|
766
|
+
let winAh = win.__ajaxHooker;
|
|
767
|
+
const resProto = win.Response.prototype;
|
|
768
|
+
const xhrResponses = ["response", "responseText", "responseXML"];
|
|
769
|
+
const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
|
|
770
|
+
const fetchInitProps = [
|
|
771
|
+
"method",
|
|
772
|
+
"headers",
|
|
773
|
+
"body",
|
|
774
|
+
"mode",
|
|
775
|
+
"credentials",
|
|
776
|
+
"cache",
|
|
777
|
+
"redirect",
|
|
778
|
+
"referrer",
|
|
779
|
+
"referrerPolicy",
|
|
780
|
+
"integrity",
|
|
781
|
+
"keepalive",
|
|
782
|
+
"signal",
|
|
783
|
+
"priority",
|
|
784
|
+
];
|
|
785
|
+
const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
|
|
786
|
+
const getType = {}.toString.call.bind({}.toString);
|
|
787
|
+
const getDescriptor = Object.getOwnPropertyDescriptor.bind(Object);
|
|
788
|
+
const emptyFn = () => {};
|
|
789
|
+
const errorFn = (e) => console.error(e);
|
|
790
|
+
function isThenable(obj) {
|
|
791
|
+
return (
|
|
792
|
+
obj &&
|
|
793
|
+
["object", "function"].includes(typeof obj) &&
|
|
794
|
+
typeof obj.then === "function"
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
function catchError(fn, ...args) {
|
|
798
|
+
try {
|
|
799
|
+
const result = fn(...args);
|
|
800
|
+
if (isThenable(result)) return result.then(null, errorFn);
|
|
801
|
+
return result;
|
|
802
|
+
} catch (err) {
|
|
803
|
+
console.error(err);
|
|
556
804
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
805
|
+
}
|
|
806
|
+
function defineProp(obj, prop, getter, setter) {
|
|
807
|
+
Object.defineProperty(obj, prop, {
|
|
808
|
+
configurable: true,
|
|
809
|
+
enumerable: true,
|
|
810
|
+
get: getter,
|
|
811
|
+
set: setter,
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
function readonly(obj, prop, value = obj[prop]) {
|
|
815
|
+
defineProp(obj, prop, () => value, emptyFn);
|
|
816
|
+
}
|
|
817
|
+
function writable(obj, prop, value = obj[prop]) {
|
|
818
|
+
Object.defineProperty(obj, prop, {
|
|
819
|
+
configurable: true,
|
|
820
|
+
enumerable: true,
|
|
821
|
+
writable: true,
|
|
822
|
+
value: value,
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
function parseHeaders(obj) {
|
|
826
|
+
const headers = {};
|
|
827
|
+
switch (getType(obj)) {
|
|
828
|
+
case "[object String]":
|
|
829
|
+
for (const line of obj.trim().split(/[\r\n]+/)) {
|
|
830
|
+
const [header, value] = line.split(/(?<=^[^:]+)\s*:\s*/);
|
|
831
|
+
if (!value) continue;
|
|
832
|
+
const lheader = header.toLowerCase();
|
|
833
|
+
headers[lheader] =
|
|
834
|
+
lheader in headers ? `${headers[lheader]}, ${value}` : value;
|
|
835
|
+
}
|
|
836
|
+
break;
|
|
837
|
+
case "[object Headers]":
|
|
838
|
+
for (const [key, val] of obj) {
|
|
839
|
+
headers[key] = val;
|
|
840
|
+
}
|
|
841
|
+
break;
|
|
842
|
+
case "[object Object]":
|
|
843
|
+
return { ...obj };
|
|
844
|
+
}
|
|
845
|
+
return headers;
|
|
846
|
+
}
|
|
847
|
+
function stopImmediatePropagation() {
|
|
848
|
+
this.ajaxHooker_isStopped = true;
|
|
849
|
+
}
|
|
850
|
+
class SyncThenable {
|
|
851
|
+
then(fn) {
|
|
852
|
+
fn && fn();
|
|
853
|
+
return new SyncThenable();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
class AHRequest {
|
|
857
|
+
constructor(request) {
|
|
858
|
+
this.request = request;
|
|
859
|
+
this.requestClone = { ...this.request };
|
|
578
860
|
}
|
|
579
|
-
|
|
580
|
-
|
|
861
|
+
shouldFilter(filters) {
|
|
862
|
+
const { type, url, method, async } = this.request;
|
|
863
|
+
return (
|
|
864
|
+
filters.length &&
|
|
865
|
+
!filters.find((obj) => {
|
|
866
|
+
switch (true) {
|
|
867
|
+
case obj.type && obj.type !== type:
|
|
868
|
+
case getType(obj.url) === "[object String]" &&
|
|
869
|
+
!url.includes(obj.url):
|
|
870
|
+
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
871
|
+
case obj.method &&
|
|
872
|
+
obj.method.toUpperCase() !== method.toUpperCase():
|
|
873
|
+
case "async" in obj && obj.async !== async:
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
return true;
|
|
877
|
+
})
|
|
878
|
+
);
|
|
581
879
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
880
|
+
waitForRequestKeys() {
|
|
881
|
+
const requestKeys = ["url", "method", "abort", "headers", "data"];
|
|
882
|
+
if (!this.request.async) {
|
|
883
|
+
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
884
|
+
if (this.shouldFilter(filters)) return;
|
|
885
|
+
hookFns.forEach((fn) => {
|
|
886
|
+
if (getType(fn) === "[object Function]")
|
|
887
|
+
catchError(fn, this.request);
|
|
888
|
+
});
|
|
889
|
+
requestKeys.forEach((key) => {
|
|
890
|
+
if (isThenable(this.request[key]))
|
|
891
|
+
this.request[key] = this.requestClone[key];
|
|
892
|
+
});
|
|
893
|
+
});
|
|
585
894
|
return new SyncThenable();
|
|
586
895
|
}
|
|
896
|
+
const promises = [];
|
|
897
|
+
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
898
|
+
if (this.shouldFilter(filters)) return;
|
|
899
|
+
promises.push(
|
|
900
|
+
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
901
|
+
() =>
|
|
902
|
+
Promise.all(
|
|
903
|
+
requestKeys.map((key) =>
|
|
904
|
+
Promise.resolve(this.request[key]).then(
|
|
905
|
+
(val) => (this.request[key] = val),
|
|
906
|
+
() => (this.request[key] = this.requestClone[key])
|
|
907
|
+
)
|
|
908
|
+
)
|
|
909
|
+
)
|
|
910
|
+
)
|
|
911
|
+
);
|
|
912
|
+
});
|
|
913
|
+
return Promise.all(promises);
|
|
587
914
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
this.request
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
case getType(obj.url) === "[object String]" &&
|
|
601
|
-
!url.includes(obj.url):
|
|
602
|
-
case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
|
|
603
|
-
case obj.method &&
|
|
604
|
-
obj.method.toUpperCase() !== method.toUpperCase():
|
|
605
|
-
case "async" in obj && obj.async !== async:
|
|
606
|
-
return false;
|
|
915
|
+
waitForResponseKeys(response) {
|
|
916
|
+
const responseKeys =
|
|
917
|
+
this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
918
|
+
if (!this.request.async) {
|
|
919
|
+
if (getType(this.request.response) === "[object Function]") {
|
|
920
|
+
catchError(this.request.response, response);
|
|
921
|
+
responseKeys.forEach((key) => {
|
|
922
|
+
if (
|
|
923
|
+
"get" in getDescriptor(response, key) ||
|
|
924
|
+
isThenable(response[key])
|
|
925
|
+
) {
|
|
926
|
+
delete response[key];
|
|
607
927
|
}
|
|
608
|
-
return true;
|
|
609
|
-
})
|
|
610
|
-
);
|
|
611
|
-
}
|
|
612
|
-
waitForRequestKeys() {
|
|
613
|
-
const requestKeys = ["url", "method", "abort", "headers", "data"];
|
|
614
|
-
if (!this.request.async) {
|
|
615
|
-
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
616
|
-
if (this.shouldFilter(filters)) return;
|
|
617
|
-
hookFns.forEach((fn) => {
|
|
618
|
-
if (getType(fn) === "[object Function]")
|
|
619
|
-
catchError(fn, this.request);
|
|
620
|
-
});
|
|
621
|
-
requestKeys.forEach((key) => {
|
|
622
|
-
if (isThenable(this.request[key]))
|
|
623
|
-
this.request[key] = this.requestClone[key];
|
|
624
|
-
});
|
|
625
928
|
});
|
|
626
|
-
return new SyncThenable();
|
|
627
929
|
}
|
|
628
|
-
|
|
629
|
-
win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
|
|
630
|
-
if (this.shouldFilter(filters)) return;
|
|
631
|
-
promises.push(
|
|
632
|
-
Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
|
|
633
|
-
() =>
|
|
634
|
-
Promise.all(
|
|
635
|
-
requestKeys.map((key) =>
|
|
636
|
-
Promise.resolve(this.request[key]).then(
|
|
637
|
-
(val) => (this.request[key] = val),
|
|
638
|
-
() => (this.request[key] = this.requestClone[key])
|
|
639
|
-
)
|
|
640
|
-
)
|
|
641
|
-
)
|
|
642
|
-
)
|
|
643
|
-
);
|
|
644
|
-
});
|
|
645
|
-
return Promise.all(promises);
|
|
930
|
+
return new SyncThenable();
|
|
646
931
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
this.request.type === "xhr" ? xhrResponses : fetchResponses;
|
|
650
|
-
if (!this.request.async) {
|
|
651
|
-
if (getType(this.request.response) === "[object Function]") {
|
|
652
|
-
catchError(this.request.response, response);
|
|
653
|
-
responseKeys.forEach((key) => {
|
|
654
|
-
if (
|
|
655
|
-
"get" in getDescriptor(response, key) ||
|
|
656
|
-
isThenable(response[key])
|
|
657
|
-
) {
|
|
658
|
-
delete response[key];
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
return new SyncThenable();
|
|
663
|
-
}
|
|
664
|
-
return Promise.resolve(
|
|
665
|
-
catchError(this.request.response, response)
|
|
666
|
-
).then(() =>
|
|
932
|
+
return Promise.resolve(catchError(this.request.response, response)).then(
|
|
933
|
+
() =>
|
|
667
934
|
Promise.all(
|
|
668
935
|
responseKeys.map((key) => {
|
|
669
936
|
const descriptor = getDescriptor(response, key);
|
|
@@ -677,424 +944,406 @@ System.register('Utils', [], (function (exports) {
|
|
|
677
944
|
}
|
|
678
945
|
})
|
|
679
946
|
)
|
|
680
|
-
|
|
681
|
-
}
|
|
947
|
+
);
|
|
682
948
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
const ah = target.__ajaxHooker;
|
|
694
|
-
if (ah && ah.proxyProps) {
|
|
695
|
-
if (prop in ah.proxyProps) {
|
|
696
|
-
const pDescriptor = ah.proxyProps[prop];
|
|
697
|
-
if ("get" in pDescriptor) return pDescriptor.get();
|
|
698
|
-
if (typeof pDescriptor.value === "function")
|
|
699
|
-
return pDescriptor.value.bind(ah);
|
|
700
|
-
return pDescriptor.value;
|
|
701
|
-
}
|
|
702
|
-
if (typeof target[prop] === "function")
|
|
703
|
-
return target[prop].bind(target);
|
|
704
|
-
}
|
|
949
|
+
}
|
|
950
|
+
const proxyHandler = {
|
|
951
|
+
get(target, prop) {
|
|
952
|
+
const descriptor = getDescriptor(target, prop);
|
|
953
|
+
if (
|
|
954
|
+
descriptor &&
|
|
955
|
+
!descriptor.configurable &&
|
|
956
|
+
!descriptor.writable &&
|
|
957
|
+
!descriptor.get
|
|
958
|
+
)
|
|
705
959
|
return target[prop];
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
if (
|
|
710
|
-
descriptor &&
|
|
711
|
-
!descriptor.configurable &&
|
|
712
|
-
!descriptor.writable &&
|
|
713
|
-
!descriptor.set
|
|
714
|
-
)
|
|
715
|
-
return true;
|
|
716
|
-
const ah = target.__ajaxHooker;
|
|
717
|
-
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
960
|
+
const ah = target.__ajaxHooker;
|
|
961
|
+
if (ah && ah.proxyProps) {
|
|
962
|
+
if (prop in ah.proxyProps) {
|
|
718
963
|
const pDescriptor = ah.proxyProps[prop];
|
|
719
|
-
pDescriptor.
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
target[prop] = value;
|
|
724
|
-
}
|
|
725
|
-
return true;
|
|
726
|
-
},
|
|
727
|
-
};
|
|
728
|
-
class XhrHooker {
|
|
729
|
-
constructor(xhr) {
|
|
730
|
-
const ah = this;
|
|
731
|
-
Object.assign(ah, {
|
|
732
|
-
originalXhr: xhr,
|
|
733
|
-
proxyXhr: new Proxy(xhr, proxyHandler),
|
|
734
|
-
resThenable: new SyncThenable(),
|
|
735
|
-
proxyProps: {},
|
|
736
|
-
proxyEvents: {},
|
|
737
|
-
});
|
|
738
|
-
xhr.addEventListener("readystatechange", (e) => {
|
|
739
|
-
if (
|
|
740
|
-
ah.proxyXhr.readyState === 4 &&
|
|
741
|
-
ah.request &&
|
|
742
|
-
typeof ah.request.response === "function"
|
|
743
|
-
) {
|
|
744
|
-
const response = {
|
|
745
|
-
finalUrl: ah.proxyXhr.responseURL,
|
|
746
|
-
status: ah.proxyXhr.status,
|
|
747
|
-
responseHeaders: parseHeaders(
|
|
748
|
-
ah.proxyXhr.getAllResponseHeaders()
|
|
749
|
-
),
|
|
750
|
-
};
|
|
751
|
-
const tempValues = {};
|
|
752
|
-
for (const key of xhrResponses) {
|
|
753
|
-
try {
|
|
754
|
-
tempValues[key] = ah.originalXhr[key];
|
|
755
|
-
} catch (err) {}
|
|
756
|
-
defineProp(
|
|
757
|
-
response,
|
|
758
|
-
key,
|
|
759
|
-
() => {
|
|
760
|
-
return (response[key] = tempValues[key]);
|
|
761
|
-
},
|
|
762
|
-
(val) => {
|
|
763
|
-
delete response[key];
|
|
764
|
-
response[key] = val;
|
|
765
|
-
}
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
ah.resThenable = new AHRequest(ah.request)
|
|
769
|
-
.waitForResponseKeys(response)
|
|
770
|
-
.then(() => {
|
|
771
|
-
for (const key of xhrResponses) {
|
|
772
|
-
ah.proxyProps[key] = {
|
|
773
|
-
get: () => {
|
|
774
|
-
if (!(key in response)) response[key] = tempValues[key];
|
|
775
|
-
return response[key];
|
|
776
|
-
},
|
|
777
|
-
};
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
ah.dispatchEvent(e);
|
|
782
|
-
});
|
|
783
|
-
xhr.addEventListener("load", (e) => ah.dispatchEvent(e));
|
|
784
|
-
xhr.addEventListener("loadend", (e) => ah.dispatchEvent(e));
|
|
785
|
-
for (const evt of xhrAsyncEvents) {
|
|
786
|
-
const onEvt = "on" + evt;
|
|
787
|
-
ah.proxyProps[onEvt] = {
|
|
788
|
-
get: () => ah.proxyEvents[onEvt] || null,
|
|
789
|
-
set: (val) => ah.addEvent(onEvt, val),
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
for (const method of [
|
|
793
|
-
"setRequestHeader",
|
|
794
|
-
"addEventListener",
|
|
795
|
-
"removeEventListener",
|
|
796
|
-
"open",
|
|
797
|
-
"send",
|
|
798
|
-
]) {
|
|
799
|
-
ah.proxyProps[method] = { value: ah[method] };
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
toJSON() {} // Converting circular structure to JSON
|
|
803
|
-
addEvent(type, event) {
|
|
804
|
-
if (type.startsWith("on")) {
|
|
805
|
-
this.proxyEvents[type] = typeof event === "function" ? event : null;
|
|
806
|
-
} else {
|
|
807
|
-
if (typeof event === "object" && event !== null)
|
|
808
|
-
event = event.handleEvent;
|
|
809
|
-
if (typeof event !== "function") return;
|
|
810
|
-
this.proxyEvents[type] = this.proxyEvents[type] || new Set();
|
|
811
|
-
this.proxyEvents[type].add(event);
|
|
964
|
+
if ("get" in pDescriptor) return pDescriptor.get();
|
|
965
|
+
if (typeof pDescriptor.value === "function")
|
|
966
|
+
return pDescriptor.value.bind(ah);
|
|
967
|
+
return pDescriptor.value;
|
|
812
968
|
}
|
|
969
|
+
if (typeof target[prop] === "function")
|
|
970
|
+
return target[prop].bind(target);
|
|
813
971
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
972
|
+
return target[prop];
|
|
973
|
+
},
|
|
974
|
+
set(target, prop, value) {
|
|
975
|
+
const descriptor = getDescriptor(target, prop);
|
|
976
|
+
if (
|
|
977
|
+
descriptor &&
|
|
978
|
+
!descriptor.configurable &&
|
|
979
|
+
!descriptor.writable &&
|
|
980
|
+
!descriptor.set
|
|
981
|
+
)
|
|
982
|
+
return true;
|
|
983
|
+
const ah = target.__ajaxHooker;
|
|
984
|
+
if (ah && ah.proxyProps && prop in ah.proxyProps) {
|
|
985
|
+
const pDescriptor = ah.proxyProps[prop];
|
|
986
|
+
pDescriptor.set ? pDescriptor.set(value) : (pDescriptor.value = value);
|
|
987
|
+
} else {
|
|
988
|
+
target[prop] = value;
|
|
822
989
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
990
|
+
return true;
|
|
991
|
+
},
|
|
992
|
+
};
|
|
993
|
+
class XhrHooker {
|
|
994
|
+
constructor(xhr) {
|
|
995
|
+
const ah = this;
|
|
996
|
+
Object.assign(ah, {
|
|
997
|
+
originalXhr: xhr,
|
|
998
|
+
proxyXhr: new Proxy(xhr, proxyHandler),
|
|
999
|
+
resThenable: new SyncThenable(),
|
|
1000
|
+
proxyProps: {},
|
|
1001
|
+
proxyEvents: {},
|
|
1002
|
+
});
|
|
1003
|
+
xhr.addEventListener("readystatechange", (e) => {
|
|
1004
|
+
if (
|
|
1005
|
+
ah.proxyXhr.readyState === 4 &&
|
|
1006
|
+
ah.request &&
|
|
1007
|
+
typeof ah.request.response === "function"
|
|
1008
|
+
) {
|
|
1009
|
+
const response = {
|
|
1010
|
+
finalUrl: ah.proxyXhr.responseURL,
|
|
1011
|
+
status: ah.proxyXhr.status,
|
|
1012
|
+
responseHeaders: parseHeaders(ah.proxyXhr.getAllResponseHeaders()),
|
|
1013
|
+
};
|
|
1014
|
+
const tempValues = {};
|
|
1015
|
+
for (const key of xhrResponses) {
|
|
1016
|
+
try {
|
|
1017
|
+
tempValues[key] = ah.originalXhr[key];
|
|
1018
|
+
} catch (err) {}
|
|
1019
|
+
defineProp(
|
|
1020
|
+
response,
|
|
1021
|
+
key,
|
|
1022
|
+
() => {
|
|
1023
|
+
return (response[key] = tempValues[key]);
|
|
1024
|
+
},
|
|
1025
|
+
(val) => {
|
|
1026
|
+
delete response[key];
|
|
1027
|
+
response[key] = val;
|
|
1028
|
+
}
|
|
831
1029
|
);
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
1030
|
+
}
|
|
1031
|
+
ah.resThenable = new AHRequest(ah.request)
|
|
1032
|
+
.waitForResponseKeys(response)
|
|
1033
|
+
.then(() => {
|
|
1034
|
+
for (const key of xhrResponses) {
|
|
1035
|
+
ah.proxyProps[key] = {
|
|
1036
|
+
get: () => {
|
|
1037
|
+
if (!(key in response)) response[key] = tempValues[key];
|
|
1038
|
+
return response[key];
|
|
1039
|
+
},
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
ah.dispatchEvent(e);
|
|
1045
|
+
});
|
|
1046
|
+
xhr.addEventListener("load", (e) => ah.dispatchEvent(e));
|
|
1047
|
+
xhr.addEventListener("loadend", (e) => ah.dispatchEvent(e));
|
|
1048
|
+
for (const evt of xhrAsyncEvents) {
|
|
1049
|
+
const onEvt = "on" + evt;
|
|
1050
|
+
ah.proxyProps[onEvt] = {
|
|
1051
|
+
get: () => ah.proxyEvents[onEvt] || null,
|
|
1052
|
+
set: (val) => ah.addEvent(onEvt, val),
|
|
1053
|
+
};
|
|
836
1054
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1055
|
+
for (const method of [
|
|
1056
|
+
"setRequestHeader",
|
|
1057
|
+
"addEventListener",
|
|
1058
|
+
"removeEventListener",
|
|
1059
|
+
"open",
|
|
1060
|
+
"send",
|
|
1061
|
+
]) {
|
|
1062
|
+
ah.proxyProps[method] = { value: ah[method] };
|
|
843
1063
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
1064
|
+
}
|
|
1065
|
+
toJSON() {} // Converting circular structure to JSON
|
|
1066
|
+
addEvent(type, event) {
|
|
1067
|
+
if (type.startsWith("on")) {
|
|
1068
|
+
this.proxyEvents[type] = typeof event === "function" ? event : null;
|
|
1069
|
+
} else {
|
|
1070
|
+
if (typeof event === "object" && event !== null)
|
|
1071
|
+
event = event.handleEvent;
|
|
1072
|
+
if (typeof event !== "function") return;
|
|
1073
|
+
this.proxyEvents[type] = this.proxyEvents[type] || new Set();
|
|
1074
|
+
this.proxyEvents[type].add(event);
|
|
850
1075
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
1076
|
+
}
|
|
1077
|
+
removeEvent(type, event) {
|
|
1078
|
+
if (type.startsWith("on")) {
|
|
1079
|
+
this.proxyEvents[type] = null;
|
|
1080
|
+
} else {
|
|
1081
|
+
if (typeof event === "object" && event !== null)
|
|
1082
|
+
event = event.handleEvent;
|
|
1083
|
+
this.proxyEvents[type] && this.proxyEvents[type].delete(event);
|
|
857
1084
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
};
|
|
869
|
-
this.openArgs = args;
|
|
870
|
-
this.resThenable = new SyncThenable();
|
|
871
|
-
[
|
|
872
|
-
"responseURL",
|
|
873
|
-
"readyState",
|
|
874
|
-
"status",
|
|
875
|
-
"statusText",
|
|
876
|
-
...xhrResponses,
|
|
877
|
-
].forEach((key) => {
|
|
878
|
-
delete this.proxyProps[key];
|
|
1085
|
+
}
|
|
1086
|
+
dispatchEvent(e) {
|
|
1087
|
+
e.stopImmediatePropagation = stopImmediatePropagation;
|
|
1088
|
+
defineProp(e, "target", () => this.proxyXhr);
|
|
1089
|
+
defineProp(e, "currentTarget", () => this.proxyXhr);
|
|
1090
|
+
this.proxyEvents[e.type] &&
|
|
1091
|
+
this.proxyEvents[e.type].forEach((fn) => {
|
|
1092
|
+
this.resThenable.then(
|
|
1093
|
+
() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e)
|
|
1094
|
+
);
|
|
879
1095
|
});
|
|
880
|
-
|
|
1096
|
+
if (e.ajaxHooker_isStopped) return;
|
|
1097
|
+
const onEvent = this.proxyEvents["on" + e.type];
|
|
1098
|
+
onEvent && this.resThenable.then(onEvent.bind(this.proxyXhr, e));
|
|
1099
|
+
}
|
|
1100
|
+
setRequestHeader(header, value) {
|
|
1101
|
+
this.originalXhr.setRequestHeader(header, value);
|
|
1102
|
+
if (!this.request) return;
|
|
1103
|
+
const headers = this.request.headers;
|
|
1104
|
+
headers[header] =
|
|
1105
|
+
header in headers ? `${headers[header]}, ${value}` : value;
|
|
1106
|
+
}
|
|
1107
|
+
addEventListener(...args) {
|
|
1108
|
+
if (xhrAsyncEvents.includes(args[0])) {
|
|
1109
|
+
this.addEvent(args[0], args[1]);
|
|
1110
|
+
} else {
|
|
1111
|
+
this.originalXhr.addEventListener(...args);
|
|
881
1112
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
new AHRequest(request).waitForRequestKeys().then(() => {
|
|
889
|
-
if (request.abort) {
|
|
890
|
-
if (typeof request.response === "function") {
|
|
891
|
-
Object.assign(ah.proxyProps, {
|
|
892
|
-
responseURL: { value: request.url },
|
|
893
|
-
readyState: { value: 4 },
|
|
894
|
-
status: { value: 200 },
|
|
895
|
-
statusText: { value: "OK" },
|
|
896
|
-
});
|
|
897
|
-
xhrAsyncEvents.forEach((evt) =>
|
|
898
|
-
xhr.dispatchEvent(new Event(evt))
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
} else {
|
|
902
|
-
xhr.open(
|
|
903
|
-
request.method,
|
|
904
|
-
request.url,
|
|
905
|
-
request.async,
|
|
906
|
-
...ah.openArgs
|
|
907
|
-
);
|
|
908
|
-
for (const header in request.headers) {
|
|
909
|
-
xhr.setRequestHeader(header, request.headers[header]);
|
|
910
|
-
}
|
|
911
|
-
xhr.send(request.data);
|
|
912
|
-
}
|
|
913
|
-
});
|
|
1113
|
+
}
|
|
1114
|
+
removeEventListener(...args) {
|
|
1115
|
+
if (xhrAsyncEvents.includes(args[0])) {
|
|
1116
|
+
this.removeEvent(args[0], args[1]);
|
|
1117
|
+
} else {
|
|
1118
|
+
this.originalXhr.removeEventListener(...args);
|
|
914
1119
|
}
|
|
915
1120
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1121
|
+
open(method, url, async = true, ...args) {
|
|
1122
|
+
this.request = {
|
|
1123
|
+
type: "xhr",
|
|
1124
|
+
url: url.toString(),
|
|
1125
|
+
method: method.toUpperCase(),
|
|
1126
|
+
abort: false,
|
|
1127
|
+
headers: {},
|
|
1128
|
+
data: null,
|
|
1129
|
+
response: null,
|
|
1130
|
+
async: !!async,
|
|
1131
|
+
};
|
|
1132
|
+
this.openArgs = args;
|
|
1133
|
+
this.resThenable = new SyncThenable();
|
|
1134
|
+
[
|
|
1135
|
+
"responseURL",
|
|
1136
|
+
"readyState",
|
|
1137
|
+
"status",
|
|
1138
|
+
"statusText",
|
|
1139
|
+
...xhrResponses,
|
|
1140
|
+
].forEach((key) => {
|
|
1141
|
+
delete this.proxyProps[key];
|
|
1142
|
+
});
|
|
1143
|
+
return this.originalXhr.open(method, url, async, ...args);
|
|
922
1144
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
const init = {};
|
|
931
|
-
if (getType(url) === "[object Request]") {
|
|
932
|
-
for (const prop of fetchInitProps) init[prop] = url[prop];
|
|
933
|
-
if (url.body) init.body = await url.arrayBuffer();
|
|
934
|
-
url = url.url;
|
|
935
|
-
}
|
|
936
|
-
url = url.toString();
|
|
937
|
-
Object.assign(init, options);
|
|
938
|
-
init.method = init.method || "GET";
|
|
939
|
-
init.headers = init.headers || {};
|
|
940
|
-
const request = {
|
|
941
|
-
type: "fetch",
|
|
942
|
-
url: url,
|
|
943
|
-
method: init.method.toUpperCase(),
|
|
944
|
-
abort: false,
|
|
945
|
-
headers: parseHeaders(init.headers),
|
|
946
|
-
data: init.body,
|
|
947
|
-
response: null,
|
|
948
|
-
async: true,
|
|
949
|
-
};
|
|
950
|
-
const req = new AHRequest(request);
|
|
951
|
-
await req.waitForRequestKeys();
|
|
1145
|
+
send(data) {
|
|
1146
|
+
const ah = this;
|
|
1147
|
+
const xhr = ah.originalXhr;
|
|
1148
|
+
const request = ah.request;
|
|
1149
|
+
if (!request) return xhr.send(data);
|
|
1150
|
+
request.data = data;
|
|
1151
|
+
new AHRequest(request).waitForRequestKeys().then(() => {
|
|
952
1152
|
if (request.abort) {
|
|
953
1153
|
if (typeof request.response === "function") {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
await req.waitForResponseKeys(response);
|
|
960
|
-
const key = fetchResponses.find((k) => k in response);
|
|
961
|
-
let val = response[key];
|
|
962
|
-
if (key === "json" && typeof val === "object") {
|
|
963
|
-
val = catchError(JSON.stringify.bind(JSON), val);
|
|
964
|
-
}
|
|
965
|
-
const res = new Response(val, {
|
|
966
|
-
status: 200,
|
|
967
|
-
statusText: "OK",
|
|
1154
|
+
Object.assign(ah.proxyProps, {
|
|
1155
|
+
responseURL: { value: request.url },
|
|
1156
|
+
readyState: { value: 4 },
|
|
1157
|
+
status: { value: 200 },
|
|
1158
|
+
statusText: { value: "OK" },
|
|
968
1159
|
});
|
|
969
|
-
|
|
970
|
-
defineProp(res, "url", () => request.url);
|
|
971
|
-
resolve(res);
|
|
972
|
-
} else {
|
|
973
|
-
reject(new DOMException("aborted", "AbortError"));
|
|
1160
|
+
xhrAsyncEvents.forEach((evt) => xhr.dispatchEvent(new Event(evt)));
|
|
974
1161
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
init.body = request.data;
|
|
980
|
-
winAh.realFetch.call(win, request.url, init).then((res) => {
|
|
981
|
-
if (typeof request.response === "function") {
|
|
982
|
-
const response = {
|
|
983
|
-
finalUrl: res.url,
|
|
984
|
-
status: res.status,
|
|
985
|
-
responseHeaders: parseHeaders(res.headers),
|
|
986
|
-
};
|
|
987
|
-
fetchResponses.forEach(
|
|
988
|
-
(key) =>
|
|
989
|
-
(res[key] = function () {
|
|
990
|
-
if (key in response) return Promise.resolve(response[key]);
|
|
991
|
-
return resProto[key].call(this).then((val) => {
|
|
992
|
-
response[key] = val;
|
|
993
|
-
return req
|
|
994
|
-
.waitForResponseKeys(response)
|
|
995
|
-
.then(() => (key in response ? response[key] : val));
|
|
996
|
-
});
|
|
997
|
-
})
|
|
998
|
-
);
|
|
1162
|
+
} else {
|
|
1163
|
+
xhr.open(request.method, request.url, request.async, ...ah.openArgs);
|
|
1164
|
+
for (const header in request.headers) {
|
|
1165
|
+
xhr.setRequestHeader(header, request.headers[header]);
|
|
999
1166
|
}
|
|
1000
|
-
|
|
1001
|
-
}
|
|
1167
|
+
xhr.send(request.data);
|
|
1168
|
+
}
|
|
1002
1169
|
});
|
|
1003
1170
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
return res;
|
|
1009
|
-
}
|
|
1010
|
-
winAh = win.__ajaxHooker = winAh || {
|
|
1011
|
-
version,
|
|
1012
|
-
fakeXHR,
|
|
1013
|
-
fakeFetch,
|
|
1014
|
-
fakeFetchClone,
|
|
1015
|
-
realXHR: win.XMLHttpRequest,
|
|
1016
|
-
realFetch: win.fetch,
|
|
1017
|
-
realFetchClone: resProto.clone,
|
|
1018
|
-
hookInsts: new Set(),
|
|
1019
|
-
};
|
|
1020
|
-
if (winAh.version !== version)
|
|
1171
|
+
}
|
|
1172
|
+
function fakeXHR() {
|
|
1173
|
+
const xhr = new winAh.realXHR();
|
|
1174
|
+
if ("__ajaxHooker" in xhr)
|
|
1021
1175
|
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1176
|
+
xhr.__ajaxHooker = new XhrHooker(xhr);
|
|
1177
|
+
return xhr.__ajaxHooker.proxyXhr;
|
|
1178
|
+
}
|
|
1179
|
+
fakeXHR.prototype = win.XMLHttpRequest.prototype;
|
|
1180
|
+
Object.keys(win.XMLHttpRequest).forEach(
|
|
1181
|
+
(key) => (fakeXHR[key] = win.XMLHttpRequest[key])
|
|
1182
|
+
);
|
|
1183
|
+
function fakeFetch(url, options = {}) {
|
|
1184
|
+
if (!url) return winAh.realFetch.call(win, url, options);
|
|
1185
|
+
return new Promise(async (resolve, reject) => {
|
|
1186
|
+
const init = {};
|
|
1187
|
+
if (getType(url) === "[object Request]") {
|
|
1188
|
+
for (const prop of fetchInitProps) init[prop] = url[prop];
|
|
1189
|
+
if (url.body) init.body = await url.arrayBuffer();
|
|
1190
|
+
url = url.url;
|
|
1191
|
+
}
|
|
1192
|
+
url = url.toString();
|
|
1193
|
+
Object.assign(init, options);
|
|
1194
|
+
init.method = init.method || "GET";
|
|
1195
|
+
init.headers = init.headers || {};
|
|
1196
|
+
const request = {
|
|
1197
|
+
type: "fetch",
|
|
1198
|
+
url: url,
|
|
1199
|
+
method: init.method.toUpperCase(),
|
|
1200
|
+
abort: false,
|
|
1201
|
+
headers: parseHeaders(init.headers),
|
|
1202
|
+
data: init.body,
|
|
1203
|
+
response: null,
|
|
1204
|
+
async: true,
|
|
1205
|
+
};
|
|
1206
|
+
const req = new AHRequest(request);
|
|
1207
|
+
await req.waitForRequestKeys();
|
|
1208
|
+
if (request.abort) {
|
|
1209
|
+
if (typeof request.response === "function") {
|
|
1210
|
+
const response = {
|
|
1211
|
+
finalUrl: request.url,
|
|
1212
|
+
status: 200,
|
|
1213
|
+
responseHeaders: {},
|
|
1214
|
+
};
|
|
1215
|
+
await req.waitForResponseKeys(response);
|
|
1216
|
+
const key = fetchResponses.find((k) => k in response);
|
|
1217
|
+
let val = response[key];
|
|
1218
|
+
if (key === "json" && typeof val === "object") {
|
|
1219
|
+
val = catchError(JSON.stringify.bind(JSON), val);
|
|
1220
|
+
}
|
|
1221
|
+
const res = new Response(val, {
|
|
1222
|
+
status: 200,
|
|
1223
|
+
statusText: "OK",
|
|
1224
|
+
});
|
|
1225
|
+
defineProp(res, "type", () => "basic");
|
|
1226
|
+
defineProp(res, "url", () => request.url);
|
|
1227
|
+
resolve(res);
|
|
1228
|
+
} else {
|
|
1229
|
+
reject(new DOMException("aborted", "AbortError"));
|
|
1035
1230
|
}
|
|
1036
|
-
return
|
|
1231
|
+
return;
|
|
1037
1232
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1233
|
+
init.method = request.method;
|
|
1234
|
+
init.headers = request.headers;
|
|
1235
|
+
init.body = request.data;
|
|
1236
|
+
winAh.realFetch.call(win, request.url, init).then((res) => {
|
|
1237
|
+
if (typeof request.response === "function") {
|
|
1238
|
+
const response = {
|
|
1239
|
+
finalUrl: res.url,
|
|
1240
|
+
status: res.status,
|
|
1241
|
+
responseHeaders: parseHeaders(res.headers),
|
|
1242
|
+
};
|
|
1243
|
+
fetchResponses.forEach(
|
|
1244
|
+
(key) =>
|
|
1245
|
+
(res[key] = function () {
|
|
1246
|
+
if (key in response) return Promise.resolve(response[key]);
|
|
1247
|
+
return resProto[key].call(this).then((val) => {
|
|
1248
|
+
response[key] = val;
|
|
1249
|
+
return req
|
|
1250
|
+
.waitForResponseKeys(response)
|
|
1251
|
+
.then(() => (key in response ? response[key] : val));
|
|
1252
|
+
});
|
|
1253
|
+
})
|
|
1254
|
+
);
|
|
1045
1255
|
}
|
|
1046
|
-
|
|
1256
|
+
resolve(res);
|
|
1257
|
+
}, reject);
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
function fakeFetchClone() {
|
|
1261
|
+
const descriptors = Object.getOwnPropertyDescriptors(this);
|
|
1262
|
+
const res = winAh.realFetchClone.call(this);
|
|
1263
|
+
Object.defineProperties(res, descriptors);
|
|
1264
|
+
return res;
|
|
1265
|
+
}
|
|
1266
|
+
winAh = win.__ajaxHooker = winAh || {
|
|
1267
|
+
version,
|
|
1268
|
+
fakeXHR,
|
|
1269
|
+
fakeFetch,
|
|
1270
|
+
fakeFetchClone,
|
|
1271
|
+
realXHR: win.XMLHttpRequest,
|
|
1272
|
+
realFetch: win.fetch,
|
|
1273
|
+
realFetchClone: resProto.clone,
|
|
1274
|
+
hookInsts: new Set(),
|
|
1275
|
+
};
|
|
1276
|
+
if (winAh.version !== version)
|
|
1277
|
+
console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
|
|
1278
|
+
win.XMLHttpRequest = winAh.fakeXHR;
|
|
1279
|
+
win.fetch = winAh.fakeFetch;
|
|
1280
|
+
resProto.clone = winAh.fakeFetchClone;
|
|
1281
|
+
winAh.hookInsts.add(hookInst);
|
|
1282
|
+
// 针对头条、抖音 secsdk.umd.js 的兼容性处理
|
|
1283
|
+
class AHFunction extends Function {
|
|
1284
|
+
call(thisArg, ...args) {
|
|
1285
|
+
if (
|
|
1286
|
+
thisArg &&
|
|
1287
|
+
thisArg.__ajaxHooker &&
|
|
1288
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
1289
|
+
) {
|
|
1290
|
+
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
1047
1291
|
}
|
|
1292
|
+
return Reflect.apply(this, thisArg, args);
|
|
1048
1293
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
);
|
|
1058
|
-
Object.setPrototypeOf(
|
|
1059
|
-
csrf.nativeXMLHttpRequestSend,
|
|
1060
|
-
AHFunction.prototype
|
|
1061
|
-
);
|
|
1294
|
+
apply(thisArg, args) {
|
|
1295
|
+
if (
|
|
1296
|
+
thisArg &&
|
|
1297
|
+
thisArg.__ajaxHooker &&
|
|
1298
|
+
thisArg.__ajaxHooker.proxyXhr === thisArg
|
|
1299
|
+
) {
|
|
1300
|
+
thisArg = thisArg.__ajaxHooker.originalXhr;
|
|
1301
|
+
}
|
|
1302
|
+
return Reflect.apply(this, thisArg, args || []);
|
|
1062
1303
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1304
|
+
}
|
|
1305
|
+
function hookSecsdk(csrf) {
|
|
1306
|
+
Object.setPrototypeOf(
|
|
1307
|
+
csrf.nativeXMLHttpRequestSetRequestHeader,
|
|
1308
|
+
AHFunction.prototype
|
|
1309
|
+
);
|
|
1310
|
+
Object.setPrototypeOf(csrf.nativeXMLHttpRequestOpen, AHFunction.prototype);
|
|
1311
|
+
Object.setPrototypeOf(csrf.nativeXMLHttpRequestSend, AHFunction.prototype);
|
|
1312
|
+
}
|
|
1313
|
+
if (win.secsdk) {
|
|
1314
|
+
if (win.secsdk.csrf && win.secsdk.csrf.nativeXMLHttpRequestOpen)
|
|
1315
|
+
hookSecsdk(win.secsdk.csrf);
|
|
1316
|
+
} else {
|
|
1317
|
+
defineProp(win, "secsdk", emptyFn, (secsdk) => {
|
|
1318
|
+
delete win.secsdk;
|
|
1319
|
+
win.secsdk = secsdk;
|
|
1320
|
+
defineProp(secsdk, "csrf", emptyFn, (csrf) => {
|
|
1321
|
+
delete secsdk.csrf;
|
|
1322
|
+
secsdk.csrf = csrf;
|
|
1323
|
+
if (csrf.nativeXMLHttpRequestOpen) hookSecsdk(csrf);
|
|
1075
1324
|
});
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
return {
|
|
1328
|
+
hook: (fn) => hookInst.hookFns.push(fn),
|
|
1329
|
+
filter: (arr) => {
|
|
1330
|
+
if (Array.isArray(arr)) hookInst.filters = arr;
|
|
1331
|
+
},
|
|
1332
|
+
protect: () => {
|
|
1333
|
+
readonly(win, "XMLHttpRequest", winAh.fakeXHR);
|
|
1334
|
+
readonly(win, "fetch", winAh.fakeFetch);
|
|
1335
|
+
readonly(resProto, "clone", winAh.fakeFetchClone);
|
|
1336
|
+
},
|
|
1337
|
+
unhook: () => {
|
|
1338
|
+
winAh.hookInsts.delete(hookInst);
|
|
1339
|
+
if (!winAh.hookInsts.size) {
|
|
1340
|
+
writable(win, "XMLHttpRequest", winAh.realXHR);
|
|
1341
|
+
writable(win, "fetch", winAh.realFetch);
|
|
1342
|
+
writable(resProto, "clone", winAh.realFetchClone);
|
|
1343
|
+
delete win.__ajaxHooker;
|
|
1344
|
+
}
|
|
1345
|
+
},
|
|
1346
|
+
};
|
|
1098
1347
|
};
|
|
1099
1348
|
|
|
1100
1349
|
// ==UserScript==
|
|
@@ -1626,7 +1875,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
1626
1875
|
menuOptions = [menuOptions];
|
|
1627
1876
|
}
|
|
1628
1877
|
for (let index = 0; index < menuOptions.length; index++) {
|
|
1629
|
-
let cloneMenuOptionData =
|
|
1878
|
+
let cloneMenuOptionData = commonUtil.deepClone(menuOptions[index].data);
|
|
1630
1879
|
const { showText, clickCallBack } = this.handleMenuData(cloneMenuOptionData);
|
|
1631
1880
|
let menuId = that.context.GM_Api.registerMenuCommand(showText, clickCallBack);
|
|
1632
1881
|
menuOptions[index].id = menuId;
|
|
@@ -1798,14 +2047,14 @@ System.register('Utils', [], (function (exports) {
|
|
|
1798
2047
|
const option = menuOption[index];
|
|
1799
2048
|
this.MenuHandle.$data.data.push({
|
|
1800
2049
|
data: option,
|
|
1801
|
-
id:
|
|
2050
|
+
id: void 0,
|
|
1802
2051
|
});
|
|
1803
2052
|
}
|
|
1804
2053
|
}
|
|
1805
2054
|
else {
|
|
1806
2055
|
this.MenuHandle.$data.data.push({
|
|
1807
2056
|
data: menuOption,
|
|
1808
|
-
id:
|
|
2057
|
+
id: void 0,
|
|
1809
2058
|
});
|
|
1810
2059
|
}
|
|
1811
2060
|
}
|
|
@@ -2028,16 +2277,12 @@ System.register('Utils', [], (function (exports) {
|
|
|
2028
2277
|
return "";
|
|
2029
2278
|
}
|
|
2030
2279
|
try {
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
"return _context['realFunc_" +
|
|
2038
|
-
_funcName +
|
|
2039
|
-
"'].apply(obj,args);\n" +
|
|
2040
|
-
"};");
|
|
2280
|
+
new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
|
|
2281
|
+
let args = Array.prototype.slice.call(arguments, 0);
|
|
2282
|
+
let obj = this;
|
|
2283
|
+
hookFunc.apply(obj, args);
|
|
2284
|
+
return _context['realFunc_${_funcName}'].apply(obj, args);
|
|
2285
|
+
};`)(_context, _funcName, hookFunc);
|
|
2041
2286
|
_context[_funcName].prototype.isHooked = true;
|
|
2042
2287
|
return true;
|
|
2043
2288
|
}
|
|
@@ -2297,14 +2542,14 @@ System.register('Utils', [], (function (exports) {
|
|
|
2297
2542
|
if (typeof args[1] === "object") {
|
|
2298
2543
|
/* 处理第二个参数details */
|
|
2299
2544
|
let optionArg = args[1];
|
|
2300
|
-
|
|
2545
|
+
commonUtil.assign(option, optionArg, true);
|
|
2301
2546
|
option.url = url;
|
|
2302
2547
|
}
|
|
2303
2548
|
}
|
|
2304
2549
|
else {
|
|
2305
2550
|
/* 传入的是配置 */
|
|
2306
2551
|
let optionArg = args[0];
|
|
2307
|
-
|
|
2552
|
+
commonUtil.assign(option, optionArg, true);
|
|
2308
2553
|
}
|
|
2309
2554
|
return option;
|
|
2310
2555
|
},
|
|
@@ -2337,7 +2582,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2337
2582
|
responseType: userRequestOption.responseType ||
|
|
2338
2583
|
this.context.#defaultRequestOption.responseType,
|
|
2339
2584
|
/* 对象使用深拷贝 */
|
|
2340
|
-
headers:
|
|
2585
|
+
headers: commonUtil.deepClone(this.context.#defaultRequestOption.headers),
|
|
2341
2586
|
data: userRequestOption.data || this.context.#defaultRequestOption.data,
|
|
2342
2587
|
redirect: userRequestOption.redirect ||
|
|
2343
2588
|
this.context.#defaultRequestOption.redirect,
|
|
@@ -2350,7 +2595,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2350
2595
|
revalidate: userRequestOption.revalidate ||
|
|
2351
2596
|
this.context.#defaultRequestOption.revalidate,
|
|
2352
2597
|
/* 对象使用深拷贝 */
|
|
2353
|
-
context:
|
|
2598
|
+
context: commonUtil.deepClone(userRequestOption.context ||
|
|
2354
2599
|
this.context.#defaultRequestOption.context),
|
|
2355
2600
|
overrideMimeType: userRequestOption.overrideMimeType ||
|
|
2356
2601
|
this.context.#defaultRequestOption.overrideMimeType,
|
|
@@ -2358,7 +2603,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2358
2603
|
this.context.#defaultRequestOption.anonymous,
|
|
2359
2604
|
fetch: userRequestOption.fetch || this.context.#defaultRequestOption.fetch,
|
|
2360
2605
|
/* 对象使用深拷贝 */
|
|
2361
|
-
fetchInit:
|
|
2606
|
+
fetchInit: commonUtil.deepClone(this.context.#defaultRequestOption.fetchInit),
|
|
2362
2607
|
allowInterceptConfig: {
|
|
2363
2608
|
beforeRequest: this.context.#defaultRequestOption
|
|
2364
2609
|
.allowInterceptConfig.beforeRequest,
|
|
@@ -2584,12 +2829,12 @@ System.register('Utils', [], (function (exports) {
|
|
|
2584
2829
|
Object.keys(option).forEach((keyName) => {
|
|
2585
2830
|
if (option[keyName] == null ||
|
|
2586
2831
|
(option[keyName] instanceof Function &&
|
|
2587
|
-
|
|
2832
|
+
commonUtil.isNull(option[keyName]))) {
|
|
2588
2833
|
Reflect.deleteProperty(option, keyName);
|
|
2589
2834
|
return;
|
|
2590
2835
|
}
|
|
2591
2836
|
});
|
|
2592
|
-
if (
|
|
2837
|
+
if (commonUtil.isNull(option.url)) {
|
|
2593
2838
|
throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
|
|
2594
2839
|
}
|
|
2595
2840
|
return option;
|
|
@@ -2788,10 +3033,10 @@ System.register('Utils', [], (function (exports) {
|
|
|
2788
3033
|
/* X浏览器会因为设置了responseType导致不返回responseText */
|
|
2789
3034
|
let originResponse = argsResult[0];
|
|
2790
3035
|
/* responseText为空,response不为空的情况 */
|
|
2791
|
-
if (
|
|
2792
|
-
|
|
3036
|
+
if (commonUtil.isNull(originResponse["responseText"]) &&
|
|
3037
|
+
commonUtil.isNotNull(originResponse["response"])) {
|
|
2793
3038
|
if (typeof originResponse["response"] === "object") {
|
|
2794
|
-
|
|
3039
|
+
TryCatch().run(() => {
|
|
2795
3040
|
originResponse["responseText"] = JSON.stringify(originResponse["response"]);
|
|
2796
3041
|
});
|
|
2797
3042
|
}
|
|
@@ -2808,7 +3053,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
2808
3053
|
// 自定义个新的response
|
|
2809
3054
|
let httpxResponse = httpxResponseText;
|
|
2810
3055
|
if (details.responseType === "json") {
|
|
2811
|
-
httpxResponse =
|
|
3056
|
+
httpxResponse = commonUtil.toJSON(httpxResponseText);
|
|
2812
3057
|
}
|
|
2813
3058
|
else if (details.responseType === "document") {
|
|
2814
3059
|
let parser = new DOMParser();
|
|
@@ -2952,13 +3197,13 @@ System.register('Utils', [], (function (exports) {
|
|
|
2952
3197
|
status: fetchResponse.status,
|
|
2953
3198
|
statusText: fetchResponse.statusText,
|
|
2954
3199
|
// @ts-ignore
|
|
2955
|
-
response:
|
|
3200
|
+
response: void 0,
|
|
2956
3201
|
responseFetchHeaders: fetchResponse.headers,
|
|
2957
3202
|
responseHeaders: "",
|
|
2958
3203
|
// @ts-ignore
|
|
2959
|
-
responseText:
|
|
3204
|
+
responseText: void 0,
|
|
2960
3205
|
responseType: option.responseType,
|
|
2961
|
-
responseXML:
|
|
3206
|
+
responseXML: void 0,
|
|
2962
3207
|
};
|
|
2963
3208
|
Object.assign(httpxResponse, option.context || {});
|
|
2964
3209
|
// 把headers转为字符串
|
|
@@ -3018,7 +3263,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3018
3263
|
(typeof fetchResponseType === "string" &&
|
|
3019
3264
|
fetchResponseType.includes("application/json"))) {
|
|
3020
3265
|
// response返回格式是JSON格式
|
|
3021
|
-
response =
|
|
3266
|
+
response = commonUtil.toJSON(responseText);
|
|
3022
3267
|
}
|
|
3023
3268
|
else if (option.responseType === "document" ||
|
|
3024
3269
|
option.responseType == null) {
|
|
@@ -3070,30 +3315,30 @@ System.register('Utils', [], (function (exports) {
|
|
|
3070
3315
|
* 默认配置
|
|
3071
3316
|
*/
|
|
3072
3317
|
#defaultRequestOption = {
|
|
3073
|
-
url:
|
|
3318
|
+
url: void 0,
|
|
3074
3319
|
timeout: 5000,
|
|
3075
3320
|
async: false,
|
|
3076
|
-
responseType:
|
|
3077
|
-
headers:
|
|
3078
|
-
data:
|
|
3079
|
-
redirect:
|
|
3080
|
-
cookie:
|
|
3081
|
-
cookiePartition:
|
|
3082
|
-
binary:
|
|
3083
|
-
nocache:
|
|
3084
|
-
revalidate:
|
|
3085
|
-
context:
|
|
3086
|
-
overrideMimeType:
|
|
3087
|
-
anonymous:
|
|
3088
|
-
fetch:
|
|
3089
|
-
fetchInit:
|
|
3321
|
+
responseType: void 0,
|
|
3322
|
+
headers: void 0,
|
|
3323
|
+
data: void 0,
|
|
3324
|
+
redirect: void 0,
|
|
3325
|
+
cookie: void 0,
|
|
3326
|
+
cookiePartition: void 0,
|
|
3327
|
+
binary: void 0,
|
|
3328
|
+
nocache: void 0,
|
|
3329
|
+
revalidate: void 0,
|
|
3330
|
+
context: void 0,
|
|
3331
|
+
overrideMimeType: void 0,
|
|
3332
|
+
anonymous: void 0,
|
|
3333
|
+
fetch: void 0,
|
|
3334
|
+
fetchInit: void 0,
|
|
3090
3335
|
allowInterceptConfig: {
|
|
3091
3336
|
beforeRequest: true,
|
|
3092
3337
|
afterResponseSuccess: true,
|
|
3093
3338
|
afterResponseError: true,
|
|
3094
3339
|
},
|
|
3095
|
-
user:
|
|
3096
|
-
password:
|
|
3340
|
+
user: void 0,
|
|
3341
|
+
password: void 0,
|
|
3097
3342
|
onabort() { },
|
|
3098
3343
|
onerror() { },
|
|
3099
3344
|
ontimeout() { },
|
|
@@ -3105,7 +3350,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3105
3350
|
/**
|
|
3106
3351
|
* `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL。
|
|
3107
3352
|
*/
|
|
3108
|
-
baseURL:
|
|
3353
|
+
baseURL: void 0,
|
|
3109
3354
|
/**
|
|
3110
3355
|
* 当前使用请求时,输出请求的配置,一般用于DEBUG|DEV
|
|
3111
3356
|
*/
|
|
@@ -3119,7 +3364,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3119
3364
|
if (typeof option.xmlHttpRequest !== "function") {
|
|
3120
3365
|
console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
|
|
3121
3366
|
}
|
|
3122
|
-
|
|
3367
|
+
commonUtil.coverObjectFunctionThis(this);
|
|
3123
3368
|
this.interceptors.request.context = this;
|
|
3124
3369
|
this.interceptors.response.context = this;
|
|
3125
3370
|
this.config(option);
|
|
@@ -3132,8 +3377,8 @@ System.register('Utils', [], (function (exports) {
|
|
|
3132
3377
|
if (typeof option.xmlHttpRequest === "function") {
|
|
3133
3378
|
this.GM_Api.xmlHttpRequest = option.xmlHttpRequest;
|
|
3134
3379
|
}
|
|
3135
|
-
this.#defaultRequestOption =
|
|
3136
|
-
this.#defaultInitOption =
|
|
3380
|
+
this.#defaultRequestOption = commonUtil.assign(this.#defaultRequestOption, option);
|
|
3381
|
+
this.#defaultInitOption = commonUtil.assign(this.#defaultInitOption, option);
|
|
3137
3382
|
}
|
|
3138
3383
|
/**
|
|
3139
3384
|
* 拦截器
|
|
@@ -3510,7 +3755,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3510
3755
|
success: false,
|
|
3511
3756
|
code: that.#statusCode.getFailed.code,
|
|
3512
3757
|
msg: that.#statusCode.getFailed.msg,
|
|
3513
|
-
data:
|
|
3758
|
+
data: void 0,
|
|
3514
3759
|
});
|
|
3515
3760
|
}
|
|
3516
3761
|
else {
|
|
@@ -3520,7 +3765,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3520
3765
|
let result = target.result;
|
|
3521
3766
|
/* result 返回的是 {key: string, value: any} */
|
|
3522
3767
|
/* 键值对存储 */
|
|
3523
|
-
let data = result ? result.value :
|
|
3768
|
+
let data = result ? result.value : void 0;
|
|
3524
3769
|
if (data == null) {
|
|
3525
3770
|
resolve({
|
|
3526
3771
|
success: true,
|
|
@@ -3547,7 +3792,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3547
3792
|
success: false,
|
|
3548
3793
|
code: that.#statusCode.getFailed.code,
|
|
3549
3794
|
msg: that.#statusCode.getFailed.msg,
|
|
3550
|
-
data:
|
|
3795
|
+
data: void 0,
|
|
3551
3796
|
event: event,
|
|
3552
3797
|
});
|
|
3553
3798
|
};
|
|
@@ -3697,7 +3942,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3697
3942
|
#flag = false;
|
|
3698
3943
|
#delayTime = 0;
|
|
3699
3944
|
#callback;
|
|
3700
|
-
#
|
|
3945
|
+
#timeId = void 0;
|
|
3701
3946
|
lock;
|
|
3702
3947
|
unlock;
|
|
3703
3948
|
run;
|
|
@@ -3707,23 +3952,22 @@ System.register('Utils', [], (function (exports) {
|
|
|
3707
3952
|
this.#callback = callback;
|
|
3708
3953
|
if (typeof context === "number") {
|
|
3709
3954
|
this.#delayTime = context;
|
|
3710
|
-
this.#context = utils;
|
|
3711
3955
|
}
|
|
3712
3956
|
else {
|
|
3713
3957
|
this.#delayTime = delayTime;
|
|
3714
|
-
this.#context = context;
|
|
3715
3958
|
}
|
|
3716
3959
|
/**
|
|
3717
3960
|
* 锁
|
|
3718
3961
|
*/
|
|
3719
3962
|
this.lock = function () {
|
|
3720
3963
|
that.#flag = true;
|
|
3964
|
+
clearTimeout(that.#timeId);
|
|
3721
3965
|
};
|
|
3722
3966
|
/**
|
|
3723
3967
|
* 解锁
|
|
3724
3968
|
*/
|
|
3725
3969
|
this.unlock = function () {
|
|
3726
|
-
|
|
3970
|
+
that.#timeId = setTimeout(() => {
|
|
3727
3971
|
that.#flag = false;
|
|
3728
3972
|
}, that.#delayTime);
|
|
3729
3973
|
};
|
|
@@ -3741,7 +3985,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
3741
3985
|
return;
|
|
3742
3986
|
}
|
|
3743
3987
|
that.lock();
|
|
3744
|
-
await that.#callback.apply(
|
|
3988
|
+
await that.#callback.apply(this, args);
|
|
3745
3989
|
that.unlock();
|
|
3746
3990
|
};
|
|
3747
3991
|
}
|
|
@@ -4029,7 +4273,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4029
4273
|
* @param paramConfig 配置信息
|
|
4030
4274
|
*/
|
|
4031
4275
|
constructor(paramConfig) {
|
|
4032
|
-
this.#config =
|
|
4276
|
+
this.#config = commonUtil.assign(this.#config, paramConfig);
|
|
4033
4277
|
if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
|
|
4034
4278
|
throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
|
|
4035
4279
|
}
|
|
@@ -4081,97 +4325,12 @@ System.register('Utils', [], (function (exports) {
|
|
|
4081
4325
|
let txt = parseInt(this.#config.progress.toString()) + "%";
|
|
4082
4326
|
this.#ctx.font = this.#config.fontSize + "px SimHei";
|
|
4083
4327
|
/* 获取文本宽度 */
|
|
4084
|
-
let w = this.#ctx.measureText(txt).width;
|
|
4085
|
-
let h = this.#config.fontSize / 2;
|
|
4086
|
-
this.#ctx.fillStyle = this.#config.textColor;
|
|
4087
|
-
this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
|
|
4088
|
-
}
|
|
4089
|
-
}
|
|
4090
|
-
|
|
4091
|
-
const TryCatch = function (...args) {
|
|
4092
|
-
/* 定义变量和函数 */
|
|
4093
|
-
let callbackFunction = null;
|
|
4094
|
-
let context = null;
|
|
4095
|
-
let handleError = (error) => { };
|
|
4096
|
-
let defaultDetails = {
|
|
4097
|
-
log: true,
|
|
4098
|
-
};
|
|
4099
|
-
const TryCatchCore = {
|
|
4100
|
-
/**
|
|
4101
|
-
*
|
|
4102
|
-
* @param paramDetails 配置
|
|
4103
|
-
* @returns
|
|
4104
|
-
*/
|
|
4105
|
-
config(paramDetails) {
|
|
4106
|
-
defaultDetails = utils.assign(defaultDetails, paramDetails);
|
|
4107
|
-
return TryCatchCore;
|
|
4108
|
-
},
|
|
4109
|
-
/**
|
|
4110
|
-
* 处理错误
|
|
4111
|
-
* @param handler
|
|
4112
|
-
*/
|
|
4113
|
-
error(handler) {
|
|
4114
|
-
// @ts-ignore
|
|
4115
|
-
handleError = handler;
|
|
4116
|
-
return TryCatchCore;
|
|
4117
|
-
},
|
|
4118
|
-
/**
|
|
4119
|
-
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
4120
|
-
* @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
4121
|
-
* @param __context__ 待执行函数的作用域,用于apply指定
|
|
4122
|
-
* @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
|
|
4123
|
-
* @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
|
|
4124
|
-
*/
|
|
4125
|
-
run(callback, __context__) {
|
|
4126
|
-
callbackFunction = callback;
|
|
4127
|
-
context = __context__ || this;
|
|
4128
|
-
let result = executeTryCatch(callbackFunction, handleError, context);
|
|
4129
|
-
// @ts-ignore
|
|
4130
|
-
return result !== undefined ? result : TryCatchCore;
|
|
4131
|
-
},
|
|
4132
|
-
};
|
|
4133
|
-
/**
|
|
4134
|
-
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
4135
|
-
* @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
4136
|
-
* @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
4137
|
-
* @param funcThis - 待执行函数的作用域,用于apply指定
|
|
4138
|
-
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
4139
|
-
*/
|
|
4140
|
-
function executeTryCatch(callback, handleErrorFunc, funcThis) {
|
|
4141
|
-
let result = undefined;
|
|
4142
|
-
try {
|
|
4143
|
-
if (typeof callback === "string") {
|
|
4144
|
-
(function () {
|
|
4145
|
-
eval(callback);
|
|
4146
|
-
}).apply(funcThis, args);
|
|
4147
|
-
}
|
|
4148
|
-
else {
|
|
4149
|
-
result = callback.apply(funcThis, args);
|
|
4150
|
-
}
|
|
4151
|
-
}
|
|
4152
|
-
catch (error) {
|
|
4153
|
-
if (defaultDetails.log) {
|
|
4154
|
-
callback = callback;
|
|
4155
|
-
console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
|
|
4156
|
-
console.log(`%c 错误原因:${error}`, "color: #f20000");
|
|
4157
|
-
console.trace(callback);
|
|
4158
|
-
}
|
|
4159
|
-
if (handleErrorFunc) {
|
|
4160
|
-
if (typeof handleErrorFunc === "string") {
|
|
4161
|
-
result = function () {
|
|
4162
|
-
return eval(handleErrorFunc);
|
|
4163
|
-
// @ts-ignore
|
|
4164
|
-
}.apply(funcThis, [...args, error]);
|
|
4165
|
-
}
|
|
4166
|
-
else {
|
|
4167
|
-
result = handleErrorFunc.apply(funcThis, [...args, error]);
|
|
4168
|
-
}
|
|
4169
|
-
}
|
|
4170
|
-
}
|
|
4171
|
-
return result;
|
|
4328
|
+
let w = this.#ctx.measureText(txt).width;
|
|
4329
|
+
let h = this.#config.fontSize / 2;
|
|
4330
|
+
this.#ctx.fillStyle = this.#config.textColor;
|
|
4331
|
+
this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
|
|
4172
4332
|
}
|
|
4173
|
-
|
|
4174
|
-
};
|
|
4333
|
+
}
|
|
4175
4334
|
|
|
4176
4335
|
class UtilsDictionary {
|
|
4177
4336
|
items = {};
|
|
@@ -4206,7 +4365,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4206
4365
|
*/
|
|
4207
4366
|
getStartsWith(key) {
|
|
4208
4367
|
let allKeys = this.keys();
|
|
4209
|
-
let result =
|
|
4368
|
+
let result = void 0;
|
|
4210
4369
|
for (const keyName of allKeys) {
|
|
4211
4370
|
if (String(keyName).startsWith(String(key))) {
|
|
4212
4371
|
result = this.get(keyName);
|
|
@@ -4221,7 +4380,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4221
4380
|
* @param val 值,默认为""
|
|
4222
4381
|
*/
|
|
4223
4382
|
set(key, val) {
|
|
4224
|
-
if (key ===
|
|
4383
|
+
if (key === void 0) {
|
|
4225
4384
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
4226
4385
|
}
|
|
4227
4386
|
Reflect.set(this.items, key, val);
|
|
@@ -4288,7 +4447,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4288
4447
|
* @param data 需要合并的字典
|
|
4289
4448
|
*/
|
|
4290
4449
|
concat(data) {
|
|
4291
|
-
this.items =
|
|
4450
|
+
this.items = commonUtil.assign(this.items, data.getItems());
|
|
4292
4451
|
}
|
|
4293
4452
|
forEach(callbackfn) {
|
|
4294
4453
|
for (const key in this.getItems()) {
|
|
@@ -4847,7 +5006,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
4847
5006
|
|
|
4848
5007
|
const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
|
|
4849
5008
|
const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
|
|
4850
|
-
const clearTimeout = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
5009
|
+
const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
4851
5010
|
const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
4852
5011
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
4853
5012
|
|
|
@@ -5249,13 +5408,194 @@ System.register('Utils', [], (function (exports) {
|
|
|
5249
5408
|
}
|
|
5250
5409
|
}
|
|
5251
5410
|
|
|
5411
|
+
class DOMUtils {
|
|
5412
|
+
windowApi;
|
|
5413
|
+
constructor(option) {
|
|
5414
|
+
this.windowApi = new WindowApi(option);
|
|
5415
|
+
}
|
|
5416
|
+
selector(selector, parent) {
|
|
5417
|
+
return this.selectorAll(selector, parent)[0];
|
|
5418
|
+
}
|
|
5419
|
+
selectorAll(selector, parent) {
|
|
5420
|
+
const context = this;
|
|
5421
|
+
parent = parent || context.windowApi.document;
|
|
5422
|
+
selector = selector.trim();
|
|
5423
|
+
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
|
5424
|
+
// empty 语法
|
|
5425
|
+
selector = selector.replace(/:empty$/gi, "");
|
|
5426
|
+
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5427
|
+
return $ele?.innerHTML?.trim() === "";
|
|
5428
|
+
});
|
|
5429
|
+
}
|
|
5430
|
+
else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
|
|
5431
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
|
|
5432
|
+
// contains 语法
|
|
5433
|
+
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
5434
|
+
let text = textMatch[2];
|
|
5435
|
+
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5436
|
+
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5437
|
+
// @ts-ignore
|
|
5438
|
+
return ($ele?.textContent || $ele?.innerText)?.includes(text);
|
|
5439
|
+
});
|
|
5440
|
+
}
|
|
5441
|
+
else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
5442
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
|
|
5443
|
+
// regexp 语法
|
|
5444
|
+
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
5445
|
+
let pattern = textMatch[2];
|
|
5446
|
+
let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
|
|
5447
|
+
let flags = "";
|
|
5448
|
+
if (flagMatch) {
|
|
5449
|
+
pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
|
|
5450
|
+
flags = flagMatch[3];
|
|
5451
|
+
}
|
|
5452
|
+
let regexp = new RegExp(pattern, flags);
|
|
5453
|
+
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5454
|
+
return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
|
|
5455
|
+
// @ts-ignore
|
|
5456
|
+
return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
|
|
5457
|
+
});
|
|
5458
|
+
}
|
|
5459
|
+
else {
|
|
5460
|
+
// 普通语法
|
|
5461
|
+
return Array.from(parent.querySelectorAll(selector));
|
|
5462
|
+
}
|
|
5463
|
+
}
|
|
5464
|
+
/**
|
|
5465
|
+
* 匹配元素,可使用以下的额外语法
|
|
5466
|
+
*
|
|
5467
|
+
* + :contains([text]) 作用: 找到包含指定文本内容的指定元素
|
|
5468
|
+
* + :empty 作用:找到既没有文本内容也没有子元素的指定元素
|
|
5469
|
+
* + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
|
|
5470
|
+
* @param $el 元素
|
|
5471
|
+
* @param selector 选择器
|
|
5472
|
+
* @example
|
|
5473
|
+
* DOMUtils.matches("div:contains('测试')")
|
|
5474
|
+
* > true
|
|
5475
|
+
* @example
|
|
5476
|
+
* DOMUtils.matches("div:empty")
|
|
5477
|
+
* > true
|
|
5478
|
+
* @example
|
|
5479
|
+
* DOMUtils.matches("div:regexp('^xxxx$')")
|
|
5480
|
+
* > true
|
|
5481
|
+
* @example
|
|
5482
|
+
* DOMUtils.matches("div:regexp(/^xxx/ig)")
|
|
5483
|
+
* > false
|
|
5484
|
+
*/
|
|
5485
|
+
matches($el, selector) {
|
|
5486
|
+
selector = selector.trim();
|
|
5487
|
+
if ($el == null) {
|
|
5488
|
+
return false;
|
|
5489
|
+
}
|
|
5490
|
+
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
|
5491
|
+
// empty 语法
|
|
5492
|
+
selector = selector.replace(/:empty$/gi, "");
|
|
5493
|
+
return $el.matches(selector) && $el?.innerHTML?.trim() === "";
|
|
5494
|
+
}
|
|
5495
|
+
else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
|
|
5496
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
|
|
5497
|
+
// contains 语法
|
|
5498
|
+
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
5499
|
+
let text = textMatch[2];
|
|
5500
|
+
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5501
|
+
// @ts-ignore
|
|
5502
|
+
let content = $el?.textContent || $el?.innerText;
|
|
5503
|
+
if (typeof content !== "string") {
|
|
5504
|
+
content = "";
|
|
5505
|
+
}
|
|
5506
|
+
return $el.matches(selector) && content?.includes(text);
|
|
5507
|
+
}
|
|
5508
|
+
else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
5509
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
|
|
5510
|
+
// regexp 语法
|
|
5511
|
+
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
5512
|
+
let pattern = textMatch[2];
|
|
5513
|
+
let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
|
|
5514
|
+
let flags = "";
|
|
5515
|
+
if (flagMatch) {
|
|
5516
|
+
pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
|
|
5517
|
+
flags = flagMatch[3];
|
|
5518
|
+
}
|
|
5519
|
+
let regexp = new RegExp(pattern, flags);
|
|
5520
|
+
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5521
|
+
// @ts-ignore
|
|
5522
|
+
let content = $el?.textContent || $el?.innerText;
|
|
5523
|
+
if (typeof content !== "string") {
|
|
5524
|
+
content = "";
|
|
5525
|
+
}
|
|
5526
|
+
return $el.matches(selector) && Boolean(content?.match(regexp));
|
|
5527
|
+
}
|
|
5528
|
+
else {
|
|
5529
|
+
// 普通语法
|
|
5530
|
+
return $el.matches(selector);
|
|
5531
|
+
}
|
|
5532
|
+
}
|
|
5533
|
+
closest($el, selector) {
|
|
5534
|
+
selector = selector.trim();
|
|
5535
|
+
if (selector.match(/[^\s]{1}:empty$/gi)) {
|
|
5536
|
+
// empty 语法
|
|
5537
|
+
selector = selector.replace(/:empty$/gi, "");
|
|
5538
|
+
let $closest = $el?.closest(selector);
|
|
5539
|
+
if ($closest && $closest?.innerHTML?.trim() === "") {
|
|
5540
|
+
return $closest;
|
|
5541
|
+
}
|
|
5542
|
+
return null;
|
|
5543
|
+
}
|
|
5544
|
+
else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
|
|
5545
|
+
selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
|
|
5546
|
+
// contains 语法
|
|
5547
|
+
let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
|
|
5548
|
+
let text = textMatch[2];
|
|
5549
|
+
selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
|
|
5550
|
+
let $closest = $el?.closest(selector);
|
|
5551
|
+
if ($closest) {
|
|
5552
|
+
// @ts-ignore
|
|
5553
|
+
let content = $el?.textContent || $el?.innerText;
|
|
5554
|
+
if (typeof content === "string" && content.includes(text)) {
|
|
5555
|
+
return $closest;
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
return null;
|
|
5559
|
+
}
|
|
5560
|
+
else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
|
|
5561
|
+
selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
|
|
5562
|
+
// regexp 语法
|
|
5563
|
+
let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
|
|
5564
|
+
let pattern = textMatch[2];
|
|
5565
|
+
let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
|
|
5566
|
+
let flags = "";
|
|
5567
|
+
if (flagMatch) {
|
|
5568
|
+
pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
|
|
5569
|
+
flags = flagMatch[3];
|
|
5570
|
+
}
|
|
5571
|
+
let regexp = new RegExp(pattern, flags);
|
|
5572
|
+
selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
|
|
5573
|
+
let $closest = $el?.closest(selector);
|
|
5574
|
+
if ($closest) {
|
|
5575
|
+
// @ts-ignore
|
|
5576
|
+
let content = $el?.textContent || $el?.innerText;
|
|
5577
|
+
if (typeof content === "string" && content.match(regexp)) {
|
|
5578
|
+
return $closest;
|
|
5579
|
+
}
|
|
5580
|
+
}
|
|
5581
|
+
return null;
|
|
5582
|
+
}
|
|
5583
|
+
else {
|
|
5584
|
+
// 普通语法
|
|
5585
|
+
let $closest = $el?.closest(selector);
|
|
5586
|
+
return $closest;
|
|
5587
|
+
}
|
|
5588
|
+
}
|
|
5589
|
+
}
|
|
5590
|
+
let domUtils = new DOMUtils();
|
|
5591
|
+
|
|
5252
5592
|
class Utils {
|
|
5253
5593
|
windowApi;
|
|
5254
5594
|
constructor(option) {
|
|
5255
5595
|
this.windowApi = new WindowApi(option);
|
|
5256
5596
|
}
|
|
5257
5597
|
/** 版本号 */
|
|
5258
|
-
version = "2025.
|
|
5598
|
+
version = "2025.6.26";
|
|
5259
5599
|
addStyle(cssText) {
|
|
5260
5600
|
if (typeof cssText !== "string") {
|
|
5261
5601
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -5281,58 +5621,22 @@ System.register('Utils', [], (function (exports) {
|
|
|
5281
5621
|
}
|
|
5282
5622
|
return cssNode;
|
|
5283
5623
|
}
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
}
|
|
5297
|
-
if (target == null) {
|
|
5298
|
-
target = {};
|
|
5299
|
-
}
|
|
5300
|
-
if (isAdd) {
|
|
5301
|
-
for (const sourceKeyName in source) {
|
|
5302
|
-
const targetKeyName = sourceKeyName;
|
|
5303
|
-
let targetValue = target[targetKeyName];
|
|
5304
|
-
let sourceValue = source[sourceKeyName];
|
|
5305
|
-
if (typeof sourceValue === "object" &&
|
|
5306
|
-
sourceValue != null &&
|
|
5307
|
-
sourceKeyName in target &&
|
|
5308
|
-
!UtilsContext.isDOM(sourceValue)) {
|
|
5309
|
-
/* 源端的值是object类型,且不是元素节点 */
|
|
5310
|
-
target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
5311
|
-
continue;
|
|
5312
|
-
}
|
|
5313
|
-
target[sourceKeyName] = sourceValue;
|
|
5314
|
-
}
|
|
5315
|
-
}
|
|
5316
|
-
else {
|
|
5317
|
-
for (const targetKeyName in target) {
|
|
5318
|
-
if (targetKeyName in source) {
|
|
5319
|
-
let targetValue = target[targetKeyName];
|
|
5320
|
-
let sourceValue = source[targetKeyName];
|
|
5321
|
-
if (typeof sourceValue === "object" &&
|
|
5322
|
-
sourceValue != null &&
|
|
5323
|
-
!UtilsContext.isDOM(sourceValue) &&
|
|
5324
|
-
Object.keys(sourceValue).length) {
|
|
5325
|
-
/* 源端的值是object类型,且不是元素节点 */
|
|
5326
|
-
target[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
5327
|
-
continue;
|
|
5328
|
-
}
|
|
5329
|
-
/* 直接赋值 */
|
|
5330
|
-
target[targetKeyName] = sourceValue;
|
|
5331
|
-
}
|
|
5624
|
+
/**
|
|
5625
|
+
* JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
|
|
5626
|
+
* @param target 目标数据
|
|
5627
|
+
* @param source 源数据
|
|
5628
|
+
* @param isAdd 是否可以追加键,默认false
|
|
5629
|
+
* @example
|
|
5630
|
+
* Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
|
|
5631
|
+
* >
|
|
5632
|
+
* {
|
|
5633
|
+
"1": 1,
|
|
5634
|
+
"2": {
|
|
5635
|
+
"3": 4
|
|
5332
5636
|
}
|
|
5333
5637
|
}
|
|
5334
|
-
|
|
5335
|
-
|
|
5638
|
+
*/
|
|
5639
|
+
assign = commonUtil.assign.bind(commonUtil);
|
|
5336
5640
|
async asyncReplaceAll(string, pattern, asyncFn) {
|
|
5337
5641
|
let UtilsContext = this;
|
|
5338
5642
|
if (typeof string !== "string") {
|
|
@@ -5375,7 +5679,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5375
5679
|
* ajax劫持库,支持xhr和fetch劫持。
|
|
5376
5680
|
* + 来源:https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
|
|
5377
5681
|
* + 作者:cxxjackie
|
|
5378
|
-
* + 版本:1.4.
|
|
5682
|
+
* + 版本:1.4.6
|
|
5379
5683
|
* + 旧版本:1.2.4
|
|
5380
5684
|
* + 文档:https://scriptcat.org/zh-CN/script-show-page/637/
|
|
5381
5685
|
* @param useOldVersion 是否使用旧版本,默认false
|
|
@@ -5385,7 +5689,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5385
5689
|
return AjaxHooker1_2_4();
|
|
5386
5690
|
}
|
|
5387
5691
|
else {
|
|
5388
|
-
return
|
|
5692
|
+
return ajaxHooker();
|
|
5389
5693
|
}
|
|
5390
5694
|
};
|
|
5391
5695
|
canvasClickByPosition(canvasElement, clientX = 0, clientY = 0, view = globalThis) {
|
|
@@ -5485,19 +5789,11 @@ System.register('Utils', [], (function (exports) {
|
|
|
5485
5789
|
* @returns
|
|
5486
5790
|
*/
|
|
5487
5791
|
ColorConversion = ColorConversion;
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
return null;
|
|
5494
|
-
let clone = obj instanceof Array ? [] : {};
|
|
5495
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
5496
|
-
clone[key] =
|
|
5497
|
-
typeof value === "object" ? UtilsContext.deepClone(value) : value;
|
|
5498
|
-
}
|
|
5499
|
-
return clone;
|
|
5500
|
-
}
|
|
5792
|
+
/**
|
|
5793
|
+
* 深拷贝
|
|
5794
|
+
* @param obj 对象
|
|
5795
|
+
*/
|
|
5796
|
+
deepClone = commonUtil.deepClone.bind(commonUtil);
|
|
5501
5797
|
debounce(fn, delay = 0) {
|
|
5502
5798
|
let timer = null;
|
|
5503
5799
|
let UtilsContext = this;
|
|
@@ -5520,7 +5816,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
5520
5816
|
throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
|
|
5521
5817
|
}
|
|
5522
5818
|
let result = false;
|
|
5523
|
-
let needRemoveDOM =
|
|
5819
|
+
let needRemoveDOM = domUtils.closest(element, targetSelector);
|
|
5524
5820
|
if (needRemoveDOM) {
|
|
5525
5821
|
needRemoveDOM.remove();
|
|
5526
5822
|
result = true;
|
|
@@ -6508,9 +6804,17 @@ System.register('Utils', [], (function (exports) {
|
|
|
6508
6804
|
throw new TypeError("参数1类型错误" + typeof firstArg);
|
|
6509
6805
|
}
|
|
6510
6806
|
}
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6807
|
+
/**
|
|
6808
|
+
* 判断对象是否是元素
|
|
6809
|
+
* @param target
|
|
6810
|
+
* @returns
|
|
6811
|
+
* + true 是元素
|
|
6812
|
+
* + false 不是元素
|
|
6813
|
+
* @example
|
|
6814
|
+
* Utils.isDOM(document.querySelector("a"))
|
|
6815
|
+
* > true
|
|
6816
|
+
*/
|
|
6817
|
+
isDOM = commonUtil.isDOM.bind(commonUtil);
|
|
6514
6818
|
isFullscreenEnabled() {
|
|
6515
6819
|
return !!(this.windowApi.document.fullscreenEnabled ||
|
|
6516
6820
|
this.windowApi.document.webkitFullScreenEnabled ||
|
|
@@ -6701,52 +7005,62 @@ System.register('Utils', [], (function (exports) {
|
|
|
6701
7005
|
}
|
|
6702
7006
|
return result;
|
|
6703
7007
|
}
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
6740
|
-
|
|
6741
|
-
|
|
6742
|
-
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
7008
|
+
/**
|
|
7009
|
+
* 判断对象是否不为空
|
|
7010
|
+
* @returns {boolean}
|
|
7011
|
+
* + true 不为空
|
|
7012
|
+
* + false 为空
|
|
7013
|
+
* @example
|
|
7014
|
+
* Utils.isNotNull("123");
|
|
7015
|
+
* > true
|
|
7016
|
+
*/
|
|
7017
|
+
isNotNull = commonUtil.isNotNull.bind(commonUtil);
|
|
7018
|
+
/**
|
|
7019
|
+
* 判断对象或数据是否为空
|
|
7020
|
+
* + `String`判空的值,如 ""、"null"、"undefined"、" "
|
|
7021
|
+
* + `Number`判空的值,如 0
|
|
7022
|
+
* + `Object`判空的值,如 {}、null、undefined
|
|
7023
|
+
* + `Array`(存在属性Symbol.iterator)判空的值,如 []
|
|
7024
|
+
* + `Boolean`判空的值,如false
|
|
7025
|
+
* + `Function`判空的值,如()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){}
|
|
7026
|
+
* @returns
|
|
7027
|
+
* + true 为空
|
|
7028
|
+
* + false 不为空
|
|
7029
|
+
* @example
|
|
7030
|
+
Utils.isNull({});
|
|
7031
|
+
> true
|
|
7032
|
+
* @example
|
|
7033
|
+
Utils.isNull([]);
|
|
7034
|
+
> true
|
|
7035
|
+
* @example
|
|
7036
|
+
Utils.isNull(" ");
|
|
7037
|
+
> true
|
|
7038
|
+
* @example
|
|
7039
|
+
Utils.isNull(function(){});
|
|
7040
|
+
> true
|
|
7041
|
+
* @example
|
|
7042
|
+
Utils.isNull(()=>{}));
|
|
7043
|
+
> true
|
|
7044
|
+
* @example
|
|
7045
|
+
Utils.isNull("undefined");
|
|
7046
|
+
> true
|
|
7047
|
+
* @example
|
|
7048
|
+
Utils.isNull("null");
|
|
7049
|
+
> true
|
|
7050
|
+
* @example
|
|
7051
|
+
Utils.isNull(" ", false);
|
|
7052
|
+
> true
|
|
7053
|
+
* @example
|
|
7054
|
+
Utils.isNull([1],[]);
|
|
7055
|
+
> false
|
|
7056
|
+
* @example
|
|
7057
|
+
Utils.isNull([],[1]);
|
|
7058
|
+
> false
|
|
7059
|
+
* @example
|
|
7060
|
+
Utils.isNull(false,[123]);
|
|
7061
|
+
> false
|
|
7062
|
+
**/
|
|
7063
|
+
isNull = commonUtil.isNull.bind(commonUtil);
|
|
6750
7064
|
isThemeDark() {
|
|
6751
7065
|
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
6752
7066
|
.matches;
|
|
@@ -6936,36 +7250,36 @@ System.register('Utils', [], (function (exports) {
|
|
|
6936
7250
|
* + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
|
|
6937
7251
|
* + false (默认) 不生效
|
|
6938
7252
|
*/
|
|
6939
|
-
subtree:
|
|
7253
|
+
subtree: void 0,
|
|
6940
7254
|
/**
|
|
6941
7255
|
* + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
|
|
6942
7256
|
* + false (默认) 不生效
|
|
6943
7257
|
*/
|
|
6944
|
-
childList:
|
|
7258
|
+
childList: void 0,
|
|
6945
7259
|
/**
|
|
6946
7260
|
* + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
|
|
6947
7261
|
* + false (默认) 不生效
|
|
6948
7262
|
*/
|
|
6949
|
-
attributes:
|
|
7263
|
+
attributes: void 0,
|
|
6950
7264
|
/**
|
|
6951
7265
|
* 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
|
|
6952
7266
|
*/
|
|
6953
|
-
attributeFilter:
|
|
7267
|
+
attributeFilter: void 0,
|
|
6954
7268
|
/**
|
|
6955
7269
|
* + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
|
|
6956
7270
|
* + false (默认) 不生效
|
|
6957
7271
|
*/
|
|
6958
|
-
attributeOldValue:
|
|
7272
|
+
attributeOldValue: void 0,
|
|
6959
7273
|
/**
|
|
6960
7274
|
* + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
|
|
6961
7275
|
* + false (默认) 不生效
|
|
6962
7276
|
*/
|
|
6963
|
-
characterData:
|
|
7277
|
+
characterData: void 0,
|
|
6964
7278
|
/**
|
|
6965
7279
|
* + true 记录前一个被监听的节点中发生的文本变化
|
|
6966
7280
|
* + false (默认) 不生效
|
|
6967
7281
|
*/
|
|
6968
|
-
characterDataOldValue:
|
|
7282
|
+
characterDataOldValue: void 0,
|
|
6969
7283
|
},
|
|
6970
7284
|
immediate: false,
|
|
6971
7285
|
};
|
|
@@ -7541,7 +7855,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
7541
7855
|
}
|
|
7542
7856
|
return new Promise((resolve) => {
|
|
7543
7857
|
UtilsContext.workerSetTimeout(() => {
|
|
7544
|
-
resolve(
|
|
7858
|
+
resolve(void 0);
|
|
7545
7859
|
}, delayTime);
|
|
7546
7860
|
});
|
|
7547
7861
|
}
|
|
@@ -7555,7 +7869,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
7555
7869
|
return mouseEvent;
|
|
7556
7870
|
}
|
|
7557
7871
|
let sliderElement = typeof selector === "string"
|
|
7558
|
-
?
|
|
7872
|
+
? domUtils.selector(selector)
|
|
7559
7873
|
: selector;
|
|
7560
7874
|
if (!(sliderElement instanceof Node) ||
|
|
7561
7875
|
!(sliderElement instanceof Element)) {
|
|
@@ -7765,47 +8079,15 @@ System.register('Utils', [], (function (exports) {
|
|
|
7765
8079
|
}
|
|
7766
8080
|
return newTargetString;
|
|
7767
8081
|
}
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
UtilsContext.tryCatch()
|
|
7778
|
-
.error(() => {
|
|
7779
|
-
try {
|
|
7780
|
-
result = UtilsContext.windowApi.window.eval("(" + data + ")");
|
|
7781
|
-
}
|
|
7782
|
-
catch (error2) {
|
|
7783
|
-
if (typeof errorCallBack === "function") {
|
|
7784
|
-
errorCallBack(error2);
|
|
7785
|
-
}
|
|
7786
|
-
}
|
|
7787
|
-
})
|
|
7788
|
-
.run(() => {
|
|
7789
|
-
if (data &&
|
|
7790
|
-
/^[\],:{}\s]*$/.test(data
|
|
7791
|
-
.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
|
|
7792
|
-
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
|
|
7793
|
-
.replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
|
|
7794
|
-
result = new Function("return " + data)();
|
|
7795
|
-
}
|
|
7796
|
-
else {
|
|
7797
|
-
if (typeof errorCallBack === "function") {
|
|
7798
|
-
errorCallBack(new Error("target is not a JSON"));
|
|
7799
|
-
}
|
|
7800
|
-
}
|
|
7801
|
-
});
|
|
7802
|
-
})
|
|
7803
|
-
.run(() => {
|
|
7804
|
-
data = data.trim();
|
|
7805
|
-
result = JSON.parse(data);
|
|
7806
|
-
});
|
|
7807
|
-
return result;
|
|
7808
|
-
}
|
|
8082
|
+
/**
|
|
8083
|
+
* 字符串转Object对象,类似'{"test":""}' => {"test":""}
|
|
8084
|
+
* @param data
|
|
8085
|
+
* @param errorCallBack (可选)错误回调
|
|
8086
|
+
* @example
|
|
8087
|
+
* Utils.toJSON("{123:123}")
|
|
8088
|
+
* > {123:123}
|
|
8089
|
+
*/
|
|
8090
|
+
toJSON = commonUtil.toJSON.bind(commonUtil);
|
|
7809
8091
|
toSearchParamsStr(obj, addPrefix) {
|
|
7810
8092
|
let UtilsContext = this;
|
|
7811
8093
|
let searhParamsStr = "";
|
|
@@ -7916,7 +8198,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
7916
8198
|
}
|
|
7917
8199
|
waitNode(...args) {
|
|
7918
8200
|
// 过滤掉undefined
|
|
7919
|
-
args = args.filter((arg) => arg !==
|
|
8201
|
+
args = args.filter((arg) => arg !== void 0);
|
|
7920
8202
|
let UtilsContext = this;
|
|
7921
8203
|
// 选择器
|
|
7922
8204
|
let selector = args[0];
|
|
@@ -7971,7 +8253,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
7971
8253
|
if (Array.isArray(selector)) {
|
|
7972
8254
|
let result = [];
|
|
7973
8255
|
for (let index = 0; index < selector.length; index++) {
|
|
7974
|
-
let node =
|
|
8256
|
+
let node = domUtils.selector(selector[index]);
|
|
7975
8257
|
if (node) {
|
|
7976
8258
|
result.push(node);
|
|
7977
8259
|
}
|
|
@@ -7984,7 +8266,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
7984
8266
|
return selector();
|
|
7985
8267
|
}
|
|
7986
8268
|
else {
|
|
7987
|
-
return
|
|
8269
|
+
return domUtils.selector(selector, parent);
|
|
7988
8270
|
}
|
|
7989
8271
|
}
|
|
7990
8272
|
return UtilsContext.wait(() => {
|
|
@@ -8005,7 +8287,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
8005
8287
|
}
|
|
8006
8288
|
waitAnyNode(...args) {
|
|
8007
8289
|
// 过滤掉undefined
|
|
8008
|
-
args = args.filter((arg) => arg !==
|
|
8290
|
+
args = args.filter((arg) => arg !== void 0);
|
|
8009
8291
|
let UtilsContext = this;
|
|
8010
8292
|
// 选择器
|
|
8011
8293
|
let selectorList = args[0];
|
|
@@ -8061,7 +8343,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
8061
8343
|
}
|
|
8062
8344
|
waitNodeList(...args) {
|
|
8063
8345
|
// 过滤掉undefined
|
|
8064
|
-
args = args.filter((arg) => arg !==
|
|
8346
|
+
args = args.filter((arg) => arg !== void 0);
|
|
8065
8347
|
let UtilsContext = this;
|
|
8066
8348
|
// 选择器数组
|
|
8067
8349
|
let selector = args[0];
|
|
@@ -8114,7 +8396,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
8114
8396
|
if (Array.isArray(selector)) {
|
|
8115
8397
|
let result = [];
|
|
8116
8398
|
for (let index = 0; index < selector.length; index++) {
|
|
8117
|
-
let nodeList =
|
|
8399
|
+
let nodeList = domUtils.selectorAll(selector[index], parent);
|
|
8118
8400
|
if (nodeList.length) {
|
|
8119
8401
|
result.push(nodeList);
|
|
8120
8402
|
}
|
|
@@ -8124,7 +8406,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
8124
8406
|
}
|
|
8125
8407
|
}
|
|
8126
8408
|
else {
|
|
8127
|
-
let nodeList =
|
|
8409
|
+
let nodeList = domUtils.selectorAll(selector, parent);
|
|
8128
8410
|
if (nodeList.length) {
|
|
8129
8411
|
return nodeList;
|
|
8130
8412
|
}
|
|
@@ -8148,7 +8430,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
8148
8430
|
}
|
|
8149
8431
|
waitAnyNodeList(...args) {
|
|
8150
8432
|
// 过滤掉undefined
|
|
8151
|
-
args = args.filter((arg) => arg !==
|
|
8433
|
+
args = args.filter((arg) => arg !== void 0);
|
|
8152
8434
|
let UtilsContext = this;
|
|
8153
8435
|
// 选择器数组
|
|
8154
8436
|
let selectorList = args[0];
|
|
@@ -8433,17 +8715,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
8433
8715
|
* @param target 需要覆盖的对象
|
|
8434
8716
|
* @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
|
|
8435
8717
|
*/
|
|
8436
|
-
coverObjectFunctionThis(
|
|
8437
|
-
if (typeof target !== "object" || target === null) {
|
|
8438
|
-
throw new Error("target must be object");
|
|
8439
|
-
}
|
|
8440
|
-
objectThis = objectThis || target;
|
|
8441
|
-
Object.keys(target).forEach((key) => {
|
|
8442
|
-
if (typeof target[key] === "function") {
|
|
8443
|
-
target[key] = target[key].bind(objectThis);
|
|
8444
|
-
}
|
|
8445
|
-
});
|
|
8446
|
-
}
|
|
8718
|
+
coverObjectFunctionThis = commonUtil.coverObjectFunctionThis.bind(commonUtil);
|
|
8447
8719
|
/**
|
|
8448
8720
|
* 生成uuid
|
|
8449
8721
|
* @example
|
|
@@ -8484,7 +8756,7 @@ System.register('Utils', [], (function (exports) {
|
|
|
8484
8756
|
workerClearTimeout(timeId) {
|
|
8485
8757
|
try {
|
|
8486
8758
|
if (timeId != null) {
|
|
8487
|
-
clearTimeout(timeId);
|
|
8759
|
+
clearTimeout$1(timeId);
|
|
8488
8760
|
}
|
|
8489
8761
|
}
|
|
8490
8762
|
catch (error) {
|