Skip to content

Instantly share code, notes, and snippets.

@nvrossett
Forked from fredericogg/playlist_time.js
Last active December 24, 2020 21:02
Show Gist options
  • Save nvrossett/696e6d5910a8d6b7c6e639ab21baebdd to your computer and use it in GitHub Desktop.
Save nvrossett/696e6d5910a8d6b7c6e639ab21baebdd to your computer and use it in GitHub Desktop.
Calcula o tempo total de uma playlist no Youtube. É só colar no console na página da playlist. Fiz esse script porque não achei o tempo total da playlist 😅.
(function() {
var timeSeconds = 0;
var timestampDivList = document.querySelectorAll("#length");
for(var i = 0; i < timestampDivList.length; i++) {
var timestampDiv = timestampDivList[i];
var timeStr = timestampDiv.innerHTML;
if ( timeStr !== '' ){
var timeParts = timeStr.split(":");
var seconds = (parseInt(timeParts[0]) * 60) + parseInt(timeParts[1]);
timeSeconds += seconds;
}
}
var hours = parseInt((timeSeconds / 60) / 60);
var minutes = parseInt((timeSeconds / 60) % 60);
var seconds = parseInt((timeSeconds % 60));
function plural( label, time ){
return (time>1) ? label+'s' : label;
}
console.log(hours + " " + plural('Hora', hours), minutes + " " + plural('Minuto', minutes), "e", seconds + " " + plural('Segundo', seconds));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment