Skip to content

Instantly share code, notes, and snippets.

@meetkool
Created September 6, 2024 05:49
Show Gist options
  • Save meetkool/e045b82e7c0285aa7764317a8b27859a to your computer and use it in GitHub Desktop.
Save meetkool/e045b82e7c0285aa7764317a8b27859a to your computer and use it in GitHub Desktop.
let totalTime = {
seconds:0,
minutes:0,
hours:0
}
document.querySelectorAll("ytd-playlist-video-renderer").forEach( (element) => {
try{
let timelist = element.querySelector("#overlays")
.querySelector("ytd-thumbnail-overlay-time-status-renderer")
.querySelector("span")
.firstChild.data.trim().split(':')
if(timelist.length == 2){
totalTime.minutes += parseInt(timelist[0])
totalTime.seconds += parseInt(timelist[1])
} else if (timelist.length == 3){
totalTime.hours += parseInt(timelist[0])
totalTime.minutes += parseInt(timelist[1])
totalTime.seconds += parseInt(timelist[2])
}
} catch(err){
console.log(err)
}
})
totalTime.minutes += parseInt(totalTime.seconds/60)
totalTime.seconds = totalTime.seconds % 60
totalTime.hours += parseInt(totalTime.minutes/60)
totalTime.minutes = totalTime.minutes % 60
console.log(totalTime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment