Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Markdown from Copy button #5

Open
7shi opened this issue May 4, 2024 · 1 comment
Open

Get Markdown from Copy button #5

7shi opened this issue May 4, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@7shi
Copy link

7shi commented May 4, 2024

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.

kmptkp pushed a commit to kmptkp/claude-export that referenced this issue Jul 21, 2024
@7shi
Copy link
Author

7shi commented Aug 23, 2024

Fixed by fork:

7shi@372836e

@ryanschiang ryanschiang self-assigned this Dec 10, 2024
@ryanschiang ryanschiang added the enhancement New feature or request label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants