Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
•
3f2303a
1
Parent(s):
d16fdf3
refactor: 删除原有latex渲染相关的js
Browse files- assets/custom.js +1 -72
assets/custom.js
CHANGED
@@ -17,13 +17,11 @@ var chatbotWrap = null;
|
|
17 |
var apSwitch = null;
|
18 |
var empty_botton = null;
|
19 |
var messageBotDivs = null;
|
20 |
-
// var renderLatex = null;
|
21 |
var loginUserForm = null;
|
22 |
var logginUser = null;
|
23 |
|
24 |
var userLogged = false;
|
25 |
var usernameGotten = false;
|
26 |
-
var shouldRenderLatex = false;
|
27 |
var historyLoaded = false;
|
28 |
|
29 |
var ga = document.getElementsByTagName("gradio-app");
|
@@ -51,7 +49,6 @@ function gradioLoaded(mutations) {
|
|
51 |
chatbot = document.querySelector('#chuanhu_chatbot');
|
52 |
chatbotWrap = document.querySelector('#chuanhu_chatbot > .wrap');
|
53 |
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
54 |
-
// renderLatex = document.querySelector("#render_latex_checkbox > label > input");
|
55 |
empty_botton = document.getElementById("empty_btn")
|
56 |
|
57 |
if (loginUserForm) {
|
@@ -80,10 +77,6 @@ function gradioLoaded(mutations) {
|
|
80 |
}
|
81 |
setChatbotScroll();
|
82 |
}
|
83 |
-
// if (renderLatex) { // renderLatex 加载出来了没?
|
84 |
-
// shouldRenderLatex = renderLatex.checked;
|
85 |
-
// updateMathJax();
|
86 |
-
// }
|
87 |
if (empty_botton) {
|
88 |
emptyHistory();
|
89 |
}
|
@@ -390,70 +383,15 @@ function removeMarkdownText(message) {
|
|
390 |
if (mdDiv) mdDiv.classList.add('hideM');
|
391 |
}
|
392 |
|
393 |
-
var rendertime = 0; // for debugging
|
394 |
-
var mathjaxUpdated = false;
|
395 |
-
|
396 |
-
function renderMathJax() {
|
397 |
-
messageBotDivs = document.querySelectorAll('.message.bot .md-message');
|
398 |
-
for (var i = 0; i < messageBotDivs.length; i++) {
|
399 |
-
var mathJaxSpan = messageBotDivs[i].querySelector('.MathJax_Preview');
|
400 |
-
if (!mathJaxSpan && shouldRenderLatex && !mathjaxUpdated) {
|
401 |
-
MathJax.Hub.Queue(["Typeset", MathJax.Hub, messageBotDivs[i]]);
|
402 |
-
rendertime +=1; // for debugging
|
403 |
-
// console.log("renderingMathJax", i)
|
404 |
-
}
|
405 |
-
}
|
406 |
-
mathjaxUpdated = true;
|
407 |
-
// console.log("MathJax Rendered")
|
408 |
-
}
|
409 |
-
|
410 |
-
function removeMathjax() {
|
411 |
-
// var jax = MathJax.Hub.getAllJax();
|
412 |
-
// for (var i = 0; i < jax.length; i++) {
|
413 |
-
// // MathJax.typesetClear(jax[i]);
|
414 |
-
// jax[i].Text(newmath)
|
415 |
-
// jax[i].Reprocess()
|
416 |
-
// }
|
417 |
-
// 我真的不会了啊啊啊,mathjax并没有提供转换为原先文本的办法。
|
418 |
-
mathjaxUpdated = true;
|
419 |
-
// console.log("MathJax removed!");
|
420 |
-
}
|
421 |
-
|
422 |
-
function updateMathJax() {
|
423 |
-
// renderLatex.addEventListener("change", function() {
|
424 |
-
// shouldRenderLatex = renderLatex.checked;
|
425 |
-
// if (!mathjaxUpdated) {
|
426 |
-
// if (shouldRenderLatex) {
|
427 |
-
// renderMathJax();
|
428 |
-
// } else {
|
429 |
-
// console.log("MathJax Disabled")
|
430 |
-
// removeMathjax();
|
431 |
-
// }
|
432 |
-
// } else {
|
433 |
-
// if (!shouldRenderLatex) {
|
434 |
-
// mathjaxUpdated = false; // reset
|
435 |
-
// }
|
436 |
-
// }
|
437 |
-
// });
|
438 |
-
if (shouldRenderLatex && !mathjaxUpdated) {
|
439 |
-
renderMathJax();
|
440 |
-
}
|
441 |
-
mathjaxUpdated = false;
|
442 |
-
}
|
443 |
-
|
444 |
let timeoutId;
|
445 |
let isThrottled = false;
|
446 |
var mmutation
|
447 |
-
// 监听所有元素中 bot message
|
448 |
var mObserver = new MutationObserver(function (mutationsList) {
|
449 |
for (mmutation of mutationsList) {
|
450 |
if (mmutation.type === 'childList') {
|
451 |
for (var node of mmutation.addedNodes) {
|
452 |
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
453 |
-
if (shouldRenderLatex) {
|
454 |
-
renderMathJax();
|
455 |
-
mathjaxUpdated = false;
|
456 |
-
}
|
457 |
saveHistoryHtml();
|
458 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
459 |
}
|
@@ -463,10 +401,6 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|
463 |
}
|
464 |
for (var node of mmutation.removedNodes) {
|
465 |
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
466 |
-
if (shouldRenderLatex) {
|
467 |
-
renderMathJax();
|
468 |
-
mathjaxUpdated = false;
|
469 |
-
}
|
470 |
saveHistoryHtml();
|
471 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
472 |
}
|
@@ -478,10 +412,6 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|
478 |
clearTimeout(timeoutId);
|
479 |
timeoutId = setTimeout(() => {
|
480 |
isThrottled = false;
|
481 |
-
if (shouldRenderLatex) {
|
482 |
-
renderMathJax();
|
483 |
-
mathjaxUpdated = false;
|
484 |
-
}
|
485 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
486 |
saveHistoryHtml();
|
487 |
}, 500);
|
@@ -556,7 +486,6 @@ observer.observe(targetNode, { childList: true, subtree: true });
|
|
556 |
window.addEventListener("DOMContentLoaded", function () {
|
557 |
isInIframe = (window.self !== window.top);
|
558 |
historyLoaded = false;
|
559 |
-
shouldRenderLatex = !!document.querySelector('script[src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"]');
|
560 |
});
|
561 |
window.addEventListener('resize', setChatbotHeight);
|
562 |
window.addEventListener('scroll', setChatbotHeight);
|
|
|
17 |
var apSwitch = null;
|
18 |
var empty_botton = null;
|
19 |
var messageBotDivs = null;
|
|
|
20 |
var loginUserForm = null;
|
21 |
var logginUser = null;
|
22 |
|
23 |
var userLogged = false;
|
24 |
var usernameGotten = false;
|
|
|
25 |
var historyLoaded = false;
|
26 |
|
27 |
var ga = document.getElementsByTagName("gradio-app");
|
|
|
49 |
chatbot = document.querySelector('#chuanhu_chatbot');
|
50 |
chatbotWrap = document.querySelector('#chuanhu_chatbot > .wrap');
|
51 |
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
|
|
52 |
empty_botton = document.getElementById("empty_btn")
|
53 |
|
54 |
if (loginUserForm) {
|
|
|
77 |
}
|
78 |
setChatbotScroll();
|
79 |
}
|
|
|
|
|
|
|
|
|
80 |
if (empty_botton) {
|
81 |
emptyHistory();
|
82 |
}
|
|
|
383 |
if (mdDiv) mdDiv.classList.add('hideM');
|
384 |
}
|
385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
let timeoutId;
|
387 |
let isThrottled = false;
|
388 |
var mmutation
|
389 |
+
// 监听所有元素中 bot message 的变化,为 bot 消息添加复制按钮。
|
390 |
var mObserver = new MutationObserver(function (mutationsList) {
|
391 |
for (mmutation of mutationsList) {
|
392 |
if (mmutation.type === 'childList') {
|
393 |
for (var node of mmutation.addedNodes) {
|
394 |
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
|
|
|
|
|
|
|
|
395 |
saveHistoryHtml();
|
396 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
397 |
}
|
|
|
401 |
}
|
402 |
for (var node of mmutation.removedNodes) {
|
403 |
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
|
|
|
|
|
|
|
|
404 |
saveHistoryHtml();
|
405 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
406 |
}
|
|
|
412 |
clearTimeout(timeoutId);
|
413 |
timeoutId = setTimeout(() => {
|
414 |
isThrottled = false;
|
|
|
|
|
|
|
|
|
415 |
document.querySelectorAll('#chuanhu_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
416 |
saveHistoryHtml();
|
417 |
}, 500);
|
|
|
486 |
window.addEventListener("DOMContentLoaded", function () {
|
487 |
isInIframe = (window.self !== window.top);
|
488 |
historyLoaded = false;
|
|
|
489 |
});
|
490 |
window.addEventListener('resize', setChatbotHeight);
|
491 |
window.addEventListener('scroll', setChatbotHeight);
|