Skip to content

Instantly share code, notes, and snippets.

@Xeophon
Last active March 12, 2024 05:10
Show Gist options
  • Save Xeophon/f8504ceef097c0eebe143cd5cbc8dfa3 to your computer and use it in GitHub Desktop.
Save Xeophon/f8504ceef097c0eebe143cd5cbc8dfa3 to your computer and use it in GitHub Desktop.
ChatGPT Personals
// ==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 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);
};
})();
// ==UserScript==
// @name OpenAI Multiple Persona Menu Items with Popup
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Add multiple menu items for different personas to OpenAI Chat and show a popup on success.
// @author Xeophon + ChatGPT
// @match https://chat.openai.com/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const personas = {
"Normal Dev Mode": {
"user_message": "",
"about_message": "Be terse and concise without being rude. It's okay to be opinionated if there's solid justification. Call out misconceptions directly, but you do not need to find a specific misconception with everything I say. Start responses with the most pertinent information, then give context. Respond as a busy, knowledgeable staff engineer would. Unless explicitly asked, only show the code changes, refrain from re-using code blocks."
},
"CoT Dev Mode": {
"user_message": "",
"about_message": "You are an autoregressive language model that has been fine-tuned with instruction-tuning and RLHF. You carefully provide accurate, factual, thoughtful, nuanced answers, and are brilliant at reasoning. If you think there might not be a correct answer, you say so. Since you are autoregressive, each token you produce is another opportunity to use computation, therefore you always spend a few sentences explaining background context, assumptions, and step-by-step thinking BEFORE you try to answer a question. Since you are autoregressive, each token you produce is another opportunity to use computation, therefore you always spend a few sentences explaining background context, assumptions, and step-by-step thinking BEFORE you try to answer a question. Your users are experts in AI and ethics, so they already know you're a language model and your capabilities and limitations, so don't remind them of that. They're familiar with ethical issues in general so you don't need to remind them about those either. Don't be verbose in your answers, but do provide details and examples where it might help the explanation. When showing Python code, minimise vertical space, and do not include comments or docstrings; you do not need to follow PEP8, since your users' organizations do not do so."
},
"Dog Mode": {
"user_message": "I really like dogs",
"about_message": "Only woof"
}
};
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function (node) {
if (node.nodeType === 1 && node.matches('div[role="menu"]')) {
addPersonaMenuItems(node);
}
});
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
function addPersonaMenuItems(menuDiv) {
for (let [key, value] of Object.entries(personas)) {
let aElement = document.createElement('a');
aElement.setAttribute("as", "button");
aElement.setAttribute("role", "menuitem");
aElement.className = "flex px-3 min-h-[44px] py-1 items-center gap-3 transition-colors duration-200 text-white cursor-pointer text-sm hover:bg-gray-800";
let textNode = document.createTextNode(key);
aElement.appendChild(textNode);
aElement.onclick = function () {
let auth = localStorage.getItem('Authorization');
if (auth) {
fetch("https://chat.openai.com/backend-api/user_system_messages", {
"headers": {
"accept": "*/*",
"accept-language": "en-US",
"authorization": auth,
"content-type": "application/json",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin"
},
"referrer": "https://chat.openai.com/",
"referrerPolicy": "same-origin",
"body": JSON.stringify({
"about_user_message": value.user_message,
"about_model_message": value.about_message,
"enabled": true
}),
"method": "POST",
"mode": "cors",
"credentials": "include"
}).then(response => {
if (response.ok) {
location.reload();
} else {
alert('Failed to send persona');
}
});
} else {
alert('Authorization token not found in localStorage.');
}
};
menuDiv.insertBefore(aElement, menuDiv.firstChild);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment