diff options
author | foxfire52 <foxfire52@virgilio.it> | 2024-10-24 12:41:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-24 12:41:55 +0200 |
commit | ee3bc784f35faf342df44ab570b98271481680f8 (patch) | |
tree | 0c2a9fc5e5d7dde0c90dee79658a19ae92b01d4b /g4f/gui | |
parent | . (diff) | |
download | gpt4free-ee3bc784f35faf342df44ab570b98271481680f8.tar gpt4free-ee3bc784f35faf342df44ab570b98271481680f8.tar.gz gpt4free-ee3bc784f35faf342df44ab570b98271481680f8.tar.bz2 gpt4free-ee3bc784f35faf342df44ab570b98271481680f8.tar.lz gpt4free-ee3bc784f35faf342df44ab570b98271481680f8.tar.xz gpt4free-ee3bc784f35faf342df44ab570b98271481680f8.tar.zst gpt4free-ee3bc784f35faf342df44ab570b98271481680f8.zip |
Diffstat (limited to 'g4f/gui')
-rw-r--r-- | g4f/gui/client/static/js/chat.v1.js | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 9790b261..8402744e 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -57,6 +57,27 @@ function filter_message(text) { ) } +function fallback_copy (text) { + console.warn("Entering fallback_copy...") + var textBox = document.createElement("textbox"); + textBox.value = text; // Avoid scrolling to bottom + textBox.style.top = "0"; + textBox.style.left = "0"; + textBox.style.position = "fixed"; + document.body.appendChild(textBox); + textBox.focus(); + textBox.select(); + try { + var success = document.execCommand('copy'); + var msg = success ? 'succeeded' : 'failed'; + console.log('Fallback: Copying text command ' + msg); + } catch (err) { + console.error('Fallback: Unable to copy', err); + }; + document.body.removeChild(textBox); + +} + hljs.addPlugin(new CopyButtonPlugin()); let typesetPromise = Promise.resolve(); const highlight = (container) => { @@ -100,6 +121,37 @@ const register_message_buttons = async () => { }) } }); + + + document.querySelectorAll(".message .fa-clipboard").forEach(async (el) => { + if (!("click" in el.dataset)) { + el.dataset.click = "true"; + el.addEventListener("click", async () => { + const message_el = el.parentElement.parentElement.parentElement; + try { + const copyText = await get_message(window.conversation_id, message_el.dataset.index); + } catch(e) { + console.error(e); + }; + + try { + console.warn("copyText type: ", typeof copyText) + console.warn("Current Text: " + copyText); + await navigator.clipboard.writeText(copyText); + } catch (e) { + console.error("Clipboard API failed!") + console.error(e); + fallback_copy(copyText); + }; + + el.classList.add("clicked"); + setTimeout(() => el.classList.remove("clicked"), 1000); + }) + } + }); + + + document.querySelectorAll(".message .fa-volume-high").forEach(async (el) => { if (!("click" in el.dataset)) { el.dataset.click = "true"; @@ -1424,4 +1476,4 @@ if (SpeechRecognition) { recognition.start(); } }); -}
\ No newline at end of file +} |