- Copy the following code:
javascript:(function()%7Bfunction%20getChatRoot(current%20%3D%20document.querySelector(%22main%22))%20%7B%0A%20%20if%20(current.firstChild.nodeType%20%3D%3D%3D%201)%20%7B%0A%20%20%20%20return%20getChatRoot(current.firstChild)%3B%0A%20%20%7D%0A%20%20return%20current.parentElement%3B%0A%7D%0A%0Aconst%20chatRoot%20%3D%20getChatRoot()%3B%0A%0Aconst%20logs%20%3D%20%5B...chatRoot.children%5D%0A%20%20.map((node%2C%20i)%20%3D%3E%20%7B%0A%20%20%20%20if%20(!node.innerText)%20%7B%0A%20%20%20%20%20%20return%20%22%22%3B%0A%20%20%20%20%7D%0A%20%20%20%20if%20(i%20%3D%3D%3D%200)%20%7B%0A%20%20%20%20%20%20return%20node.innerText%3B%0A%20%20%20%20%7D%0A%20%20%20%20if%20(i%20%25%202%20%3D%3D%3D%201)%20%7B%0A%20%20%20%20%20%20return%20%22**Me%3A**%5Cn%5Cn%22%20%2B%20node.innerText%3B%0A%20%20%20%20%7D%0A%20%20%20%20return%20%22**ChatGPT%3A**%5Cn%5Cn%22%20%2B%20node.innerText%3B%0A%20%20%7D)%0A%20%20.join(%22%5Cn%5Cn---%5Cn%5Cn%22)%3B%0A%0Aasync%20function%20copyToClipboard()%20%7B%0A%20%20try%20%7B%0A%20%20%20%20await%20navigator.clipboard.writeText(logs)%3B%0A%20%20%20%20console.log(%22Content%20copied%20to%20clipboard%22)%3B%0A%20%20%7D%20catch%20(err)%20%7B%0A%20%20%20%20console.error(%22Failed%20to%20copy%3A%20%22%2C%20err)%3B%0A%20%20%7D%0A%7D%0A%0AcopyToClipboard()%3B%7D)()%3B
- Create a new browser bookmark
- Name it whatever you'd like (e.g. Copy ChatGPT Logs)
- Paste the code above into the URL field
After having a convo with ChatGPT, simply click the bookmark. The contents of your chat should be saved to your clipboard. If anything went wrong, there'll be an error in the console.
function getChatRoot(current = document.querySelector("main")) {
if (current.firstChild.nodeType === 1) {
return getChatRoot(current.firstChild);
}
return current.parentElement;
}
const chatRoot = getChatRoot();
const logs = [...chatRoot.children]
.map((node, i) => {
if (!node.innerText) {
return "";
}
if (i === 0) {
return node.innerText;
}
if (i % 2 === 1) {
return "**Me:**\n\n" + node.innerText;
}
return "**ChatGPT:**\n\n" + node.innerText;
})
.join("\n\n---\n\n");
async function copyToClipboard() {
try {
await navigator.clipboard.writeText(logs);
console.log("Content copied to clipboard");
} catch (err) {
console.error("Failed to copy: ", err);
}
}
copyToClipboard();