Created
August 20, 2022 16:05
-
-
Save benlieb/9c94bda07d960a353b18b5a6789a9c5c to your computer and use it in GitHub Desktop.
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
function toSecs(val) { | |
val = val.split(':').reverse() | |
const sec = parseInt(val[0]) | |
const min = parseInt(val[1] || 0) | |
const hr = parseInt(val[2] || 0) | |
return ( (hr * 60 * 60) + (min * 60) + sec ) | |
} | |
function youtubeLink(yt_id, start_stamp, end_stamp) { | |
const start_secs = toSecs(start_stamp) | |
const end_secs = end_stamp ? toSecs(end_stamp) : start_secs + 5 | |
if(yt_id && start_secs) { | |
return (`https://www.youtube.com/embed/${yt_id}?start=${start_secs}&end=${end_secs}`) | |
} else { | |
return ('.') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment