Keldos commited on
Commit
1c21e1a
1 Parent(s): 5754184

refactor: 简化附加btn的CSS写法

Browse files
Files changed (2) hide show
  1. assets/custom.css +13 -32
  2. assets/custom.js +7 -5
assets/custom.css CHANGED
@@ -251,53 +251,34 @@ ol:not(.options), ul:not(.options) {
251
  display: none;
252
  }
253
 
254
- .copy-bot-btn {
 
255
  border-radius: 5px;
256
  /* background-color: #E6E6E6 !important; */
257
  color: rgba(120, 120, 120, 0.64) !important;
258
  padding: 4px !important;
259
  position: absolute;
260
  right: -22px;
261
- bottom: 0;
262
  cursor: pointer !important;
263
  transition: color .2s ease, background-color .2s ease;
264
  }
265
- .copy-bot-btn:hover {
266
  background-color: rgba(167, 167, 167, 0.25) !important;
267
  color: unset !important;
268
  }
269
- .copy-bot-btn:active {
270
  background-color: rgba(167, 167, 167, 0.5) !important;
271
  }
272
- .copy-bot-btn:focus {
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;
@@ -306,9 +287,9 @@ ol:not(.options), ul:not(.options) {
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;
@@ -317,7 +298,7 @@ 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;
 
251
  display: none;
252
  }
253
 
254
+
255
+ .chuanhu-btn {
256
  border-radius: 5px;
257
  /* background-color: #E6E6E6 !important; */
258
  color: rgba(120, 120, 120, 0.64) !important;
259
  padding: 4px !important;
260
  position: absolute;
261
  right: -22px;
 
262
  cursor: pointer !important;
263
  transition: color .2s ease, background-color .2s ease;
264
  }
265
+ .chuanhu-btn:hover {
266
  background-color: rgba(167, 167, 167, 0.25) !important;
267
  color: unset !important;
268
  }
269
+ .chuanhu-btn:active {
270
  background-color: rgba(167, 167, 167, 0.5) !important;
271
  }
272
+ .chuanhu-btn:focus {
273
  outline: none;
274
  }
275
+ .copy-bot-btn {
276
+ bottom: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  }
278
+ .toggle-md-btn {
279
+ bottom: 18px;
 
280
  }
281
+ /* .raw-message {
 
282
  display: none;
283
  top: -18px;
284
  left: 0;
 
287
  padding: 8px;
288
  border-radius: 5px;
289
  box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.1);
290
+ } */
291
 
292
+ /* .raw-message:before {
293
  content: "Source Text";
294
  display: block;
295
  font-size: 12px;
 
298
  padding: 2px 5px;
299
  border-radius: 3px;
300
  opacity: 0.8;
301
+ } */
302
 
303
  .message-wrap>div img{
304
  border-radius: 10px !important;
assets/custom.js CHANGED
@@ -276,13 +276,13 @@ const copyIcon = '<span><svg stroke="currentColor" fill="none" stroke-width="2
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();
@@ -292,6 +292,7 @@ function addCopyBotButton(botElement) {
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;
@@ -311,7 +312,8 @@ function addCopyBotButton(botElement) {
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', () => {
@@ -408,7 +410,7 @@ var mObserver = new MutationObserver(function (mutationsList) {
408
  renderMathJax();
409
  mathjaxUpdated = false;
410
  }
411
- document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addCopyBotButton);
412
  saveHistoryHtml();
413
  }, 500);
414
  }
@@ -438,7 +440,7 @@ function loadHistoryHtml() {
438
  if (!historyLoaded) {
439
  var tempDiv = document.createElement('div');
440
  tempDiv.innerHTML = historyHtml;
441
- var buttons = tempDiv.querySelectorAll('button.copy-bot-btn');
442
  for (var i = 0; i < buttons.length; i++) {
443
  buttons[i].parentNode.removeChild(buttons[i]);
444
  }
 
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 addChuanhuButton(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-md-btn');
286
  if (!rawMessage) return;
287
  if (copyButton) {
288
  copyButton.remove();
 
292
  }
293
  rawMessage.style.display = "none";
294
  var copyButton = document.createElement('button');
295
+ copyButton.classList.add('chuanhu-btn');
296
  copyButton.classList.add('copy-bot-btn');
297
  copyButton.setAttribute('aria-label', 'Copy');
298
  copyButton.innerHTML = copyIcon;
 
312
 
313
  // Toggle button
314
  var toggleButton = document.createElement('button');
315
+ toggleButton.classList.add('chuanhu-btn');
316
+ toggleButton.classList.add('toggle-md-btn');
317
  toggleButton.setAttribute('aria-label', 'Toggle');
318
  toggleButton.innerHTML = toggleIcon;
319
  toggleButton.addEventListener('click', () => {
 
410
  renderMathJax();
411
  mathjaxUpdated = false;
412
  }
413
+ document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
414
  saveHistoryHtml();
415
  }, 500);
416
  }
 
440
  if (!historyLoaded) {
441
  var tempDiv = document.createElement('div');
442
  tempDiv.innerHTML = historyHtml;
443
+ var buttons = tempDiv.querySelectorAll('button.chuanhu-btn');
444
  for (var i = 0; i < buttons.length; i++) {
445
  buttons[i].parentNode.removeChild(buttons[i]);
446
  }