From b256fa8e5ed49a194b9cbb24de68fe9f340fa4c8 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Wed, 28 Oct 2020 22:35:09 +0100 Subject: [PATCH] #91 Optimized the JS code --- src/javascript/enhancements/watch2getherChat.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/javascript/enhancements/watch2getherChat.js b/src/javascript/enhancements/watch2getherChat.js index cd8df67..7e29f80 100644 --- a/src/javascript/enhancements/watch2getherChat.js +++ b/src/javascript/enhancements/watch2getherChat.js @@ -45,9 +45,6 @@ function addCharCounter(textarea) { function updateCharCounter(textarea, charCounterSpan) { const SHAKE_CLASS = 'awp-w2g-chatCounter-max'; - // reset class - charCounterSpan.classList.remove(SHAKE_CLASS); - let current = textarea.value.length; let max = textarea.maxLength; @@ -55,9 +52,11 @@ function updateCharCounter(textarea, charCounterSpan) { // animation if at max // this need to be delayed because removing and adding it too fast again will prevent the browsers to replay the animation - if (current >= max) { + if (current >= max && !charCounterSpan.classList.contains(SHAKE_CLASS)) { + charCounterSpan.classList.add(SHAKE_CLASS); + setTimeout(() => { - charCounterSpan.classList.add(SHAKE_CLASS); - }, 100); + charCounterSpan.classList.remove(SHAKE_CLASS); + }, 200); } } \ No newline at end of file