Skip to content

Instantly share code, notes, and snippets.

@JocsaPB
Forked from fredericogg/playlist_time.js
Last active January 18, 2019 00:22
Show Gist options
  • Save JocsaPB/9fb9d4ee6e308a5da6b144d5ef219898 to your computer and use it in GitHub Desktop.
Save JocsaPB/9fb9d4ee6e308a5da6b144d5ef219898 to your computer and use it in GitHub Desktop.
Calcula o tempo total de uma playlist no Youtube, com condicional para vídeos apenas não assistidos. É só colar no console na página da playlist. Vi a ideia de um colega aqui do Git Hub e aprimorei.
(function () {
var onlyUnassistedVideos = true;
var timeSeconds = 0;
var timestampDivList = document.querySelectorAll("#pl-load-more-destination");
for (var i of timestampDivList[0].children) {
var percentageGreaterOrAlmostHundred = false;
if (onlyUnassistedVideos) {
for (var l of i.children) {
if(l.className == "pl-video-thumbnail"){
// resume-playback-progress-bar: class who only have percentage relative to quantity of watched video
for(var m of l.children[0].children) {
if(m.className == "resume-playback-progress-bar"){
var percent = m.style.cssText.replace(/\D/g, '');
console.log('procentagem assitida: ', percent);
if(percent >= 95) {
percentageGreaterOrAlmostHundred = true;
}
}
}
}
}
}
for (var j of i.children) {
// pl-video-time: class relative to time video
if(j.className == "pl-video-time"){
var timeParts = j.innerText.split(":");
if(onlyUnassistedVideos && !percentageGreaterOrAlmostHundred) {
timeSeconds += (timeParts[0] * 60) + parseInt(timeParts[1]);
} else if(!onlyUnassistedVideos) {
timeSeconds += (timeParts[0] * 60) + parseInt(timeParts[1]);
}
}
}
}
var hours = (timeSeconds / 60) / 60;
var minutes = (timeSeconds / 60) % 60;
var seconds = (timeSeconds % 60);
var 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