From 326d4bf218359fcae36f616a90f88ad146b69e90 Mon Sep 17 00:00:00 2001 From: ellvix Date: Tue, 3 Dec 2024 18:27:11 -0700 Subject: [PATCH] feat: alert user that chat has been copied via aria-live (#614) --- src/js/constants.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/js/constants.js b/src/js/constants.js index 953b9e0b..32a5d3c8 100644 --- a/src/js/constants.js +++ b/src/js/constants.js @@ -1962,6 +1962,7 @@ class ChatLLM { */ CopyChatHistory(e) { let text = ''; + let notificationText = ''; if (typeof e == 'undefined') { // check for passthrough // get html of the full chat history @@ -1971,9 +1972,11 @@ class ChatLLM { if (e.target.id == 'chatLLM_copy_all') { // get html of the full chat history text = document.getElementById('chatLLM_chat_history').innerHTML; + notificationText = 'Copied All.'; } else if (e.target.classList.contains('chatLLM_message_copy_button')) { // get the text of the element before the button text = e.target.closest('p').previousElementSibling.innerHTML; + notificationText = 'Copied.'; } } else if (e.type == 'keyup') { // check for alt shift c or ctrl shift c @@ -1985,6 +1988,7 @@ class ChatLLM { ); if (elem) { text = elem.innerHTML; + notificationText = 'Copied.'; } } else if ( e.key == 'A' && @@ -1994,6 +1998,7 @@ class ChatLLM { e.preventDefault(); // get html of the full chat history text = document.getElementById('chatLLM_chat_history').innerHTML; + notificationText = 'Copied All.'; } } @@ -2011,6 +2016,12 @@ class ChatLLM { // this messes up a bit with spacing, so kill more than 2 newlines in a row markdown = markdown.replace(/\n{3,}/g, '\n\n'); + if (notificationText != '') { + if (display) { + display.announceText(notificationText); + } + } + try { navigator.clipboard.writeText(markdown); // note: this fails if you're on the inspector. That's fine as it'll never happen to real users } catch (err) {