Copy code or full message
This commit is contained in:
@@ -22,6 +22,71 @@
|
||||
|
||||
{{embed}}
|
||||
|
||||
<script>
|
||||
function copyToClipboardCode(button) {
|
||||
// Get the code element next to the button
|
||||
var codeElement = button.nextElementSibling;
|
||||
|
||||
// Create a temporary textarea element
|
||||
var tempTextarea = document.createElement('textarea');
|
||||
tempTextarea.value = codeElement.textContent;
|
||||
|
||||
// Append the temporary textarea to the document body
|
||||
document.body.appendChild(tempTextarea);
|
||||
|
||||
// Select the text in the temporary textarea
|
||||
tempTextarea.select();
|
||||
|
||||
// Copy the selected text to the clipboard
|
||||
document.execCommand('copy');
|
||||
|
||||
// Remove the temporary textarea from the document body
|
||||
document.body.removeChild(tempTextarea);
|
||||
|
||||
// Change the button text to indicate successful copy
|
||||
var originalText = button.innerHTML;
|
||||
button.innerHTML = '<i class="fa-solid fa-check"></i>';
|
||||
|
||||
// Revert the button text after a short delay
|
||||
setTimeout(function () {
|
||||
button.innerHTML = originalText;
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function copyToClipboard(button) {
|
||||
// Get the container element for all the message content
|
||||
var messageContentContainer = button.closest('.message-bot').querySelector('#content-column .content');
|
||||
|
||||
// Get the text content of all the messages
|
||||
var messageContent = messageContentContainer.textContent.trim();
|
||||
|
||||
// Create a temporary textarea element
|
||||
var tempTextarea = document.createElement('textarea');
|
||||
tempTextarea.value = messageContent;
|
||||
|
||||
// Append the temporary textarea to the document body
|
||||
document.body.appendChild(tempTextarea);
|
||||
|
||||
// Select the text in the temporary textarea
|
||||
tempTextarea.select();
|
||||
|
||||
// Copy the selected text to the clipboard
|
||||
document.execCommand('copy');
|
||||
|
||||
// Remove the temporary textarea from the document body
|
||||
document.body.removeChild(tempTextarea);
|
||||
|
||||
// Change the button text to indicate successful copy
|
||||
var originalText = button.innerHTML;
|
||||
button.innerHTML = '<i class="fa-solid fa-check"></i>';
|
||||
|
||||
// Revert the button text after a short delay
|
||||
setTimeout(function () {
|
||||
button.innerHTML = originalText;
|
||||
}, 2000);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user