Write.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. createChat(thisChatType).then((r) => {
  2. if(r.ok) talk = r.obj;
  3. });
  4. /**重写重置聊天到初始状态函数 */
  5. function reSetStartChatMessage(type) {
  6. chat.innerHTML = ``;
  7. isSpeaking = false;
  8. }
  9. /**重写函数 */
  10. function isSpeakingStart(chatWithMagic, sendText) {
  11. isSpeaking = true;
  12. }
  13. //重写
  14. function isSpeakingFinish() {
  15. isSpeaking = false;
  16. }
  17. //重写send函数
  18. oldSend = send;
  19. send = (text) => {
  20. reSetStartChatMessage();
  21. oldSend(text);
  22. }
  23. //重写porserTextBlock函数
  24. /*
  25. 解析TextBlock body.type==TextBlock
  26. */
  27. function porserTextBlock(body, father) {
  28. if (!body.size) {
  29. let div = getByClass('textBlock', 'div', father, 'markdown-body');
  30. div.innerHTML = marked.marked(completeCodeBlock(body.text));
  31. renderMathInElement(div,renderMathInElementOptions);
  32. let aaas = div.getElementsByTagName('a');
  33. //将超链接在新页面打开
  34. for(let i=0;i<aaas.length;i++){
  35. aaas[i].target = '_blank';
  36. }
  37. //如果是注释则加上上标样式
  38. for(let i=0;i<aaas.length;i++){
  39. let reg = new RegExp('^\\^(\\d+)\\^$');
  40. if(reg.test(aaas[i].innerHTML)){
  41. aaas[i].innerHTML = aaas[i].innerHTML.replace(reg,'$1');
  42. aaas[i].classList.add('superscript');
  43. }
  44. }
  45. } else if (body.size == 'small') {
  46. //原本bing官网的small并没有输出
  47. }
  48. }
  49. //重写send按钮点击事件
  50. send_button.onclick = () => {
  51. let text = input_text.value;
  52. send(text);
  53. };