Skip to content

Instantly share code, notes, and snippets.

@Raphango
Forked from fredericogg/playlist_time.js
Last active July 22, 2020 21:49
Show Gist options
  • Save Raphango/d77617184f0c0854bda610bc5789a9cf to your computer and use it in GitHub Desktop.
Save Raphango/d77617184f0c0854bda610bc5789a9cf 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(".timestamp");
var nomePlaylist = document.getElementsByClassName("pl-header-title")[0].textContent.replace(new RegExp("\n * ", 'g')," ")
for(var i = 0; i < timestampDivList.length; i++) {
var timestampDiv = timestampDivList[i];
var timeStr = timestampDiv.childNodes[0].innerHTML
var timeParts = timeStr.split(":");
var seconds = (timeParts[0] * 60) + parseInt(timeParts[1]);
timeSeconds += seconds;
}
var hours = (timeSeconds / 60) / 60;
var minutes = (timeSeconds / 60) % 60;
var seconds = (timeSeconds % 60);
var result = parseInt(hours) + ":" + parseInt(minutes) + ":" + parseInt(seconds);
alert("O tempo total da playlist:\n\n\"" + nomePlaylist + "\"\n\né:\n\n"+result);
})();
@Raphango
Copy link
Author

Formatação "bonitinha" adicionada

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment