Skip to content

Instantly share code, notes, and snippets.

@shpetimhaxhiu
Created February 7, 2023 03:58
Show Gist options
  • Save shpetimhaxhiu/5895ddcd5725e70131f5e10043357aad to your computer and use it in GitHub Desktop.
Save shpetimhaxhiu/5895ddcd5725e70131f5e10043357aad to your computer and use it in GitHub Desktop.
Save ChatGPT conversation to clipboard with one simple step!
/**
* @name saveChatGPT
* @description Saves the chat log to the clipboard. Useful for saving the chat log for GPT-3 train
* @async
* @throws {DOMException} If the document is not focused or there is a problem accessing the clipboard.
* @returns {void}
*
* @author <shpetim.h@gmail.com>
* @link github.com/shpetimhaxhiu
* @version 1.0.0
* @license MIT
*/
async function saveChatGPT() {
var elements = document.querySelectorAll(".whitespace-pre-wrap");
var html = "";
for (var i = 0; i < elements.length; i++) {
html += elements[i].outerHTML;
}
try {
document.querySelector("body").focus();
await navigator.clipboard.writeText(html);
console.log("Text copied to clipboard");
} catch (err) {
console.error("Failed to copy text: ", err);
}
}
// Language: javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment