Last active
March 21, 2024 19:16
-
-
Save ncortines/7f4fb6a8b9fe4603100b7a0cb30e6633 to your computer and use it in GitHub Desktop.
Don't have much time to finish your knowbe4 training?
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
(() => { | |
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