Capture bindSNS Request and Response

Capture and store the bindSNS request and response

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Capture bindSNS Request and Response
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Capture and store the bindSNS request and response
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==


(function() {
    'use strict';

    // Store the request and response in global variables
    window.bindSNSRequest = null;
    window.bindSNSResponse = null;

    // Intercept fetch requests
    const originalFetch = window.fetch;
    window.fetch = function(...args) {
        const url = args[0];
        return originalFetch.apply(this, args).then(response => {
            if (url.includes("bindSNS")) {
                console.log("Captured bindSNS request:", url);
                window.bindSNSRequest = url;

                // Clone the response so we can read it
                response.clone().text().then(text => {
                    console.log("Captured bindSNS response:", text);
                    window.bindSNSResponse = text;
                });
            }
            return response;
        });
    };

    // Intercept XMLHttpRequests (if needed)
    const originalXhrOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url) {
        this.addEventListener("readystatechange", function() {
            if (this.readyState === 4 && url.includes("bindSNS")) {  // readyState 4 means the request is done
                console.log("Captured bindSNS request:", url);
                window.bindSNSRequest = url;
                console.log("Captured bindSNS response:", this.responseText);
                window.bindSNSResponse = this.responseText;
            }
        });
        originalXhrOpen.apply(this, arguments);
    };
})();