Created
October 2, 2024 18:58
-
-
Save sidpan1/1299bf2ea461584ab97b49559c29078b to your computer and use it in GitHub Desktop.
Chat GPT - claude collab
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 ChatGPT and Claude Response Passer | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Automatically passes responses between ChatGPT and Claude | |
// @author Your Name | |
// @match https://chatgpt.com/c/* // Match for ChatGPT | |
// @match https://claude.ai/chat/* // Match for Claude | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const inputSelectorChatGPT = '#prompt-textarea'; // ChatGPT input area | |
const sendButtonSelectorChatGPT = 'button[aria-label="Send prompt"]'; // Send button for ChatGPT | |
const responseSelectorChatGPT = '.text-base'; // Response area selector for ChatGPT | |
const inputSelectorClaude = '[contenteditable="true"]'; // Claude's input area | |
const sendButtonSelectorClaude = 'button[aria-label="Upload content"]'; // Send button for Claude | |
const responseSelectorClaude = '.flex.flex-col.bg-bg-000'; // Response area selector for Claude | |
function getThreadId(url, platform) { | |
return platform === 'chatgpt' ? url.split('/c/')[1] : url.split('/chat/')[1]; | |
} | |
function sendToClaude(response) { | |
const chatGPTUrl = window.location.href; | |
const threadId = getThreadId(chatGPTUrl, 'chatgpt'); | |
const claudeUrl = `https://claude.ai/chat/${threadId}`; // Construct Claude URL with thread ID | |
const claudeTab = window.open(claudeUrl, '_blank'); | |
claudeTab.focus(); | |
// Send the response after a delay | |
setTimeout(() => { | |
const inputField = claudeTab.document.querySelector(inputSelectorClaude); | |
inputField.innerText = response + `\nThread ID: ${threadId}`; // Append thread ID to response | |
const inputEvent = new Event('input', { bubbles: true }); | |
inputField.dispatchEvent(inputEvent); | |
const sendButton = claudeTab.document.querySelector(sendButtonSelectorClaude); | |
sendButton.click(); | |
}, 2000); | |
} | |
function sendToChatGPT(response) { | |
const claudeUrl = window.location.href; | |
const threadId = getThreadId(claudeUrl, 'claude'); | |
const chatGPTUrl = `https://chatgpt.com/c/${threadId}`; // Construct ChatGPT URL with thread ID | |
const chatGPTTab = window.open(chatGPTUrl, '_blank'); | |
chatGPTTab.focus(); | |
// Send the response after a delay | |
setTimeout(() => { | |
const inputField = chatGPTTab.document.querySelector(inputSelectorChatGPT); | |
inputField.innerText = response + `\nThread ID: ${threadId}`; // Append thread ID to response | |
const inputEvent = new Event('input', { bubbles: true }); | |
inputField.dispatchEvent(inputEvent); | |
chatGPTTab.document.querySelector(sendButtonSelectorChatGPT).click(); | |
}, 2000); | |
} | |
// Observe ChatGPT's response area | |
if (window.location.href.includes('chatgpt.com')) { | |
const observerChatGPT = new MutationObserver(() => { | |
const response = document.querySelector(responseSelectorChatGPT).lastElementChild.innerText; | |
sendToClaude(response); | |
}); | |
observerChatGPT.observe(document.querySelector(responseSelectorChatGPT), { childList: true, subtree: true }); | |
} | |
// Observe Claude's response area | |
if (window.location.href.includes('claude.ai')) { | |
const observerClaude = new MutationObserver(() => { | |
const response = document.querySelector(responseSelectorClaude).lastElementChild.innerText; | |
sendToChatGPT(response); | |
}); | |
observerClaude.observe(document.querySelector(responseSelectorClaude), { childList: true, subtree: true }); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment