Created
November 7, 2022 16:08
-
-
Save RascalTwo/0ba4f17de3fc8191ed5b0d031d51db3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// must have textbox open & editing for this to work | |
textboxInterval = ((end) => { | |
function tick(){ | |
const now = Date.now(); | |
const diff = Math.floor((end.getTime() - now) / 1000); | |
const mins = diff < 0 ? 0 : Math.floor(diff / 60); | |
const seconds = diff < 0 ? 0 : diff % 60; | |
const textbox = $('.textbox-editor')[0]; | |
if (!textbox) return; | |
textbox.value = `${mins.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} minutes`; | |
textbox.dispatchEvent(new Event('input', {bubbles:true})); | |
} | |
return setInterval(tick, 1000); | |
// set end date below | |
})(new Date('Sun Nov 6 2022 15:00:00')) | |
// to stop, clearInterval(textboxInterval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment