claude-export
claude-export copied to clipboard
Get Markdown from Copy button
To get Markdown, it is reliable to hook the text sent to the clipboard from the Copy button.
I implemented this in a simple way. It requires exportMarkdown to be async. Since the clipboard cannot be manipulated without user interaction, the original method is not called.
if (ele.classList.contains("font-claude-message")) {
markdown += `_Claude_:\n`;
var clip = navigator.clipboard;
if (!clip._writeText) clip._writeText = clip.writeText;
for (var copy of Array.from(ele.nextSibling.getElementsByTagName("button")).filter(b => b.innerText == "Copy")) {
await new Promise((resolve, reject) => {
clip.writeText = async arg => {
markdown += arg.trimEnd() + "\n";
resolve();
};
try {
copy.click();
} catch (e) {
reject(e);
}
});
}
clip.writeText = clip._writeText;
} else {
Getting prompts still require the existing converter.
Fixed by fork:
https://github.com/7shi/claude-export/commit/372836ef45b2326b17b2d4b3af913d70f7dda8ab