Skip to content

Instantly share code, notes, and snippets.

@RascalTwo
Created November 7, 2022 16:08
Show Gist options
  • Save RascalTwo/0ba4f17de3fc8191ed5b0d031d51db3b to your computer and use it in GitHub Desktop.
Save RascalTwo/0ba4f17de3fc8191ed5b0d031d51db3b to your computer and use it in GitHub Desktop.
// 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