From ee3bc784f35faf342df44ab570b98271481680f8 Mon Sep 17 00:00:00 2001 From: foxfire52 Date: Thu, 24 Oct 2024 12:41:55 +0200 Subject: Update chat.v1.js --- g4f/gui/client/static/js/chat.v1.js | 54 ++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'g4f/gui/client/static/js/chat.v1.js') 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 +} -- cgit v1.2.3 From 89b5a6353ed7a83bd388b01da523b52774cb7cc5 Mon Sep 17 00:00:00 2001 From: foxfire52 Date: Thu, 24 Oct 2024 12:47:07 +0200 Subject: Update chat.v1.js --- g4f/gui/client/static/js/chat.v1.js | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'g4f/gui/client/static/js/chat.v1.js') diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 8402744e..da990024 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -109,19 +109,6 @@ 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; - const copyText = await get_message(window.conversation_id, message_el.dataset.index); - navigator.clipboard.writeText(copyText); - el.classList.add("clicked"); - setTimeout(() => el.classList.remove("clicked"), 1000); - }) - } - }); - document.querySelectorAll(".message .fa-clipboard").forEach(async (el) => { if (!("click" in el.dataset)) { -- cgit v1.2.3 From c5e356a3219ae86b18bb366c47ccb0a36f8a651a Mon Sep 17 00:00:00 2001 From: foxfire52 Date: Thu, 24 Oct 2024 13:40:23 +0200 Subject: Update chat.v1.js --- g4f/gui/client/static/js/chat.v1.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'g4f/gui/client/static/js/chat.v1.js') diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index da990024..5309a04d 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -59,7 +59,7 @@ function filter_message(text) { function fallback_copy (text) { console.warn("Entering fallback_copy...") - var textBox = document.createElement("textbox"); + var textBox = document.createElement("textarea"); textBox.value = text; // Avoid scrolling to bottom textBox.style.top = "0"; textBox.style.left = "0"; @@ -115,11 +115,7 @@ const register_message_buttons = async () => { 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) -- cgit v1.2.3 From 6bf6c5e5e97633050b0bdf61f0c4730b40c08851 Mon Sep 17 00:00:00 2001 From: foxfire52 Date: Sat, 26 Oct 2024 12:29:58 +0200 Subject: Clean up chat.v1.js --- g4f/gui/client/static/js/chat.v1.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'g4f/gui/client/static/js/chat.v1.js') diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 5309a04d..2777e79a 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -57,10 +57,9 @@ function filter_message(text) { ) } -function fallback_copy (text) { - console.warn("Entering fallback_copy...") +function fallback_clipboard (text) { var textBox = document.createElement("textarea"); - textBox.value = text; // Avoid scrolling to bottom + textBox.value = text; textBox.style.top = "0"; textBox.style.left = "0"; textBox.style.position = "fixed"; @@ -70,12 +69,11 @@ function fallback_copy (text) { 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); - }; + console.log('Clipboard Fallback: Copying text command ' + msg); + } catch (e) { + console.error('Clipboard Fallback: Unable to copy', e); + } document.body.removeChild(textBox); - } hljs.addPlugin(new CopyButtonPlugin()); @@ -118,14 +116,12 @@ const register_message_buttons = async () => { const copyText = await get_message(window.conversation_id, message_el.dataset.index); 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); - }; + console.error("Clipboard API failed! Fallback to document.exec("copy")..."); + fallback_clipboard(copyText); + } el.classList.add("clicked"); setTimeout(() => el.classList.remove("clicked"), 1000); @@ -133,8 +129,6 @@ const register_message_buttons = async () => { } }); - - document.querySelectorAll(".message .fa-volume-high").forEach(async (el) => { if (!("click" in el.dataset)) { el.dataset.click = "true"; -- cgit v1.2.3 From 6f0eae8a067879758bb65ce9f21e6223ba8917e5 Mon Sep 17 00:00:00 2001 From: foxfire52 Date: Sat, 26 Oct 2024 12:42:23 +0200 Subject: Clean up chat.v1.js --- g4f/gui/client/static/js/chat.v1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'g4f/gui/client/static/js/chat.v1.js') diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 2777e79a..9682de59 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -119,7 +119,7 @@ const register_message_buttons = async () => { await navigator.clipboard.writeText(copyText); } catch (e) { console.error(e); - console.error("Clipboard API failed! Fallback to document.exec("copy")..."); + console.error("Clipboard API writeText() failed! Fallback to document.exec(\"copy\")..."); fallback_clipboard(copyText); } -- cgit v1.2.3 From 8d010d892777ab7e191ade861ef1f357a54b3fe4 Mon Sep 17 00:00:00 2001 From: foxfire52 Date: Sat, 26 Oct 2024 13:28:08 +0200 Subject: Update chat.v1.js --- g4f/gui/client/static/js/chat.v1.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'g4f/gui/client/static/js/chat.v1.js') diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 9682de59..d5a1ffaa 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -115,7 +115,10 @@ const register_message_buttons = async () => { const message_el = el.parentElement.parentElement.parentElement; const copyText = await get_message(window.conversation_id, message_el.dataset.index); - try { + try { + if (!navigator.clipboard) { + throw new Error("navigator.clipboard: Clipboard API unavailable."); + } await navigator.clipboard.writeText(copyText); } catch (e) { console.error(e); -- cgit v1.2.3