Skip to content

Instantly share code, notes, and snippets.

@eoghanobrien
Created February 13, 2018 18:36
Show Gist options
  • Select an option

  • Save eoghanobrien/afbfc3c3e35a2a607c5e2594ceb5c09f to your computer and use it in GitHub Desktop.

Select an option

Save eoghanobrien/afbfc3c3e35a2a607c5e2594ceb5c09f to your computer and use it in GitHub Desktop.
Bookmarklet source code to calculate the length of a series on Laracasts.com
// Bookmarklet created using http://chriszarate.github.io/bookmarkleter/
var time = $('.running-time').map(function () {
return $(this).text().replace(/([^0-9:]+)/gi, '').split(':').reverse().reduce(function (prev, curr, i) {
return prev + curr * Math.pow(60, i)
}, 0);
}).get().reduce(function (a, b) {
return a + b
}, 0);
function format(time) {
var hora = ~~(time / 3600);
var mins = ~~((time % 3600) / 60);
var secs = time % 60;
var ret = "";
if (hora > 0) {
ret += "" + hora + ":" + (mins < 10 ? "0" : "");
}
ret += "" + mins + ":" + (secs < 10 ? "0" : "");
ret += "" + secs;
return ret;
}
alert(format(time));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment