XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update chat.v1.js

ee3bc784
foxfire52 <foxfire52@virgilio.it>
提交于

代码差异

1 个文件 +53 -1
Modified g4f/gui/client/static/js/chat.v1.js +53 -1
@@ -57,6 +57,27 @@ function filter_message(text) {
57 57 )
58 58 }
59 59
60 function fallback_copy (text) {
61 console.warn("Entering fallback_copy...")
62 var textBox = document.createElement("textbox");
63 textBox.value = text; // Avoid scrolling to bottom
64 textBox.style.top = "0";
65 textBox.style.left = "0";
66 textBox.style.position = "fixed";
67 document.body.appendChild(textBox);
68 textBox.focus();
69 textBox.select();
70 try {
71 var success = document.execCommand('copy');
72 var msg = success ? 'succeeded' : 'failed';
73 console.log('Fallback: Copying text command ' + msg);
74 } catch (err) {
75 console.error('Fallback: Unable to copy', err);
76 };
77 document.body.removeChild(textBox);
78
79 }
80
60 81 hljs.addPlugin(new CopyButtonPlugin());
61 82 let typesetPromise = Promise.resolve();
62 83 const highlight = (container) => {
@@ -100,6 +121,37 @@ const register_message_buttons = async () => {
100 121 })
101 122 }
102 123 });
124
125
126 document.querySelectorAll(".message .fa-clipboard").forEach(async (el) => {
127 if (!("click" in el.dataset)) {
128 el.dataset.click = "true";
129 el.addEventListener("click", async () => {
130 const message_el = el.parentElement.parentElement.parentElement;
131 try {
132 const copyText = await get_message(window.conversation_id, message_el.dataset.index);
133 } catch(e) {
134 console.error(e);
135 };
136
137 try {
138 console.warn("copyText type: ", typeof copyText)
139 console.warn("Current Text: " + copyText);
140 await navigator.clipboard.writeText(copyText);
141 } catch (e) {
142 console.error("Clipboard API failed!")
143 console.error(e);
144 fallback_copy(copyText);
145 };
146
147 el.classList.add("clicked");
148 setTimeout(() => el.classList.remove("clicked"), 1000);
149 })
150 }
151 });
152
153
154
103 155 document.querySelectorAll(".message .fa-volume-high").forEach(async (el) => {
104 156 if (!("click" in el.dataset)) {
105 157 el.dataset.click = "true";
@@ -1424,4 +1476,4 @@ if (SpeechRecognition) {
1424 1476 recognition.start();
1425 1477 }
1426 1478 });
1427 }
1479 }