Skip to content

Instantly share code, notes, and snippets.

@kamilogorek
Last active February 19, 2020 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamilogorek/a8196a0fdb0e4e4e9e9e10e79c53fde5 to your computer and use it in GitHub Desktop.
Save kamilogorek/a8196a0fdb0e4e4e9e9e10e79c53fde5 to your computer and use it in GitHub Desktop.
var elements = Array.from(document.querySelectorAll(".ytd-playlist-video-list-renderer span.ytd-thumbnail-overlay-time-status-renderer"))
var time = elements.map(v => {
const [s,m,h] = v.innerText.split(':').reverse().map(x => parseInt(x,10));
return s + (m || 0) * 60 + (h || 0) * 60 * 60;
})
var total = time.reduce((acc, v) => acc + v);
var h = Math.floor(total / (60 * 60));
var m = Math.floor((total - (h * 60 * 60)) / 60);
var s = total%60;
console.log(`${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment