Tuchuanhuhuhu commited on
Commit
5754184
1 Parent(s): 5314ca6

加入是否显示SourceText的按钮

Browse files

Keldos修改了文件的缩进,避免显示过多diff

Files changed (2) hide show
  1. assets/custom.css +46 -0
  2. assets/custom.js +27 -9
assets/custom.css CHANGED
@@ -273,6 +273,52 @@ ol:not(.options), ul:not(.options) {
273
  outline: none;
274
  }
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  .message-wrap>div img{
277
  border-radius: 10px !important;
278
  }
 
273
  outline: none;
274
  }
275
 
276
+ .toggle-btn {
277
+ border-radius: 5px;
278
+ color: rgba(120, 120, 120, 0.64) !important;
279
+ padding: 4px !important;
280
+ position: absolute;
281
+ right: -22px;
282
+ bottom: 18px;
283
+ cursor: pointer !important;
284
+ transition: color .2s ease, background-color .2s ease;
285
+ }
286
+
287
+ .toggle-btn:hover {
288
+ background-color: rgba(167, 167, 167, 0.25) !important;
289
+ color: unset !important;
290
+ }
291
+
292
+ .toggle-btn:active {
293
+ background-color: rgba(167, 167, 167, 0.5) !important;
294
+ }
295
+
296
+ .toggle-btn:focus {
297
+ outline: none;
298
+ }
299
+
300
+ .raw-message {
301
+ display: none;
302
+ top: -18px;
303
+ left: 0;
304
+ right: 0;
305
+ border: 1px solid #dddddd;
306
+ padding: 8px;
307
+ border-radius: 5px;
308
+ box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.1);
309
+ }
310
+
311
+ .raw-message:before {
312
+ content: "Source Text";
313
+ display: block;
314
+ font-size: 12px;
315
+ top: -1.5em;
316
+ left: 8px;
317
+ padding: 2px 5px;
318
+ border-radius: 3px;
319
+ opacity: 0.8;
320
+ }
321
+
322
  .message-wrap>div img{
323
  border-radius: 10px !important;
324
  }
assets/custom.js CHANGED
@@ -274,33 +274,51 @@ function setChatbotHeight() {
274
 
275
  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>';
276
  const copiedIcon = '<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"><polyline points="20 6 9 17 4 12"></polyline></svg></span>';
 
 
277
  function addCopyBotButton(botElement) {
278
  var copyButton = null;
 
279
  var rawMessage = null;
280
  rawMessage = botElement.querySelector('.raw-message');
281
  copyButton = botElement.querySelector('button.copy-bot-btn');
 
282
  if (!rawMessage) return;
283
  if (copyButton) {
284
  copyButton.remove();
285
  }
286
- var button = document.createElement('button');
287
- button.classList.add('copy-bot-btn');
288
- button.setAttribute('aria-label', 'Copy');
289
- button.innerHTML = copyIcon;
290
- button.addEventListener('click', () => {
 
 
 
 
291
  const textToCopy = rawMessage.innerText;
292
  navigator.clipboard
293
  .writeText(textToCopy)
294
  .catch(() => {
295
  console.error("copy failed");
296
  });
297
- button.innerHTML = copiedIcon;
298
  setTimeout(() => {
299
- button.innerHTML = copyIcon;
300
  }, 1500);
301
  });
302
- botElement.appendChild(button);
303
- };
 
 
 
 
 
 
 
 
 
 
304
 
305
  var rendertime = 0; // for debugging
306
  var mathjaxUpdated = false;
 
274
 
275
  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>';
276
  const copiedIcon = '<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"><polyline points="20 6 9 17 4 12"></polyline></svg></span>';
277
+ const toggleIcon = '<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="4" y="4" width="16" height="16" rx="2" ry="2"></rect><circle cx="8" cy="12" r="2"></circle><circle cx="16" cy="12" r="2"></circle></svg></span>';
278
+
279
  function addCopyBotButton(botElement) {
280
  var copyButton = null;
281
+ var toggleButton = null;
282
  var rawMessage = null;
283
  rawMessage = botElement.querySelector('.raw-message');
284
  copyButton = botElement.querySelector('button.copy-bot-btn');
285
+ toggleButton = botElement.querySelector('button.toggle-btn');
286
  if (!rawMessage) return;
287
  if (copyButton) {
288
  copyButton.remove();
289
  }
290
+ if (toggleButton) {
291
+ toggleButton.remove();
292
+ }
293
+ rawMessage.style.display = "none";
294
+ var copyButton = document.createElement('button');
295
+ copyButton.classList.add('copy-bot-btn');
296
+ copyButton.setAttribute('aria-label', 'Copy');
297
+ copyButton.innerHTML = copyIcon;
298
+ copyButton.addEventListener('click', () => {
299
  const textToCopy = rawMessage.innerText;
300
  navigator.clipboard
301
  .writeText(textToCopy)
302
  .catch(() => {
303
  console.error("copy failed");
304
  });
305
+ copyButton.innerHTML = copiedIcon;
306
  setTimeout(() => {
307
+ copyButton.innerHTML = copyIcon;
308
  }, 1500);
309
  });
310
+ botElement.appendChild(copyButton);
311
+
312
+ // Toggle button
313
+ var toggleButton = document.createElement('button');
314
+ toggleButton.classList.add('toggle-btn');
315
+ toggleButton.setAttribute('aria-label', 'Toggle');
316
+ toggleButton.innerHTML = toggleIcon;
317
+ toggleButton.addEventListener('click', () => {
318
+ rawMessage.style.display === "none" ? rawMessage.style.display = "block" : rawMessage.style.display = "none";
319
+ });
320
+ botElement.insertBefore(toggleButton, copyButton);
321
+ }
322
 
323
  var rendertime = 0; // for debugging
324
  var mathjaxUpdated = false;