Skip to content

Instantly share code, notes, and snippets.

@joismar
Forked from cesarhilario/playlist_time.js
Last active November 30, 2017 01:58
Show Gist options
  • Save joismar/4fe344d149e5a2bd6d1fb18e6092da3f to your computer and use it in GitHub Desktop.
Save joismar/4fe344d149e5a2bd6d1fb18e6092da3f 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. Update para a nova interface do Youtube
(function() {
if (document.getElementsByClassName('ytd-playlist-video-list-renderer') != "undefined") {
var playlist = document.querySelector("ytd-playlist-video-list-renderer");
}
else {
var playlist = document.querySelector("ytd-playlist-panel-renderer");
}
var timeSeconds = 0,
timesContainer = playlist.querySelectorAll("ytd-thumbnail-overlay-time-status-renderer");
for(var i = 0; i < timesContainer.length; i++){
var timeStr = timesContainer[i].childNodes[0].innerHTML,
timeParts = timeStr.split(":"),
seconds = (timeParts[0] * 60) + parseInt(timeParts[1]);
timeSeconds += seconds;
}
var hours = (timeSeconds / 60) / 60,
minutes = (timeSeconds / 60) % 60,
seconds = (timeSeconds % 60),
result = parseInt(hours) + ":" + parseInt(minutes) + ":" + parseInt(seconds);
alert(result);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment