remove dom queries and jQuery during streaming

ded6536b062d3fc34c2ab48656fc5cc35fbcf074

LenAnderson <Anderson.Len@outlook.com>

1 files changed, +14 -5Ignore whitespace
public/script.js+14 -5
@@ -2797,6 +2797,10 @@ class StreamingProcessor {
2797 constructor(type, force_name2, timeStarted, messageAlreadyGenerated) {2797 constructor(type, force_name2, timeStarted, messageAlreadyGenerated) {
2798 this.result = '';2798 this.result = '';
2799 this.messageId = -1;2799 this.messageId = -1;
2800 this.messageDom = null;
2801 this.messageTextDom = null;
2802 this.messageTimerDom = null;
2803 this.sendTextarea = document.querySelector('#send_textarea');
2800 this.type = type;2804 this.type = type;
2801 this.force_name2 = force_name2;2805 this.force_name2 = force_name2;
2802 this.isStopped = false;2806 this.isStopped = false;
@@ -2833,11 +2837,15 @@ class StreamingProcessor {
2833 let messageId = -1;2837 let messageId = -1;
28342838
2835 if (this.type == 'impersonate') {2839 if (this.type == 'impersonate') {
2836 $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));2840 this.sendTextarea.value = '';
2841 this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true }));
2837 }2842 }
2838 else {2843 else {
2839 await saveReply(this.type, text, true);2844 await saveReply(this.type, text, true);
2840 messageId = chat.length - 1;2845 messageId = chat.length - 1;
2846 this.messageDom = document.querySelector(`#chat .mes[mesid="${messageId}"]`);
2847 this.messageTextDom = this.messageDom.querySelector('.mes_text');
2848 this.messageTimerDom = this.messageDom.querySelector('.mes_timer');
2841 this.showMessageButtons(messageId);2849 this.showMessageButtons(messageId);
2842 }2850 }
28432851
@@ -2869,7 +2877,8 @@ class StreamingProcessor {
2869 }2877 }
28702878
2871 if (isImpersonate) {2879 if (isImpersonate) {
2872 $('#send_textarea').val(processedText)[0].dispatchEvent(new Event('input', { bubbles: true }));2880 this.sendTextarea.value = processedText;
2881 this.sendTextarea.dispatchEvent(new Event('input', { bubbles: true }));
2873 }2882 }
2874 else {2883 else {
2875 let currentTime = new Date();2884 let currentTime = new Date();
@@ -2902,9 +2911,9 @@ class StreamingProcessor {
2902 chat[messageId].is_user,2911 chat[messageId].is_user,
2903 messageId,2912 messageId,
2904 );2913 );
2905 const mesText = $(`#chat .mes[mesid="${messageId}"] .mes_text`);2914 this.messageTextDom.innerHTML = formattedText;
2906 mesText.html(formattedText);2915 this.messageTimerDom.textContent = timePassed.timerValue;
2907 $(`#chat .mes[mesid="${messageId}"] .mes_timer`).text(timePassed.timerValue).attr('title', timePassed.timerTitle);2916 this.messageTimerDom.title = timePassed.timerTitle;
2908 this.setFirstSwipe(messageId);2917 this.setFirstSwipe(messageId);
2909 }2918 }
29102919