Skip to content

Instantly share code, notes, and snippets.

@ncortines
Last active March 21, 2024 19:16
Show Gist options
  • Save ncortines/7f4fb6a8b9fe4603100b7a0cb30e6633 to your computer and use it in GitHub Desktop.
Save ncortines/7f4fb6a8b9fe4603100b7a0cb30e6633 to your computer and use it in GitHub Desktop.
Don't have much time to finish your knowbe4 training?
(() => {
const getSliderControlInput = () =>
document.querySelectorAll('input[data-ref=progressBar]')[0]
const getPlayButton = () =>
document.querySelectorAll('button[id=play-pause]')[0]
const isInputReady = $input =>
parseInt($input.value) < (parseInt($input.max) - parseInt($input.step))
const isPaused = $play =>
$play.attributes['aria-label'] && $play.attributes['aria-label'].value.includes('Play')
const playNext = () => {
const $input = getSliderControlInput()
if (!$input || !isInputReady($input)) {
setTimeout(playNext, 100)
return
}
const $play = getPlayButton()
if (!$play) {
setTimeout(playNext, 100)
return
}
if (isPaused($play)) {
$play.click()
}
setTimeout(moveForward, 100)
}
const moveForward = () => {
const $input = getSliderControlInput()
if (!$input || !isInputReady($input)) {
setTimeout(moveForward, 100)
return
}
$input.removeAttribute('disabled')
$input.value = $input.max
$input.dispatchEvent(new Event('change'))
setTimeout(playNext, 100)
}
moveForward()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment