Skip to content

Instantly share code, notes, and snippets.

@anjosc
Created April 3, 2015 04:00
Show Gist options
  • Save anjosc/532c634dd9043d17c4de to your computer and use it in GitHub Desktop.
Save anjosc/532c634dd9043d17c4de to your computer and use it in GitHub Desktop.
Adds the time in a youtube playlist
timestamps = document.querySelectorAll("td.pl-video-time > div > div.timestamp > span")
var total = 0
for (i=0; i < timestamps.length; i++){
var times = timestamps[i].innerHTML.split(":")
for(j = 0 ; j < times.length ; j++){
z = times.length - j - 1
total += parseInt(times[z]) * Math.pow(60,j)
}
}
var res = ""
timeDivisions = [60,60,24]
timeLetters = ['m','h','d']
for (i = 0; i < timeDivisions.length ; i++){
if(total >= timeDivisions[i]){
sub = total % timeDivisions[i];
res = timeLetters[i]+sub + res
total = (total-sub)/timeDivisions[i]
} else {
break
}
}
res = total + res+'s'
alert('total playing time = '+res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment