Capture bindSNS Request and Response

Capture and store the bindSNS request and response

当前为 2024-08-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Capture bindSNS Request and Response
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Capture and store the bindSNS request and response
  6. // @match *://*/*
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Store the request and response in global variables
  16. window.bindSNSRequest = null;
  17. window.bindSNSResponse = null;
  18.  
  19. // Intercept fetch requests
  20. const originalFetch = window.fetch;
  21. window.fetch = function(...args) {
  22. const url = args[0];
  23. return originalFetch.apply(this, args).then(response => {
  24. if (url.includes("bindSNS")) {
  25. console.log("Captured bindSNS request:", url);
  26. window.bindSNSRequest = url;
  27.  
  28. // Clone the response so we can read it
  29. response.clone().text().then(text => {
  30. console.log("Captured bindSNS response:", text);
  31. window.bindSNSResponse = text;
  32. });
  33. }
  34. return response;
  35. });
  36. };
  37.  
  38. // Intercept XMLHttpRequests (if needed)
  39. const originalXhrOpen = XMLHttpRequest.prototype.open;
  40. XMLHttpRequest.prototype.open = function(method, url) {
  41. this.addEventListener("readystatechange", function() {
  42. if (this.readyState === 4 && url.includes("bindSNS")) { // readyState 4 means the request is done
  43. console.log("Captured bindSNS request:", url);
  44. window.bindSNSRequest = url;
  45. console.log("Captured bindSNS response:", this.responseText);
  46. window.bindSNSResponse = this.responseText;
  47. }
  48. });
  49. originalXhrOpen.apply(this, arguments);
  50. };
  51. })();