Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
a3f3ca9
1
Parent(s):
76d9dc2
hotfix: 解决首条消息无法加载按钮和存储历史记录的问题
Browse files- assets/custom.js +12 -2
assets/custom.js
CHANGED
@@ -20,6 +20,7 @@ var loginUserForm = null;
|
|
20 |
var logginUser = null;
|
21 |
var updateToast = null;
|
22 |
var sendBtn = null;
|
|
|
23 |
var sliders = null;
|
24 |
|
25 |
var userLogged = false;
|
@@ -75,6 +76,7 @@ function gradioLoaded(mutations) {
|
|
75 |
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
76 |
updateToast = document.querySelector("#toast-update");
|
77 |
sendBtn = document.getElementById("submit_btn");
|
|
|
78 |
sliders = document.querySelectorAll('input[type="range"]');
|
79 |
|
80 |
if (loginUserForm) {
|
@@ -114,6 +116,9 @@ function gradioLoaded(mutations) {
|
|
114 |
updateLatestVersion();
|
115 |
}
|
116 |
}
|
|
|
|
|
|
|
117 |
}
|
118 |
}
|
119 |
}
|
@@ -453,7 +458,7 @@ function removeMarkdownText(message) {
|
|
453 |
let timeoutId;
|
454 |
let isThrottled = false;
|
455 |
var mmutation
|
456 |
-
//
|
457 |
var mObserver = new MutationObserver(function (mutationsList) {
|
458 |
for (mmutation of mutationsList) {
|
459 |
if (mmutation.type === 'childList') {
|
@@ -471,7 +476,7 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|
471 |
document.querySelectorAll('#chuanhu_chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
|
472 |
}
|
473 |
}
|
474 |
-
} else if (mmutation.type === 'attributes'
|
475 |
if (isThrottled) break; // 为了防止重复不断疯狂渲染,加上等待_(:з」∠)_
|
476 |
isThrottled = true;
|
477 |
clearTimeout(timeoutId);
|
@@ -486,6 +491,11 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|
486 |
});
|
487 |
// mObserver.observe(targetNode, { attributes: true, childList: true, subtree: true, characterData: true});
|
488 |
|
|
|
|
|
|
|
|
|
|
|
489 |
var loadhistorytime = 0; // for debugging
|
490 |
function saveHistoryHtml() {
|
491 |
var historyHtml = document.querySelector('#chuanhu_chatbot>.wrapper>.wrap');
|
|
|
20 |
var logginUser = null;
|
21 |
var updateToast = null;
|
22 |
var sendBtn = null;
|
23 |
+
var cancelBtn = null;
|
24 |
var sliders = null;
|
25 |
|
26 |
var userLogged = false;
|
|
|
76 |
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
77 |
updateToast = document.querySelector("#toast-update");
|
78 |
sendBtn = document.getElementById("submit_btn");
|
79 |
+
cancelBtn = document.getElementById("cancel_btn");
|
80 |
sliders = document.querySelectorAll('input[type="range"]');
|
81 |
|
82 |
if (loginUserForm) {
|
|
|
116 |
updateLatestVersion();
|
117 |
}
|
118 |
}
|
119 |
+
if (cancelBtn) {
|
120 |
+
submitObserver.observe(cancelBtn, { attributes: true, characterData: true});
|
121 |
+
}
|
122 |
}
|
123 |
}
|
124 |
}
|
|
|
458 |
let timeoutId;
|
459 |
let isThrottled = false;
|
460 |
var mmutation
|
461 |
+
// 监听chatWrap元素的变化,为 bot 消息添加复制按钮。
|
462 |
var mObserver = new MutationObserver(function (mutationsList) {
|
463 |
for (mmutation of mutationsList) {
|
464 |
if (mmutation.type === 'childList') {
|
|
|
476 |
document.querySelectorAll('#chuanhu_chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
|
477 |
}
|
478 |
}
|
479 |
+
} else if (mmutation.type === 'attributes') {
|
480 |
if (isThrottled) break; // 为了防止重复不断疯狂渲染,加上等待_(:з」∠)_
|
481 |
isThrottled = true;
|
482 |
clearTimeout(timeoutId);
|
|
|
491 |
});
|
492 |
// mObserver.observe(targetNode, { attributes: true, childList: true, subtree: true, characterData: true});
|
493 |
|
494 |
+
var submitObserver = new MutationObserver(function (mutationsList) {
|
495 |
+
document.querySelectorAll('#chuanhu_chatbot .message-wrap .message.bot').forEach(addChuanhuButton);
|
496 |
+
saveHistoryHtml();
|
497 |
+
});
|
498 |
+
|
499 |
var loadhistorytime = 0; // for debugging
|
500 |
function saveHistoryHtml() {
|
501 |
var historyHtml = document.querySelector('#chuanhu_chatbot>.wrapper>.wrap');
|