Skip to content

Instantly share code, notes, and snippets.

@justinsbarrett
Created September 18, 2021 23:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinsbarrett/7355ecc5d3e4b9d43e9722999aa224a8 to your computer and use it in GitHub Desktop.
Save justinsbarrett/7355ecc5d3e4b9d43e9722999aa224a8 to your computer and use it in GitHub Desktop.
A simple, configurable countdown timer for Airtable.
// Setup
const timerOptions = ["30", "45", "60"]
// Functions
function showTime(seconds) {
const min = Math.floor(seconds / 60)
const sec = seconds % 60
output.clear()
output.markdown(`# ${min}:${("0" + sec).slice(-2)}`)
}
function countdown(seconds) {
showTime(seconds)
const startTime = Date.now()
let diff = 1
while (true) {
if (Date.now() > startTime + (diff * 1000)) {
showTime(seconds - diff)
diff++
if (diff === seconds + 1)
break
}
}
}
output.clear()
let time = await input.buttonsAsync("Set Timer Length", timerOptions)
countdown(Number(time))
output.markdown("# ✅ DONE!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment