Forked from angel333/youtube-playlist-duration.js
Last active
January 29, 2019 05:14
-
-
Save mehranattari/26df56119c8b5cbf74c3c4b53dfa4507 to your computer and use it in GitHub Desktop.
Youtube playlist duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just copy this into console while on a playlist page (https://www.youtube.com/playlist?list=.....) | |
console.log(((document) => { | |
let seconds = Array.from(document.querySelectorAll('.ytd-thumbnail-overlay-time-status-renderer')) | |
.map((span) => { | |
let time = span.textContent.split(':'); | |
return (Number(time[0]) * 60) + Number(time[1]); | |
}) | |
.reduce((a,b) => { | |
return a + b; | |
}); | |
let total = { | |
hours: Math.floor(seconds/(3600)), | |
minutes: Math.floor((seconds%3600)/60), | |
seconds: (seconds%60) | |
}; | |
return 'Playlist duration: ' + total.hours + ' hours, ' + total.minutes + ' minutes, ' + total.seconds + ' seconds'; | |
})(document)); | |
// This above will print the result in console after this code, but if you want to get the duration in Alert box, just replace the console.log by alert |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment