|
102 | 102 | // ===== Voice Preparing Toast ===== |
103 | 103 | var voiceAnimInjected = false; |
104 | 104 | var spinAnimInjected = false; |
| 105 | + var voicePreparingHideTimer = null; |
| 106 | + var voiceReadyToastTimer = null; |
| 107 | + var voiceReadyHideTimer = null; |
105 | 108 |
|
106 | 109 | function injectVoiceAnimations() { |
107 | 110 | if (voiceAnimInjected) return; |
|
125 | 128 | function showVoicePreparing(message) { |
126 | 129 | injectVoiceAnimations(); |
127 | 130 | injectSpinAnimation(); |
| 131 | + hideReadyToSpeak(); |
| 132 | + clearVoicePreparingHideTimer(); |
128 | 133 |
|
129 | 134 | var toast = document.getElementById('voice-preparing-toast'); |
130 | 135 | if (!toast) { |
|
155 | 160 | toast.appendChild(span); |
156 | 161 | } |
157 | 162 |
|
| 163 | + function clearVoicePreparingHideTimer() { |
| 164 | + if (voicePreparingHideTimer) { |
| 165 | + clearTimeout(voicePreparingHideTimer); |
| 166 | + voicePreparingHideTimer = null; |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + function clearVoiceReadyTimers() { |
| 171 | + if (voiceReadyToastTimer) { |
| 172 | + clearTimeout(voiceReadyToastTimer); |
| 173 | + voiceReadyToastTimer = null; |
| 174 | + } |
| 175 | + if (voiceReadyHideTimer) { |
| 176 | + clearTimeout(voiceReadyHideTimer); |
| 177 | + voiceReadyHideTimer = null; |
| 178 | + } |
| 179 | + } |
| 180 | + |
158 | 181 | function hideVoicePreparing() { |
159 | 182 | var toast = document.getElementById('voice-preparing-toast'); |
160 | 183 | if (toast) { |
| 184 | + clearVoicePreparingHideTimer(); |
161 | 185 | toast.style.animation = 'voiceToastFadeIn 0.3s ease reverse'; |
162 | | - setTimeout(function() { toast.style.display = 'none'; }, 300); |
| 186 | + voicePreparingHideTimer = setTimeout(function() { |
| 187 | + voicePreparingHideTimer = null; |
| 188 | + toast.style.display = 'none'; |
| 189 | + }, 300); |
163 | 190 | } |
164 | 191 | } |
165 | 192 |
|
|
182 | 209 | } |
183 | 210 |
|
184 | 211 | // ===== Voice Ready Toast ===== |
| 212 | + function hideReadyToSpeak() { |
| 213 | + var toast = document.getElementById('voice-ready-toast'); |
| 214 | + if (toast) { |
| 215 | + clearVoiceReadyTimers(); |
| 216 | + toast.style.display = 'none'; |
| 217 | + } |
| 218 | + } |
| 219 | + |
185 | 220 | function showReadyToSpeak(message) { |
186 | 221 | injectVoiceAnimations(); |
| 222 | + hideVoicePreparing(); |
| 223 | + clearVoiceReadyTimers(); |
187 | 224 |
|
188 | 225 | var toast = document.getElementById('voice-ready-toast'); |
189 | 226 | if (!toast) { |
|
216 | 253 | toast.appendChild(img); |
217 | 254 | toast.appendChild(span); |
218 | 255 |
|
219 | | - setTimeout(function() { |
| 256 | + voiceReadyToastTimer = setTimeout(function() { |
| 257 | + voiceReadyToastTimer = null; |
220 | 258 | toast.style.animation = 'voiceToastFadeIn 0.3s ease reverse'; |
221 | | - setTimeout(function() { toast.style.display = 'none'; }, 300); |
| 259 | + voiceReadyHideTimer = setTimeout(function() { |
| 260 | + voiceReadyHideTimer = null; |
| 261 | + toast.style.display = 'none'; |
| 262 | + }, 300); |
222 | 263 | }, 2000); |
223 | 264 | } |
224 | 265 |
|
|
0 commit comments