Last active
August 27, 2025 14:27
-
-
Save FreesoSaiFared/45d7304bad4416bc0e6ed1052722e9f6 to your computer and use it in GitHub Desktop.
chatgpt_jwt_interceptor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name OpenAI Authorization Header Interceptor | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.1 | |
| // @description Intercept OpenAI chat requests, store Authorization header once, and exit | |
| // @author FreesoSaiFared + Xeophon + ChatGPT | |
| // @match https://chat.openai.com/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| console.log('[Tampermonkey] Script initialized.'); | |
| if (localStorage.getItem('Authorization')) { | |
| console.log('[Tampermonkey] Authorization header already stored. Exiting.'); | |
| return; // Exit if the Authorization header is already stored | |
| } | |
| // Store a reference to the original fetch function | |
| const originalFetch = window.fetch; | |
| // Override the fetch function | |
| window.fetch = async function(...args) { | |
| const [url, requestInit] = args; | |
| console.log('[Tampermonkey] Intercepted fetch call to:', url); | |
| // Check if the URL matches the desired pattern | |
| if (url.includes("https://chat.openai.com/backend-api/")) { | |
| console.log('[Tampermonkey] URL matches desired pattern.'); | |
| // Create a new Request object from the arguments to extract headers | |
| const request = new Request(url, requestInit); | |
| // Extract the Authorization header if it exists | |
| if (request.headers.has('Authorization')) { | |
| const authHeader = request.headers.get('Authorization'); | |
| // Store in localStorage | |
| localStorage.setItem('Authorization', authHeader); | |
| console.log('[Tampermonkey] Authorization header stored in localStorage.'); | |
| // Remove the fetch interceptor after storing the header | |
| window.fetch = originalFetch; | |
| } else { | |
| console.log('[Tampermonkey] Authorization header not found in the request.'); | |
| } | |
| } | |
| // Call the original fetch function with the arguments | |
| return originalFetch.apply(this, args); | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment