claude-export icon indicating copy to clipboard operation
claude-export copied to clipboard

Get Markdown from Copy button

Open 7shi opened this issue 1 year ago • 1 comments

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.

7shi avatar May 04 '24 17:05 7shi

Fixed by fork:

https://github.com/7shi/claude-export/commit/372836ef45b2326b17b2d4b3af913d70f7dda8ab

7shi avatar Aug 23 '24 15:08 7shi