Skip to content

Instantly share code, notes, and snippets.

@MrShennawy
Created September 9, 2018 14:52
Show Gist options
  • Save MrShennawy/472d1be1e56c9c93278ebd73fa4ea438 to your computer and use it in GitHub Desktop.
Save MrShennawy/472d1be1e56c9c93278ebd73fa4ea438 to your computer and use it in GitHub Desktop.
Calculate YouTube Playlist total time
Number.prototype.padDigit = function () {
return (this < 10) ? '0' + this : this;
}
var time1 = "00:00";
var secs = 0;
var mins = 0;
var hrs = 0;
$('.ytd-thumbnail-overlay-time-status-renderer').each(function(){
time1 = time1.split(':');
var time2 = $(this).text().split(':');
secs = Number(time1[1]) + Number(time2[1]);
secMins = Math.floor(parseInt(secs / 60));
mins = Number(time1[0]) + Number(time2[0]) + secMins;
secs = secs % 60;
time1 = mins.padDigit() + ':' + secs.padDigit();
});
console.log(time1);
totalTime = time1.split(':');
var seconds = (Number(totalTime[0]) * 60) + Number(totalTime[1]);
hrs = Math.floor(parseInt((seconds / 60) / 60));
mins = Math.floor((seconds - (hrs * 3600)) / 60);
console.log('عدد الساعات ' + hrs);
console.log('عدد الدقائق ' + Math.floor(mins));
console.log('عدد الثوانى ' + Math.floor(seconds - ((hrs * 3600) + (mins * 60))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment