Show Copied text on copy

This commit is contained in:
taskylizard 2023-11-06 00:50:18 +05:30
parent 8b2ae07c58
commit 3a71e8f164
No known key found for this signature in database
GPG Key ID: 5CABA3D642DDC497

View File

@ -17,10 +17,9 @@ export function copyableCodePlugin(md: MarkdownRenderer) {
}
const token = tokens[idx];
const content = token.content;
const buttonHTML = `<button class='base64' onclick="navigator.clipboard.writeText('${decode(
content,
)}')"><code>${content}</code></button>`;
return buttonHTML;
return `<button class='base64' onclick="(function(btn){ const codeEl = btn.querySelector('code'); navigator.clipboard.writeText('${decode(
content,
)}').then(() => { const originalText = codeEl.textContent; codeEl.textContent = 'Copied'; setTimeout(() => codeEl.textContent = originalText, 3000); }).catch(console.error); })(this)"><code>${content}</code></button>`;
};
}