Skip to content

Instantly share code, notes, and snippets.

@nicksahler
Last active February 28, 2016 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicksahler/1d9f2ba0449c7a973cf1 to your computer and use it in GitHub Desktop.
Save nicksahler/1d9f2ba0449c7a973cf1 to your computer and use it in GitHub Desktop.
// 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