Created
February 13, 2018 18:36
-
-
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
This file contains hidden or 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
| // 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