Keldos commited on
Commit
7aee8f2
·
1 Parent(s): e30b4e3

feat: add generating loader when new bot message is empty

Browse files
web_assets/javascript/message-button.js CHANGED
@@ -83,6 +83,7 @@ function addChuanhuButton(botElement) {
83
 
84
  // if (!isLatestMessage) botElement.querySelector('.message-btn-row')?.remove();
85
  setLatestMessage();
 
86
 
87
  // 改成生成时不添加按钮好了……
88
  if (chatbotIndicator.classList.contains('generating')) return;
@@ -194,6 +195,7 @@ function setLatestMessage() {
194
  } else {
195
  message.classList.remove('latest');
196
  message.querySelector('.message-btn-row')?.remove();
 
197
  }
198
  });
199
  if (chatbotIndicator.classList.contains('generating')) return;
@@ -269,6 +271,20 @@ function addLatestMessageButtons(botElement) {
269
  messageBtnRowTrailing.appendChild(dislikeButton);
270
  }
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
  // button svg code
274
  const copyIcon = '<span><svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height=".8em" width=".8em" xmlns="http://www.w3.org/2000/svg"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg></span>';
 
83
 
84
  // if (!isLatestMessage) botElement.querySelector('.message-btn-row')?.remove();
85
  setLatestMessage();
86
+ addGeneratingLoader(botElement);
87
 
88
  // 改成生成时不添加按钮好了……
89
  if (chatbotIndicator.classList.contains('generating')) return;
 
195
  } else {
196
  message.classList.remove('latest');
197
  message.querySelector('.message-btn-row')?.remove();
198
+ message.querySelector('.generating-loader')?.remove();
199
  }
200
  });
201
  if (chatbotIndicator.classList.contains('generating')) return;
 
271
  messageBtnRowTrailing.appendChild(dislikeButton);
272
  }
273
 
274
+ function addGeneratingLoader(botElement) {
275
+ if (botElement.innerText.trim() === '' && chatbotIndicator.classList.contains('generating')) {
276
+ var generatingLoader = document.createElement('div');
277
+ generatingLoader.classList.add('generating-loader');
278
+ botElement.appendChild(generatingLoader);
279
+ thisMessageObserver = new MutationObserver((mutations) => {
280
+ botElement.querySelector('.generating-loader')?.remove();
281
+ thisMessageObserver.disconnect();
282
+ });
283
+ thisMessageObserver.observe(botElement, { childList: true, attributes: true, subtree: true});
284
+ } else {
285
+ botElement.querySelector('.generating-loader')?.remove();
286
+ }
287
+ }
288
 
289
  // button svg code
290
  const copyIcon = '<span><svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" height=".8em" width=".8em" xmlns="http://www.w3.org/2000/svg"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg></span>';
web_assets/stylesheet/ChuanhuChat.css CHANGED
@@ -1251,6 +1251,29 @@ button:active .icon-need-hover, button:active.icon-need-hover {
1251
  }
1252
  }
1253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1254
  /* .main-body {
1255
  flex-wrap: nowrap;
1256
  gap: 0;
 
1251
  }
1252
  }
1253
 
1254
+ .generating-loader {
1255
+ height: 12px;
1256
+ width: 48px;
1257
+ aspect-ratio: 4;
1258
+ --_g: no-repeat radial-gradient(farthest-side, var(--body-text-color) 90%,#0000);
1259
+ background: var(--_g), var(--_g), var(--_g), var(--_g);
1260
+ background-size: 12% 48%;
1261
+ animation: generating-dots 1s infinite linear;
1262
+ opacity: 0.3;
1263
+ margin: 6px 4.5px;
1264
+ }
1265
+
1266
+ @keyframes generating-dots {
1267
+ 0% {background-position: calc(0*100%/3) 50% ,calc(1*100%/3) 50% ,calc(2*100%/3) 50% ,calc(3*100%/3) 50% }
1268
+ 16.67% {background-position: calc(0*100%/3) 0 ,calc(1*100%/3) 50% ,calc(2*100%/3) 50% ,calc(3*100%/3) 50% }
1269
+ 33.33% {background-position: calc(0*100%/3) 100%,calc(1*100%/3) 0 ,calc(2*100%/3) 50% ,calc(3*100%/3) 50% }
1270
+ 50% {background-position: calc(0*100%/3) 50% ,calc(1*100%/3) 100%,calc(2*100%/3) 0 ,calc(3*100%/3) 50% }
1271
+ 66.67% {background-position: calc(0*100%/3) 50% ,calc(1*100%/3) 50% ,calc(2*100%/3) 100%,calc(3*100%/3) 0 }
1272
+ 83.33% {background-position: calc(0*100%/3) 50% ,calc(1*100%/3) 50% ,calc(2*100%/3) 50% ,calc(3*100%/3) 100%}
1273
+ 100% {background-position: calc(0*100%/3) 50% ,calc(1*100%/3) 50% ,calc(2*100%/3) 50% ,calc(3*100%/3) 50% }
1274
+ }
1275
+
1276
+
1277
  /* .main-body {
1278
  flex-wrap: nowrap;
1279
  gap: 0;