Keldos commited on
Commit
e1ee750
·
1 Parent(s): a788e7c

refactor & fix: 加载旧历史记录时避免显示新按钮

Browse files
Files changed (1) hide show
  1. assets/custom.js +13 -6
assets/custom.js CHANGED
@@ -277,13 +277,18 @@ function addChuanhuButton(botElement) {
277
  var mdMessage = null;
278
  rawMessage = botElement.querySelector('.raw-message');
279
  mdMessage = botElement.querySelector('.md-message');
 
 
 
 
 
 
 
280
  var renderMarkdown = true;
281
  var copyButton = null;
282
  var toggleButton = null;
283
  copyButton = botElement.querySelector('button.copy-bot-btn');
284
  toggleButton = botElement.querySelector('button.toggle-md-btn');
285
-
286
- if (!rawMessage) return;
287
  if (copyButton) copyButton.remove();
288
  if (toggleButton) toggleButton.remove();
289
 
@@ -297,13 +302,15 @@ function addChuanhuButton(botElement) {
297
  const textToCopy = rawMessage.innerText;
298
  navigator.clipboard
299
  .writeText(textToCopy)
 
 
 
 
 
 
300
  .catch(() => {
301
  console.error("copy failed");
302
  });
303
- copyButton.innerHTML = copiedIcon;
304
- setTimeout(() => {
305
- copyButton.innerHTML = copyIcon;
306
- }, 1500);
307
  });
308
  botElement.appendChild(copyButton);
309
 
 
277
  var mdMessage = null;
278
  rawMessage = botElement.querySelector('.raw-message');
279
  mdMessage = botElement.querySelector('.md-message');
280
+ if (!rawMessage) {
281
+ var buttons = botElement.querySelectorAll('button.chuanhu-btn');
282
+ for (var i = 0; i < buttons.length; i++) {
283
+ buttons[i].parentNode.removeChild(buttons[i]);
284
+ }
285
+ return;
286
+ }
287
  var renderMarkdown = true;
288
  var copyButton = null;
289
  var toggleButton = null;
290
  copyButton = botElement.querySelector('button.copy-bot-btn');
291
  toggleButton = botElement.querySelector('button.toggle-md-btn');
 
 
292
  if (copyButton) copyButton.remove();
293
  if (toggleButton) toggleButton.remove();
294
 
 
302
  const textToCopy = rawMessage.innerText;
303
  navigator.clipboard
304
  .writeText(textToCopy)
305
+ .then(() => {
306
+ copyButton.innerHTML = copiedIcon;
307
+ setTimeout(() => {
308
+ copyButton.innerHTML = copyIcon;
309
+ }, 1500);
310
+ })
311
  .catch(() => {
312
  console.error("copy failed");
313
  });
 
 
 
 
314
  });
315
  botElement.appendChild(copyButton);
316