Last active
February 28, 2016 22:04
-
-
Save nicksahler/1d9f2ba0449c7a973cf1 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
// Sums duration of videos on youtube playlist pages | |
var total = 0; | |
var mult = [1, 60, 3600, 86400]; | |
Array.prototype.map.call(document.getElementsByClassName('timestamp'), | |
function(a) { | |
var time = a.textContent.split(':').reverse() | |
for ( var i in time ) total += Number(time[i]) * mult[i]; | |
} | |
); | |
var seconds = total % 60; | |
var minutes = ((total - seconds) / 60) % 60; | |
var hours = (total - (minutes * 60 + seconds )) / 3600; | |
console.log(`${hours}:${minutes}:${seconds}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment