Skip to content

Instantly share code, notes, and snippets.

@orafaribeiro
Forked from cesarhilario/playlist_time.js
Last active December 12, 2020 21:26
Show Gist options
  • Save orafaribeiro/dafe380fe87334089cf4cf14a752393c to your computer and use it in GitHub Desktop.
Save orafaribeiro/dafe380fe87334089cf4cf14a752393c 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() {
const playlist = document.querySelector("ytd-playlist-video-list-renderer");
const timesContainer = playlist.querySelectorAll("ytd-thumbnail-overlay-time-status-renderer");
let timeSeconds = 0;
for(let i = 0; i < timesContainer.length; i++){
const timeStr = timesContainer[i].querySelector('span.style-scope').innerHTML;
const timeParts = timeStr.split(":");
const seconds = (timeParts[0] * 60) + parseInt(timeParts[1]);
timeSeconds += seconds;
}
const hours = (timeSeconds / 60) / 60;
const minutes = (timeSeconds / 60) % 60;
const seconds = (timeSeconds % 60);
const result = parseInt(hours) + ":" + parseInt(minutes) + ":" + parseInt(seconds);
alert(result);
})();
@cesarhilario
Copy link

Vlw Rafa, vou atualizar o original....

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