owoHackUrl.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. (function(xhr) {
  2. var XHR = XMLHttpRequest.prototype;
  3. var open = XHR.open;
  4. var send = XHR.send;
  5. var setRequestHeader = XHR.setRequestHeader;
  6. XHR.open = function(method, url) {
  7. this._method = method;
  8. this._url = url;
  9. this._requestHeaders = {};
  10. this._startTime = (new Date()).toISOString();
  11. return open.apply(this, arguments);
  12. };
  13. XHR.setRequestHeader = function(header, value) {
  14. this._requestHeaders[header] = value;
  15. return setRequestHeader.apply(this, arguments);
  16. };
  17. XHR.send = function(postData) {
  18. this.addEventListener('load', function() {
  19. var endTime = (new Date()).toISOString();
  20. var myUrl = this._url ? this._url.toLowerCase() : this._url;
  21. if(myUrl) {
  22. if (postData) {
  23. if (typeof postData === 'string') {
  24. try {
  25. // here you get the REQUEST HEADERS, in JSON format, so you can also use JSON.parse
  26. this._requestHeaders = postData;
  27. } catch(err) {
  28. console.log('Request Header JSON decode failed, transfer_encoding field could be base64');
  29. console.log(err);
  30. }
  31. } else if (typeof postData === 'object' || typeof postData === 'array' || typeof postData === 'number' || typeof postData === 'boolean') {
  32. // do something if you need
  33. }
  34. }
  35. // here you get the RESPONSE HEADERS
  36. var responseHeaders = this.getAllResponseHeaders();
  37. if ( this.responseType != 'blob' && this.responseText) {
  38. // responseText is string or null
  39. try {
  40. // here you get RESPONSE TEXT (BODY), in JSON format, so you can use JSON.parse
  41. var arr = this.responseText;
  42. // printing url, request headers, response headers, response body, to console
  43. // console.log(this._url);
  44. // console.log(JSON.parse(this._requestHeaders));
  45. // console.log(responseHeaders);
  46. console.log(myUrl);
  47. if (window.owoHackUrl) {
  48. for (const key in window.owoHackUrl) {
  49. if (Object.hasOwnProperty.call(window.owoHackUrl, key)) {
  50. const element = window.owoHackUrl[key];
  51. if (myUrl.includes(key)) {
  52. if (element) element(arr)
  53. }
  54. }
  55. }
  56. }
  57. if (window.owoHackUrlSend) {
  58. for (const key in window.owoHackUrlSend) {
  59. if (Object.hasOwnProperty.call(window.owoHackUrlSend, key)) {
  60. const element = window.owoHackUrlSend[key];
  61. if (myUrl.includes(key)) {
  62. if (element) element(postData, myUrl)
  63. }
  64. }
  65. }
  66. }
  67. } catch(err) {
  68. console.log("Error in responseType try catch");
  69. console.log(err);
  70. }
  71. }
  72. }
  73. });
  74. return send.apply(this, arguments);
  75. };
  76. })(XMLHttpRequest);