Keldos commited on
Commit
e7d04a4
·
1 Parent(s): b791a35

feat: 点击“新的对话”按钮清空的历史显示

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +1 -1
  2. assets/custom.js +16 -0
ChuanhuChatbot.py CHANGED
@@ -62,7 +62,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
62
  cancelBtn = gr.Button(value="", variant="secondary", visible=False, elem_id="cancel_btn")
63
  with gr.Row():
64
  emptyBtn = gr.Button(
65
- i18n("🧹 新的对话"),
66
  )
67
  retryBtn = gr.Button(i18n("🔄 重新生成"))
68
  delFirstBtn = gr.Button(i18n("🗑️ 删除最旧对话"))
 
62
  cancelBtn = gr.Button(value="", variant="secondary", visible=False, elem_id="cancel_btn")
63
  with gr.Row():
64
  emptyBtn = gr.Button(
65
+ i18n("🧹 新的对话"), elem_id="empty_btn"
66
  )
67
  retryBtn = gr.Button(i18n("🔄 重新生成"))
68
  delFirstBtn = gr.Button(i18n("🗑️ 删除最旧对话"))
assets/custom.js CHANGED
@@ -15,6 +15,7 @@ var appTitleDiv = null;
15
  var chatbot = null;
16
  var chatbotWrap = null;
17
  var apSwitch = null;
 
18
  var messageBotDivs = null;
19
  var renderLatex = null;
20
  var shouldRenderLatex = false;
@@ -36,6 +37,7 @@ function gradioLoaded(mutations) {
36
  chatbotWrap = document.querySelector('#chuanhu_chatbot > .wrap');
37
  apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
38
  renderLatex = document.querySelector("#render_latex_checkbox > label > input");
 
39
 
40
  if (gradioContainer && apSwitch) { // gradioCainter 加载出来了没?
41
  adjustDarkMode();
@@ -58,6 +60,9 @@ function gradioLoaded(mutations) {
58
  shouldRenderLatex = renderLatex.checked;
59
  updateMathJax();
60
  }
 
 
 
61
  }
62
  }
63
  }
@@ -354,6 +359,17 @@ function loadHistoryHtml() {
354
  }
355
  }
356
 
 
 
 
 
 
 
 
 
 
 
 
357
  // 监视页面内部 DOM 变动
358
  var observer = new MutationObserver(function (mutations) {
359
  gradioLoaded(mutations);
 
15
  var chatbot = null;
16
  var chatbotWrap = null;
17
  var apSwitch = null;
18
+ var empty_botton = null;
19
  var messageBotDivs = null;
20
  var renderLatex = null;
21
  var shouldRenderLatex = false;
 
37
  chatbotWrap = document.querySelector('#chuanhu_chatbot > .wrap');
38
  apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
39
  renderLatex = document.querySelector("#render_latex_checkbox > label > input");
40
+ empty_botton = document.getElementById("empty_btn")
41
 
42
  if (gradioContainer && apSwitch) { // gradioCainter 加载出来了没?
43
  adjustDarkMode();
 
60
  shouldRenderLatex = renderLatex.checked;
61
  updateMathJax();
62
  }
63
+ if (empty_botton) {
64
+ emptyHistory();
65
+ }
66
  }
67
  }
68
  }
 
359
  }
360
  }
361
 
362
+ function emptyHistory (){
363
+ empty_botton.addEventListener("click", function () {
364
+ localStorage.removeItem("chatHistory");
365
+ historyMessages = chatbotWrap.querySelector('.history-message');
366
+ if (historyMessages) {
367
+ chatbotWrap.removeChild(historyMessages);
368
+ console.log("History Cleared");
369
+ }
370
+ });
371
+ }
372
+
373
  // 监视页面内部 DOM 变动
374
  var observer = new MutationObserver(function (mutations) {
375
  gradioLoaded(mutations);