MZhaovo commited on
Commit
9bc6075
2 Parent(s): 7bce60f 7134a2d

Merge branch 'main' of https://github.com/GaiZhenbiao/ChuanhuChatGPT

Browse files
web_assets/javascript/ChuanhuChat.js CHANGED
@@ -57,7 +57,7 @@ function addInit() {
57
  }
58
  }
59
 
60
- chatbotObserver.observe(chatbotIndicator, { attributes: true });
61
  chatListObserver.observe(chatListIndicator, { attributes: true });
62
  setUploader();
63
 
@@ -340,19 +340,32 @@ function clearChatbot() {
340
  // clearMessageRows();
341
  }
342
 
343
- function chatbotContentChanged(attempt = 1) {
344
  for (var i = 0; i < attempt; i++) {
345
  setTimeout(() => {
346
  // clearMessageRows();
347
  saveHistoryHtml();
348
  disableSendBtn();
349
- // gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.user').forEach((userElement) => {addAvatars(userElement, 'user')});
350
- // gradioApp().querySelectorAll('#chuanhu-chatbot > .wrapper > .wrap > .message-wrap .message-row.bot-row').forEach(addChuanhuButton);
351
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
352
- if (chatbotIndicator.classList.contains('hide')) {
 
353
  setLatestMessage();
354
  setChatList();
355
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  }, i === 0 ? 0 : 200);
357
  }
358
  // 理论上是不需要多次尝试执行的,可惜gradio的bug导致message可能没有渲染完毕,所以尝试500ms后再次执行
@@ -364,6 +377,10 @@ var chatbotObserver = new MutationObserver(() => {
364
  // setLatestMessage();
365
  chatbotContentChanged(2);
366
  }
 
 
 
 
367
  });
368
 
369
  var chatListObserver = new MutationObserver(() => {
 
57
  }
58
  }
59
 
60
+ chatbotObserver.observe(chatbotIndicator, { attributes: true, childList: true, subtree: true });
61
  chatListObserver.observe(chatListIndicator, { attributes: true });
62
  setUploader();
63
 
 
340
  // clearMessageRows();
341
  }
342
 
343
+ function chatbotContentChanged(attempt = 1, force = false) {
344
  for (var i = 0; i < attempt; i++) {
345
  setTimeout(() => {
346
  // clearMessageRows();
347
  saveHistoryHtml();
348
  disableSendBtn();
349
+
 
350
  gradioApp().querySelectorAll('#chuanhu-chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
351
+
352
+ if (chatbotIndicator.classList.contains('hide')) { // generation finished
353
  setLatestMessage();
354
  setChatList();
355
  }
356
+
357
+ if (!chatbotIndicator.classList.contains('translucent')) { // message deleted
358
+ var checkLatestAdded = setInterval(() => {
359
+ var latestMessageNow = gradioApp().querySelector('#chuanhu-chatbot > .wrapper > .wrap > .message-wrap .message.bot.latest');
360
+ if (latestMessageNow && latestMessageNow.querySelector('.message-btn-row')) {
361
+ clearInterval(checkLatestAdded);
362
+ } else {
363
+ setLatestMessage();
364
+ }
365
+ }, 200);
366
+ }
367
+
368
+
369
  }, i === 0 ? 0 : 200);
370
  }
371
  // 理论上是不需要多次尝试执行的,可惜gradio的bug导致message可能没有渲染完毕,所以尝试500ms后再次执行
 
377
  // setLatestMessage();
378
  chatbotContentChanged(2);
379
  }
380
+ if (!chatbotIndicator.classList.contains('translucent')) {
381
+ chatbotContentChanged(2);
382
+ }
383
+
384
  });
385
 
386
  var chatListObserver = new MutationObserver(() => {
web_assets/javascript/chat-list.js CHANGED
@@ -59,14 +59,19 @@ function saveChatHistory(a, b, c, d) {
59
  var fileName = b;
60
 
61
  while (true) {
62
- fileName = prompt(renameChat_i18n, fileName);
63
-
64
- if (isValidFileName(fileName)) {
65
- return [a, fileName, c, d];
 
 
 
 
66
  } else {
67
  alert(validFileName_i18n + "!@#$%^&*()<>?/\\|}{~:");
68
  }
69
  }
 
70
  }
71
 
72
  function isValidFileName(fileName) {
 
59
  var fileName = b;
60
 
61
  while (true) {
62
+ var result = prompt(renameChat_i18n, fileName);
63
+
64
+ if (result === null) {
65
+ throw new Error("rename operation cancelled");
66
+ // 不返回原文件名,而是使用 throw new Error() 打断程序,避免 gradio 进行保存操作
67
+ // break;
68
+ } else if (isValidFileName(result)) {
69
+ return [a, result, c, d];
70
  } else {
71
  alert(validFileName_i18n + "!@#$%^&*()<>?/\\|}{~:");
72
  }
73
  }
74
+ return [a, b, c, d]; // 兜底保障
75
  }
76
 
77
  function isValidFileName(fileName) {
web_assets/javascript/message-button.js CHANGED
@@ -144,7 +144,6 @@ function addLatestMessageButtons(botElement) {
144
  var gradioDelLastBtn = gradioApp().querySelector('#gr-dellast-btn');
145
  deleteButton.addEventListener('click', () => {
146
  gradioDelLastBtn.click();
147
- chatbotContentChanged(2);
148
  });
149
 
150
  messageBtnRowLeading.appendChild(regenerateButton);
 
144
  var gradioDelLastBtn = gradioApp().querySelector('#gr-dellast-btn');
145
  deleteButton.addEventListener('click', () => {
146
  gradioDelLastBtn.click();
 
147
  });
148
 
149
  messageBtnRowLeading.appendChild(regenerateButton);
web_assets/stylesheet/ChuanhuChat.css CHANGED
@@ -398,6 +398,7 @@ body.popup-open {
398
  /* padding: 8px 6px; */
399
  min-height: 82px;
400
  /* max-height: 166px; */
 
401
  background: var(--chatbot-blur-background-color);
402
  -webkit-backdrop-filter: blur(24px);
403
  backdrop-filter: blur(24px);
 
398
  /* padding: 8px 6px; */
399
  min-height: 82px;
400
  /* max-height: 166px; */
401
+ z-index: 2;
402
  background: var(--chatbot-blur-background-color);
403
  -webkit-backdrop-filter: blur(24px);
404
  backdrop-filter: blur(24px);