@@ -259,7 +259,24 @@ function cancel_loading_status() {
259
259
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
260
260
// 第 2 部分: 复制按钮
261
261
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
262
+ // 解压缩函数
263
+ function decompressString ( compressedString ) {
264
+ // 第1步:Base64解码
265
+ const binaryString = atob ( compressedString ) ;
262
266
267
+ // 第2步:将二进制字符串转换为Uint8Array
268
+ const bytes = new Uint8Array ( binaryString . length ) ;
269
+ for ( let i = 0 ; i < binaryString . length ; i ++ ) {
270
+ bytes [ i ] = binaryString . charCodeAt ( i ) ;
271
+ }
272
+
273
+ // 第3步:使用DecompressionStream (基于Web Streams API)进行gzip解压缩
274
+ const ds = new DecompressionStream ( 'gzip' ) ;
275
+ const decompressedStream = new Response ( new Blob ( [ bytes ] ) ) . body . pipeThrough ( ds ) ;
276
+
277
+ // 第4步:获取解压后的数据并转换为字符串
278
+ return new Response ( decompressedStream ) . text ( ) ;
279
+ }
263
280
264
281
var allow_auto_read_continously = true ;
265
282
var allow_auto_read_tts_flag = false ;
@@ -283,19 +300,56 @@ function addCopyButton(botElement, index, is_last_in_arr) {
283
300
return ;
284
301
}
285
302
286
- var copyButton = document . createElement ( 'button' ) ;
287
- copyButton . classList . add ( 'copy-bot-btn' ) ;
288
- copyButton . setAttribute ( 'aria-label' , 'Copy' ) ;
289
- copyButton . innerHTML = copyIcon ;
290
- copyButton . addEventListener ( 'click' , async ( ) => {
291
- const textToCopy = botElement . innerText ;
303
+ // var copyButton = document.createElement('button');
304
+ // copyButton.classList.add('copy-bot-btn');
305
+ // copyButton.setAttribute('aria-label', 'Copy');
306
+ // copyButton.innerHTML = copyIcon;
307
+ // copyButton.addEventListener('click', async () => {
308
+ // const textToCopy = botElement.innerText;
309
+ // try {
310
+ // // push_text_to_audio(textToCopy).catch(console.error);
311
+ // if ("clipboard" in navigator) {
312
+ // await navigator.clipboard.writeText(textToCopy);
313
+ // copyButton.innerHTML = copiedIcon;
314
+ // setTimeout(() => {
315
+ // copyButton.innerHTML = copyIcon;
316
+ // }, 1500);
317
+ // } else {
318
+ // const textArea = document.createElement("textarea");
319
+ // textArea.value = textToCopy;
320
+ // document.body.appendChild(textArea);
321
+ // textArea.select();
322
+ // try {
323
+ // document.execCommand('copy');
324
+ // copyButton.innerHTML = copiedIcon;
325
+ // setTimeout(() => {
326
+ // copyButton.innerHTML = copyIcon;
327
+ // }, 1500);
328
+ // } catch (error) {
329
+ // console.error("Copy failed: ", error);
330
+ // }
331
+ // document.body.removeChild(textArea);
332
+ // }
333
+ // } catch (error) {
334
+ // console.error("Copy failed: ", error);
335
+ // }
336
+ // });
337
+
338
+ // 原始文本拷贝
339
+ var copyButtonOrig = document . createElement ( 'button' ) ;
340
+ copyButtonOrig . classList . add ( 'copy-bot-btn' ) ;
341
+ copyButtonOrig . setAttribute ( 'aria-label' , 'Copy' ) ;
342
+ copyButtonOrig . innerHTML = copyIcon ;
343
+ copyButtonOrig . addEventListener ( 'click' , async ( ) => {
292
344
try {
345
+ const base64gzipcode = botElement . getElementsByClassName ( 'raw_text' ) [ 0 ] . innerText ;
346
+ const textToCopy = await decompressString ( base64gzipcode ) ;
293
347
// push_text_to_audio(textToCopy).catch(console.error);
294
348
if ( "clipboard" in navigator ) {
295
349
await navigator . clipboard . writeText ( textToCopy ) ;
296
- copyButton . innerHTML = copiedIcon ;
350
+ copyButtonOrig . innerHTML = copiedIcon ;
297
351
setTimeout ( ( ) => {
298
- copyButton . innerHTML = copyIcon ;
352
+ copyButtonOrig . innerHTML = copyIcon ;
299
353
} , 1500 ) ;
300
354
} else {
301
355
const textArea = document . createElement ( "textarea" ) ;
@@ -304,9 +358,9 @@ function addCopyButton(botElement, index, is_last_in_arr) {
304
358
textArea . select ( ) ;
305
359
try {
306
360
document . execCommand ( 'copy' ) ;
307
- copyButton . innerHTML = copiedIcon ;
361
+ copyButtonOrig . innerHTML = copiedIcon ;
308
362
setTimeout ( ( ) => {
309
- copyButton . innerHTML = copyIcon ;
363
+ copyButtonOrig . innerHTML = copyIcon ;
310
364
} , 1500 ) ;
311
365
} catch ( error ) {
312
366
console . error ( "Copy failed: " , error ) ;
@@ -345,7 +399,8 @@ function addCopyButton(botElement, index, is_last_in_arr) {
345
399
346
400
var messageBtnColumn = document . createElement ( 'div' ) ;
347
401
messageBtnColumn . classList . add ( 'message-btn-row' ) ;
348
- messageBtnColumn . appendChild ( copyButton ) ;
402
+ // messageBtnColumn.appendChild(copyButton);
403
+ messageBtnColumn . appendChild ( copyButtonOrig ) ;
349
404
if ( enable_tts ) {
350
405
messageBtnColumn . appendChild ( audioButton ) ;
351
406
}
0 commit comments