Skip to content

Instantly share code, notes, and snippets.

@zoyo23
Last active May 25, 2024 15:38
Show Gist options
  • Save zoyo23/e4050ba6a2f672949f39bb6beca0694c to your computer and use it in GitHub Desktop.
Save zoyo23/e4050ba6a2f672949f39bb6beca0694c 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.
(function() {
var timeSeconds = 0;
var timestampList = document.querySelectorAll("div#content div#container ytd-thumbnail#thumbnail a#thumbnail div#overlays.style-scope.ytd-thumbnail.style-scope ytd-thumbnail-overlay-time-status-renderer span");
for(var i = 0; i < timestampList.length; i++) {
var timestampDiv = timestampList[i];
var timeStr = timestampDiv.innerHTML.replace("\n", "").replace("\n", "").trim();
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);
var mensagem = `Tempo total Playlist: ${result}`;
console.log(mensagem);
alert(mensagem);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment