Forked from aomarks/archive-all-chatgpt-chats.js
Last active
February 13, 2025 22:41
-
-
Save Vinaco00/83abbfb4c745abeab5fda580d08e8f37 to your computer and use it in GitHub Desktop.
Archive all ChatGPT chats browser script
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
// This script will iterate over all of your ChatGPT sessions and archive them one-by-one. | |
// | |
// 1. Go to https://chat.openai.com/ | |
// 2. Open Chrome devtools (see https://developer.chrome.com/docs/devtools/open) or equivalent in your browser | |
// 3. Open the console tab | |
// 4. Paste the code below and press enter | |
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
const history = document.querySelector('[aria-label="Chat history"]'); | |
while (true) { | |
const chat = history.querySelector( | |
'a[href^="/c/"]:not(.group), a[href^="/g/"]:not(.group)' | |
); | |
if (!chat) { | |
console.log("No chats found"); | |
break; | |
} | |
chat.click(); | |
await pause(500); | |
const menuButton = chat.parentElement.querySelector("button"); | |
console.log("Menu button:", menuButton); | |
if (!menuButton) { | |
console.error("Menu button not found"); | |
break; | |
} | |
const isVisible = !!(menuButton.offsetWidth || menuButton.offsetHeight || menuButton.getClientRects().length); | |
console.log("Menu button visible:", isVisible); | |
// Use pointer events to open the menu | |
menuButton.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true })); | |
menuButton.dispatchEvent(new PointerEvent("pointerup", { bubbles: true })); | |
await pause(1000); | |
// Locate the menu and find the "Archive chat" button | |
const menu = document.body.querySelector('[role="menu"]'); | |
if (!menu) { | |
console.error("Menu did not open"); | |
break; | |
} | |
const archiveButton = [...menu.querySelectorAll('[role="menuitem"]')].find( | |
(item) => /archive/i.test(item.textContent.trim()) | |
); | |
if (!archiveButton) { | |
console.error("Archive button not found"); | |
break; | |
} | |
// Click the archive button | |
archiveButton.scrollIntoView(); | |
archiveButton.click(); | |
console.log("Archived chat successfully"); | |
await pause(1500); // Wait for the archive action to complete | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment