Created
September 18, 2021 23:37
-
-
Save justinsbarrett/7355ecc5d3e4b9d43e9722999aa224a8 to your computer and use it in GitHub Desktop.
A simple, configurable countdown timer for Airtable.
This file contains hidden or 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
// 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