@whitesev/utils 1.5.6 → 1.5.8

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.
@@ -468,26 +468,43 @@ System.register('Utils', [], (function (exports) {
468
468
  // @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
469
469
 
470
470
  const AjaxHooker = function () {
471
- return function() {
472
- const version = '1.4.3';
471
+ return (function () {
472
+ const version = "1.4.3";
473
473
  const hookInst = {
474
474
  hookFns: [],
475
- filters: []
475
+ filters: [],
476
476
  };
477
477
  const win = window.unsafeWindow || document.defaultView || window;
478
478
  let winAh = win.__ajaxHooker;
479
479
  const resProto = win.Response.prototype;
480
- const xhrResponses = ['response', 'responseText', 'responseXML'];
481
- const fetchResponses = ['arrayBuffer', 'blob', 'formData', 'json', 'text'];
482
- const fetchInitProps = ['method', 'headers', 'body', 'mode', 'credentials', 'cache', 'redirect',
483
- 'referrer', 'referrerPolicy', 'integrity', 'keepalive', 'signal', 'priority'];
484
- const xhrAsyncEvents = ['readystatechange', 'load', 'loadend'];
485
- const getType = ({}).toString.call.bind(({}).toString);
480
+ const xhrResponses = ["response", "responseText", "responseXML"];
481
+ const fetchResponses = ["arrayBuffer", "blob", "formData", "json", "text"];
482
+ const fetchInitProps = [
483
+ "method",
484
+ "headers",
485
+ "body",
486
+ "mode",
487
+ "credentials",
488
+ "cache",
489
+ "redirect",
490
+ "referrer",
491
+ "referrerPolicy",
492
+ "integrity",
493
+ "keepalive",
494
+ "signal",
495
+ "priority",
496
+ ];
497
+ const xhrAsyncEvents = ["readystatechange", "load", "loadend"];
498
+ const getType = {}.toString.call.bind({}.toString);
486
499
  const getDescriptor = Object.getOwnPropertyDescriptor.bind(Object);
487
500
  const emptyFn = () => {};
488
- const errorFn = e => console.error(e);
501
+ const errorFn = (e) => console.error(e);
489
502
  function isThenable(obj) {
490
- return obj && ['object', 'function'].includes(typeof obj) && typeof obj.then === 'function';
503
+ return (
504
+ obj &&
505
+ ["object", "function"].includes(typeof obj) &&
506
+ typeof obj.then === "function"
507
+ );
491
508
  }
492
509
  function catchError(fn, ...args) {
493
510
  try {
@@ -503,7 +520,7 @@ System.register('Utils', [], (function (exports) {
503
520
  configurable: true,
504
521
  enumerable: true,
505
522
  get: getter,
506
- set: setter
523
+ set: setter,
507
524
  });
508
525
  }
509
526
  function readonly(obj, prop, value = obj[prop]) {
@@ -514,27 +531,28 @@ System.register('Utils', [], (function (exports) {
514
531
  configurable: true,
515
532
  enumerable: true,
516
533
  writable: true,
517
- value: value
534
+ value: value,
518
535
  });
519
536
  }
520
537
  function parseHeaders(obj) {
521
538
  const headers = {};
522
539
  switch (getType(obj)) {
523
- case '[object String]':
540
+ case "[object String]":
524
541
  for (const line of obj.trim().split(/[\r\n]+/)) {
525
542
  const [header, value] = line.split(/\s*:\s*/);
526
543
  if (!header) break;
527
544
  const lheader = header.toLowerCase();
528
- headers[lheader] = lheader in headers ? `${headers[lheader]}, ${value}` : value;
545
+ headers[lheader] =
546
+ lheader in headers ? `${headers[lheader]}, ${value}` : value;
529
547
  }
530
548
  break;
531
- case '[object Headers]':
549
+ case "[object Headers]":
532
550
  for (const [key, val] of obj) {
533
551
  headers[key] = val;
534
552
  }
535
553
  break;
536
- case '[object Object]':
537
- return {...obj};
554
+ case "[object Object]":
555
+ return { ...obj };
538
556
  }
539
557
  return headers;
540
558
  }
@@ -550,104 +568,142 @@ System.register('Utils', [], (function (exports) {
550
568
  class AHRequest {
551
569
  constructor(request) {
552
570
  this.request = request;
553
- this.requestClone = {...this.request};
571
+ this.requestClone = { ...this.request };
554
572
  }
555
573
  shouldFilter(filters) {
556
- const {type, url, method, async} = this.request;
557
- return filters.length && !filters.find(obj => {
558
- switch (true) {
559
- case obj.type && obj.type !== type:
560
- case getType(obj.url) === '[object String]' && !url.includes(obj.url):
561
- case getType(obj.url) === '[object RegExp]' && !obj.url.test(url):
562
- case obj.method && obj.method.toUpperCase() !== method.toUpperCase():
563
- case 'async' in obj && obj.async !== async:
564
- return false;
565
- }
566
- return true;
567
- });
574
+ const { type, url, method, async } = this.request;
575
+ return (
576
+ filters.length &&
577
+ !filters.find((obj) => {
578
+ switch (true) {
579
+ case obj.type && obj.type !== type:
580
+ case getType(obj.url) === "[object String]" &&
581
+ !url.includes(obj.url):
582
+ case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
583
+ case obj.method &&
584
+ obj.method.toUpperCase() !== method.toUpperCase():
585
+ case "async" in obj && obj.async !== async:
586
+ return false;
587
+ }
588
+ return true;
589
+ })
590
+ );
568
591
  }
569
592
  waitForRequestKeys() {
570
- const requestKeys = ['url', 'method', 'abort', 'headers', 'data'];
593
+ const requestKeys = ["url", "method", "abort", "headers", "data"];
571
594
  if (!this.request.async) {
572
- win.__ajaxHooker.hookInsts.forEach(({hookFns, filters}) => {
595
+ win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
573
596
  if (this.shouldFilter(filters)) return;
574
- hookFns.forEach(fn => {
575
- if (getType(fn) === '[object Function]') catchError(fn, this.request);
597
+ hookFns.forEach((fn) => {
598
+ if (getType(fn) === "[object Function]")
599
+ catchError(fn, this.request);
576
600
  });
577
- requestKeys.forEach(key => {
578
- if (isThenable(this.request[key])) this.request[key] = this.requestClone[key];
601
+ requestKeys.forEach((key) => {
602
+ if (isThenable(this.request[key]))
603
+ this.request[key] = this.requestClone[key];
579
604
  });
580
605
  });
581
606
  return new SyncThenable();
582
607
  }
583
608
  const promises = [];
584
- win.__ajaxHooker.hookInsts.forEach(({hookFns, filters}) => {
609
+ win.__ajaxHooker.hookInsts.forEach(({ hookFns, filters }) => {
585
610
  if (this.shouldFilter(filters)) return;
586
- promises.push(Promise.all(hookFns.map(fn => catchError(fn, this.request))).then(() =>
587
- Promise.all(requestKeys.map(key => Promise.resolve(this.request[key]).then(
588
- val => this.request[key] = val,
589
- () => this.request[key] = this.requestClone[key]
590
- )))
591
- ));
611
+ promises.push(
612
+ Promise.all(hookFns.map((fn) => catchError(fn, this.request))).then(
613
+ () =>
614
+ Promise.all(
615
+ requestKeys.map((key) =>
616
+ Promise.resolve(this.request[key]).then(
617
+ (val) => (this.request[key] = val),
618
+ () => (this.request[key] = this.requestClone[key])
619
+ )
620
+ )
621
+ )
622
+ )
623
+ );
592
624
  });
593
625
  return Promise.all(promises);
594
626
  }
595
627
  waitForResponseKeys(response) {
596
- const responseKeys = this.request.type === 'xhr' ? xhrResponses : fetchResponses;
628
+ const responseKeys =
629
+ this.request.type === "xhr" ? xhrResponses : fetchResponses;
597
630
  if (!this.request.async) {
598
- if (getType(this.request.response) === '[object Function]') {
631
+ if (getType(this.request.response) === "[object Function]") {
599
632
  catchError(this.request.response, response);
600
- responseKeys.forEach(key => {
601
- if ('get' in getDescriptor(response, key) || isThenable(response[key])) {
633
+ responseKeys.forEach((key) => {
634
+ if (
635
+ "get" in getDescriptor(response, key) ||
636
+ isThenable(response[key])
637
+ ) {
602
638
  delete response[key];
603
639
  }
604
640
  });
605
641
  }
606
642
  return new SyncThenable();
607
643
  }
608
- return Promise.resolve(catchError(this.request.response, response)).then(() =>
609
- Promise.all(responseKeys.map(key => {
610
- const descriptor = getDescriptor(response, key);
611
- if (descriptor && 'value' in descriptor) {
612
- return Promise.resolve(descriptor.value).then(
613
- val => response[key] = val,
614
- () => delete response[key]
615
- );
616
- } else {
617
- delete response[key];
618
- }
619
- }))
644
+ return Promise.resolve(
645
+ catchError(this.request.response, response)
646
+ ).then(() =>
647
+ Promise.all(
648
+ responseKeys.map((key) => {
649
+ const descriptor = getDescriptor(response, key);
650
+ if (descriptor && "value" in descriptor) {
651
+ return Promise.resolve(descriptor.value).then(
652
+ (val) => (response[key] = val),
653
+ () => delete response[key]
654
+ );
655
+ } else {
656
+ delete response[key];
657
+ }
658
+ })
659
+ )
620
660
  );
621
661
  }
622
662
  }
623
663
  const proxyHandler = {
624
664
  get(target, prop) {
625
665
  const descriptor = getDescriptor(target, prop);
626
- if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.get) return target[prop];
666
+ if (
667
+ descriptor &&
668
+ !descriptor.configurable &&
669
+ !descriptor.writable &&
670
+ !descriptor.get
671
+ )
672
+ return target[prop];
627
673
  const ah = target.__ajaxHooker;
628
674
  if (ah && ah.proxyProps) {
629
675
  if (prop in ah.proxyProps) {
630
676
  const pDescriptor = ah.proxyProps[prop];
631
- if ('get' in pDescriptor) return pDescriptor.get();
632
- if (typeof pDescriptor.value === 'function') return pDescriptor.value.bind(ah);
677
+ if ("get" in pDescriptor) return pDescriptor.get();
678
+ if (typeof pDescriptor.value === "function")
679
+ return pDescriptor.value.bind(ah);
633
680
  return pDescriptor.value;
634
681
  }
635
- if (typeof target[prop] === 'function') return target[prop].bind(target);
682
+ if (typeof target[prop] === "function")
683
+ return target[prop].bind(target);
636
684
  }
637
685
  return target[prop];
638
686
  },
639
687
  set(target, prop, value) {
640
688
  const descriptor = getDescriptor(target, prop);
641
- if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.set) return true;
689
+ if (
690
+ descriptor &&
691
+ !descriptor.configurable &&
692
+ !descriptor.writable &&
693
+ !descriptor.set
694
+ )
695
+ return true;
642
696
  const ah = target.__ajaxHooker;
643
697
  if (ah && ah.proxyProps && prop in ah.proxyProps) {
644
698
  const pDescriptor = ah.proxyProps[prop];
645
- pDescriptor.set ? pDescriptor.set(value) : (pDescriptor.value = value);
699
+ pDescriptor.set
700
+ ? pDescriptor.set(value)
701
+ : (pDescriptor.value = value);
646
702
  } else {
647
703
  target[prop] = value;
648
704
  }
649
705
  return true;
650
- }
706
+ },
651
707
  };
652
708
  class XhrHooker {
653
709
  constructor(xhr) {
@@ -657,86 +713,113 @@ System.register('Utils', [], (function (exports) {
657
713
  proxyXhr: new Proxy(xhr, proxyHandler),
658
714
  resThenable: new SyncThenable(),
659
715
  proxyProps: {},
660
- proxyEvents: {}
716
+ proxyEvents: {},
661
717
  });
662
- xhr.addEventListener('readystatechange', e => {
663
- if (ah.proxyXhr.readyState === 4 && ah.request && typeof ah.request.response === 'function') {
718
+ xhr.addEventListener("readystatechange", (e) => {
719
+ if (
720
+ ah.proxyXhr.readyState === 4 &&
721
+ ah.request &&
722
+ typeof ah.request.response === "function"
723
+ ) {
664
724
  const response = {
665
725
  finalUrl: ah.proxyXhr.responseURL,
666
726
  status: ah.proxyXhr.status,
667
- responseHeaders: parseHeaders(ah.proxyXhr.getAllResponseHeaders())
727
+ responseHeaders: parseHeaders(
728
+ ah.proxyXhr.getAllResponseHeaders()
729
+ ),
668
730
  };
669
731
  const tempValues = {};
670
732
  for (const key of xhrResponses) {
671
733
  try {
672
734
  tempValues[key] = ah.originalXhr[key];
673
735
  } catch (err) {}
674
- defineProp(response, key, () => {
675
- return response[key] = tempValues[key];
676
- }, val => {
677
- delete response[key];
678
- response[key] = val;
679
- });
736
+ defineProp(
737
+ response,
738
+ key,
739
+ () => {
740
+ return (response[key] = tempValues[key]);
741
+ },
742
+ (val) => {
743
+ delete response[key];
744
+ response[key] = val;
745
+ }
746
+ );
680
747
  }
681
- ah.resThenable = new AHRequest(ah.request).waitForResponseKeys(response).then(() => {
682
- for (const key of xhrResponses) {
683
- ah.proxyProps[key] = {get: () => {
684
- if (!(key in response)) response[key] = tempValues[key];
685
- return response[key];
686
- }};
687
- }
688
- });
748
+ ah.resThenable = new AHRequest(ah.request)
749
+ .waitForResponseKeys(response)
750
+ .then(() => {
751
+ for (const key of xhrResponses) {
752
+ ah.proxyProps[key] = {
753
+ get: () => {
754
+ if (!(key in response)) response[key] = tempValues[key];
755
+ return response[key];
756
+ },
757
+ };
758
+ }
759
+ });
689
760
  }
690
761
  ah.dispatchEvent(e);
691
762
  });
692
- xhr.addEventListener('load', e => ah.dispatchEvent(e));
693
- xhr.addEventListener('loadend', e => ah.dispatchEvent(e));
763
+ xhr.addEventListener("load", (e) => ah.dispatchEvent(e));
764
+ xhr.addEventListener("loadend", (e) => ah.dispatchEvent(e));
694
765
  for (const evt of xhrAsyncEvents) {
695
- const onEvt = 'on' + evt;
766
+ const onEvt = "on" + evt;
696
767
  ah.proxyProps[onEvt] = {
697
768
  get: () => ah.proxyEvents[onEvt] || null,
698
- set: val => ah.addEvent(onEvt, val)
769
+ set: (val) => ah.addEvent(onEvt, val),
699
770
  };
700
771
  }
701
- for (const method of ['setRequestHeader', 'addEventListener', 'removeEventListener', 'open', 'send']) {
702
- ah.proxyProps[method] = {value: ah[method]};
772
+ for (const method of [
773
+ "setRequestHeader",
774
+ "addEventListener",
775
+ "removeEventListener",
776
+ "open",
777
+ "send",
778
+ ]) {
779
+ ah.proxyProps[method] = { value: ah[method] };
703
780
  }
704
781
  }
705
782
  toJSON() {} // Converting circular structure to JSON
706
783
  addEvent(type, event) {
707
- if (type.startsWith('on')) {
708
- this.proxyEvents[type] = typeof event === 'function' ? event : null;
784
+ if (type.startsWith("on")) {
785
+ this.proxyEvents[type] = typeof event === "function" ? event : null;
709
786
  } else {
710
- if (typeof event === 'object' && event !== null) event = event.handleEvent;
711
- if (typeof event !== 'function') return;
787
+ if (typeof event === "object" && event !== null)
788
+ event = event.handleEvent;
789
+ if (typeof event !== "function") return;
712
790
  this.proxyEvents[type] = this.proxyEvents[type] || new Set();
713
791
  this.proxyEvents[type].add(event);
714
792
  }
715
793
  }
716
794
  removeEvent(type, event) {
717
- if (type.startsWith('on')) {
795
+ if (type.startsWith("on")) {
718
796
  this.proxyEvents[type] = null;
719
797
  } else {
720
- if (typeof event === 'object' && event !== null) event = event.handleEvent;
798
+ if (typeof event === "object" && event !== null)
799
+ event = event.handleEvent;
721
800
  this.proxyEvents[type] && this.proxyEvents[type].delete(event);
722
801
  }
723
802
  }
724
803
  dispatchEvent(e) {
725
804
  e.stopImmediatePropagation = stopImmediatePropagation;
726
- defineProp(e, 'target', () => this.proxyXhr);
727
- defineProp(e, 'currentTarget', () => this.proxyXhr);
728
- this.proxyEvents[e.type] && this.proxyEvents[e.type].forEach(fn => {
729
- this.resThenable.then(() => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e));
730
- });
805
+ defineProp(e, "target", () => this.proxyXhr);
806
+ defineProp(e, "currentTarget", () => this.proxyXhr);
807
+ this.proxyEvents[e.type] &&
808
+ this.proxyEvents[e.type].forEach((fn) => {
809
+ this.resThenable.then(
810
+ () => !e.ajaxHooker_isStopped && fn.call(this.proxyXhr, e)
811
+ );
812
+ });
731
813
  if (e.ajaxHooker_isStopped) return;
732
- const onEvent = this.proxyEvents['on' + e.type];
814
+ const onEvent = this.proxyEvents["on" + e.type];
733
815
  onEvent && this.resThenable.then(onEvent.bind(this.proxyXhr, e));
734
816
  }
735
817
  setRequestHeader(header, value) {
736
818
  this.originalXhr.setRequestHeader(header, value);
737
819
  if (!this.request) return;
738
820
  const headers = this.request.headers;
739
- headers[header] = header in headers ? `${headers[header]}, ${value}` : value;
821
+ headers[header] =
822
+ header in headers ? `${headers[header]}, ${value}` : value;
740
823
  }
741
824
  addEventListener(...args) {
742
825
  if (xhrAsyncEvents.includes(args[0])) {
@@ -754,18 +837,24 @@ System.register('Utils', [], (function (exports) {
754
837
  }
755
838
  open(method, url, async = true, ...args) {
756
839
  this.request = {
757
- type: 'xhr',
840
+ type: "xhr",
758
841
  url: url.toString(),
759
842
  method: method.toUpperCase(),
760
843
  abort: false,
761
844
  headers: {},
762
845
  data: null,
763
846
  response: null,
764
- async: !!async
847
+ async: !!async,
765
848
  };
766
849
  this.openArgs = args;
767
850
  this.resThenable = new SyncThenable();
768
- ['responseURL', 'readyState', 'status', 'statusText', ...xhrResponses].forEach(key => {
851
+ [
852
+ "responseURL",
853
+ "readyState",
854
+ "status",
855
+ "statusText",
856
+ ...xhrResponses,
857
+ ].forEach((key) => {
769
858
  delete this.proxyProps[key];
770
859
  });
771
860
  return this.originalXhr.open(method, url, async, ...args);
@@ -778,17 +867,24 @@ System.register('Utils', [], (function (exports) {
778
867
  request.data = data;
779
868
  new AHRequest(request).waitForRequestKeys().then(() => {
780
869
  if (request.abort) {
781
- if (typeof request.response === 'function') {
870
+ if (typeof request.response === "function") {
782
871
  Object.assign(ah.proxyProps, {
783
- responseURL: {value: request.url},
784
- readyState: {value: 4},
785
- status: {value: 200},
786
- statusText: {value: 'OK'}
872
+ responseURL: { value: request.url },
873
+ readyState: { value: 4 },
874
+ status: { value: 200 },
875
+ statusText: { value: "OK" },
787
876
  });
788
- xhrAsyncEvents.forEach(evt => xhr.dispatchEvent(new Event(evt)));
877
+ xhrAsyncEvents.forEach((evt) =>
878
+ xhr.dispatchEvent(new Event(evt))
879
+ );
789
880
  }
790
881
  } else {
791
- xhr.open(request.method, request.url, request.async, ...ah.openArgs);
882
+ xhr.open(
883
+ request.method,
884
+ request.url,
885
+ request.async,
886
+ ...ah.openArgs
887
+ );
792
888
  for (const header in request.headers) {
793
889
  xhr.setRequestHeader(header, request.headers[header]);
794
890
  }
@@ -799,79 +895,87 @@ System.register('Utils', [], (function (exports) {
799
895
  }
800
896
  function fakeXHR() {
801
897
  const xhr = new winAh.realXHR();
802
- if ('__ajaxHooker' in xhr) console.warn('检测到不同版本的ajaxHooker,可能发生冲突!');
898
+ if ("__ajaxHooker" in xhr)
899
+ console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
803
900
  xhr.__ajaxHooker = new XhrHooker(xhr);
804
901
  return xhr.__ajaxHooker.proxyXhr;
805
902
  }
806
903
  fakeXHR.prototype = win.XMLHttpRequest.prototype;
807
- Object.keys(win.XMLHttpRequest).forEach(key => fakeXHR[key] = win.XMLHttpRequest[key]);
904
+ Object.keys(win.XMLHttpRequest).forEach(
905
+ (key) => (fakeXHR[key] = win.XMLHttpRequest[key])
906
+ );
808
907
  function fakeFetch(url, options = {}) {
809
908
  if (!url) return winAh.realFetch.call(win, url, options);
810
909
  return new Promise(async (resolve, reject) => {
811
910
  const init = {};
812
- if (getType(url) === '[object Request]') {
911
+ if (getType(url) === "[object Request]") {
813
912
  for (const prop of fetchInitProps) init[prop] = url[prop];
814
913
  if (url.body) init.body = await url.arrayBuffer();
815
914
  url = url.url;
816
915
  }
817
916
  url = url.toString();
818
917
  Object.assign(init, options);
819
- init.method = init.method || 'GET';
918
+ init.method = init.method || "GET";
820
919
  init.headers = init.headers || {};
821
920
  const request = {
822
- type: 'fetch',
921
+ type: "fetch",
823
922
  url: url,
824
923
  method: init.method.toUpperCase(),
825
924
  abort: false,
826
925
  headers: parseHeaders(init.headers),
827
926
  data: init.body,
828
927
  response: null,
829
- async: true
928
+ async: true,
830
929
  };
831
930
  const req = new AHRequest(request);
832
931
  await req.waitForRequestKeys();
833
932
  if (request.abort) {
834
- if (typeof request.response === 'function') {
933
+ if (typeof request.response === "function") {
835
934
  const response = {
836
935
  finalUrl: request.url,
837
936
  status: 200,
838
- responseHeaders: {}
937
+ responseHeaders: {},
839
938
  };
840
939
  await req.waitForResponseKeys(response);
841
- const key = fetchResponses.find(k => k in response);
940
+ const key = fetchResponses.find((k) => k in response);
842
941
  let val = response[key];
843
- if (key === 'json' && typeof val === 'object') {
942
+ if (key === "json" && typeof val === "object") {
844
943
  val = catchError(JSON.stringify.bind(JSON), val);
845
944
  }
846
945
  const res = new Response(val, {
847
946
  status: 200,
848
- statusText: 'OK'
947
+ statusText: "OK",
849
948
  });
850
- defineProp(res, 'type', () => 'basic');
851
- defineProp(res, 'url', () => request.url);
949
+ defineProp(res, "type", () => "basic");
950
+ defineProp(res, "url", () => request.url);
852
951
  resolve(res);
853
952
  } else {
854
- reject(new DOMException('aborted', 'AbortError'));
953
+ reject(new DOMException("aborted", "AbortError"));
855
954
  }
856
955
  return;
857
956
  }
858
957
  init.method = request.method;
859
958
  init.headers = request.headers;
860
959
  init.body = request.data;
861
- winAh.realFetch.call(win, request.url, init).then(res => {
862
- if (typeof request.response === 'function') {
960
+ winAh.realFetch.call(win, request.url, init).then((res) => {
961
+ if (typeof request.response === "function") {
863
962
  const response = {
864
963
  finalUrl: res.url,
865
964
  status: res.status,
866
- responseHeaders: parseHeaders(res.headers)
965
+ responseHeaders: parseHeaders(res.headers),
867
966
  };
868
- fetchResponses.forEach(key => res[key] = function() {
869
- if (key in response) return Promise.resolve(response[key]);
870
- return resProto[key].call(this).then(val => {
871
- response[key] = val;
872
- return req.waitForResponseKeys(response).then(() => key in response ? response[key] : val);
873
- });
874
- });
967
+ fetchResponses.forEach(
968
+ (key) =>
969
+ (res[key] = function () {
970
+ if (key in response) return Promise.resolve(response[key]);
971
+ return resProto[key].call(this).then((val) => {
972
+ response[key] = val;
973
+ return req
974
+ .waitForResponseKeys(response)
975
+ .then(() => (key in response ? response[key] : val));
976
+ });
977
+ })
978
+ );
875
979
  }
876
980
  resolve(res);
877
981
  }, reject);
@@ -884,38 +988,42 @@ System.register('Utils', [], (function (exports) {
884
988
  return res;
885
989
  }
886
990
  winAh = win.__ajaxHooker = winAh || {
887
- version, fakeXHR, fakeFetch, fakeFetchClone,
991
+ version,
992
+ fakeXHR,
993
+ fakeFetch,
994
+ fakeFetchClone,
888
995
  realXHR: win.XMLHttpRequest,
889
996
  realFetch: win.fetch,
890
997
  realFetchClone: resProto.clone,
891
- hookInsts: new Set()
998
+ hookInsts: new Set(),
892
999
  };
893
- if (winAh.version !== version) console.warn('检测到不同版本的ajaxHooker,可能发生冲突!');
1000
+ if (winAh.version !== version)
1001
+ console.warn("检测到不同版本的ajaxHooker,可能发生冲突!");
894
1002
  win.XMLHttpRequest = winAh.fakeXHR;
895
1003
  win.fetch = winAh.fakeFetch;
896
1004
  resProto.clone = winAh.fakeFetchClone;
897
1005
  winAh.hookInsts.add(hookInst);
898
1006
  return {
899
- hook: fn => hookInst.hookFns.push(fn),
900
- filter: arr => {
1007
+ hook: (fn) => hookInst.hookFns.push(fn),
1008
+ filter: (arr) => {
901
1009
  if (Array.isArray(arr)) hookInst.filters = arr;
902
1010
  },
903
1011
  protect: () => {
904
- readonly(win, 'XMLHttpRequest', winAh.fakeXHR);
905
- readonly(win, 'fetch', winAh.fakeFetch);
906
- readonly(resProto, 'clone', winAh.fakeFetchClone);
1012
+ readonly(win, "XMLHttpRequest", winAh.fakeXHR);
1013
+ readonly(win, "fetch", winAh.fakeFetch);
1014
+ readonly(resProto, "clone", winAh.fakeFetchClone);
907
1015
  },
908
1016
  unhook: () => {
909
1017
  winAh.hookInsts.delete(hookInst);
910
1018
  if (!winAh.hookInsts.size) {
911
- writable(win, 'XMLHttpRequest', winAh.realXHR);
912
- writable(win, 'fetch', winAh.realFetch);
913
- writable(resProto, 'clone', winAh.realFetchClone);
1019
+ writable(win, "XMLHttpRequest", winAh.realXHR);
1020
+ writable(win, "fetch", winAh.realFetch);
1021
+ writable(resProto, "clone", winAh.realFetchClone);
914
1022
  delete win.__ajaxHooker;
915
1023
  }
916
- }
1024
+ },
917
1025
  };
918
- }();
1026
+ })();
919
1027
  };
920
1028
 
921
1029
  class GMMenu {
@@ -3285,7 +3393,6 @@ System.register('Utils', [], (function (exports) {
3285
3393
  }
3286
3394
  }
3287
3395
 
3288
- /// <reference path="./ajaxHooker/index.d.ts" />
3289
3396
  class Utils {
3290
3397
  constructor(option) {
3291
3398
  UtilsCore.init(option);