Skip to content

Instantly share code, notes, and snippets.

@aomarks
Last active January 24, 2024 05:41
Show Gist options
  • Save aomarks/6dc4042fd2e4941158f97164f5cf05f7 to your computer and use it in GitHub Desktop.
Save aomarks/6dc4042fd2e4941158f97164f5cf05f7 to your computer and use it in GitHub Desktop.
Archive all ChatGPT chats browser script
// 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) {
break;
}
chat.click();
await pause(500);
const menuButton = chat.parentElement.querySelector("button");
menuButton.dispatchEvent(
new KeyboardEvent("keydown", { key: "Enter", code: "Enter", bubbles: true })
);
await pause(500);
const archiveButton = [...document.querySelectorAll('[role="menuitem"]')].find(
(item) => item.textContent === "Archive chat"
);
archiveButton.click();
await pause(1500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment