{converted_visible[1]}
'
f'{copy_button}'
+ f'{refresh_button if i == len(history["visible"]) - 1 else ""}'
f'From 1b9121e5b87625edbbc13d2dc0e42624173553ca Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:41:41 -0800 Subject: [PATCH] Add a "refresh" button below the last message, add a missing file --- css/main.css | 29 +++++++++++++++++++---------- js/global_scope_js.js | 23 +++++++++++++++++++++++ modules/html_generator.py | 7 ++++++- 3 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 js/global_scope_js.js diff --git a/css/main.css b/css/main.css index 48c6727a..63681979 100644 --- a/css/main.css +++ b/css/main.css @@ -1236,11 +1236,10 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { position: relative; } -.copy-button { +.footer-button { position: absolute; - bottom: -23px; - left: 0; padding: 0; + margin: 0; border: none; border-radius: 3px; cursor: pointer; @@ -1250,25 +1249,35 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { transition: opacity 0.2s; } -.message:hover .copy-button, -.user-message:hover .copy-button, -.assistant-message:hover .copy-button { +.footer-button#copy-button { + bottom: -23px; + left: 0; +} + +.footer-button#refresh-button { + bottom: -23px; + left: 25px; +} + +.message:hover .footer-button, +.user-message:hover .footer-button, +.assistant-message:hover .footer-button { opacity: 1; } -.copy-button svg { +.footer-button svg { stroke: rgb(156 163 175); transition: stroke 0.2s; } -.copy-button:hover svg { +.footer-button:hover svg { stroke: rgb(107 114 128); } -.dark .copy-button svg { +.dark .footer-button svg { stroke: rgb(156 163 175); } -.dark .copy-button:hover svg { +.dark .footer-button:hover svg { stroke: rgb(209 213 219); } diff --git a/js/global_scope_js.js b/js/global_scope_js.js new file mode 100644 index 00000000..79b673d7 --- /dev/null +++ b/js/global_scope_js.js @@ -0,0 +1,23 @@ +function copyToClipboard(element) { + if (!element) return; + + const messageElement = element.closest(".message, .user-message, .assistant-message"); + if (!messageElement) return; + + const rawText = messageElement.getAttribute("data-raw"); + if (!rawText) return; + + navigator.clipboard.writeText(rawText).then(function() { + const originalSvg = element.innerHTML; + element.innerHTML = ""; + setTimeout(() => { + element.innerHTML = originalSvg; + }, 1000); + }).catch(function(err) { + console.error("Failed to copy text: ", err); + }); +} + +function regenerateClick() { + document.getElementById("Regenerate").click(); +} diff --git a/modules/html_generator.py b/modules/html_generator.py index b565c63a..79a8dc64 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -293,7 +293,9 @@ def get_image_cache(path): copy_svg = '''''' -copy_button = f'' +refresh_svg = '''''' +copy_button = f'' +refresh_button = f'' def generate_instruct_html(history): output = f'