Last active
March 7, 2017 19:35
-
-
Save jlongtine/996cf8d974e54fb9669d to your computer and use it in GitHub Desktop.
Overcast Time Calculator
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
(function() { | |
var regex = new RegExp("([0-9]{2,}) min"); | |
function minutes_to_hhmm(t) { | |
if (isNaN(t)) return '-:--'; | |
var h = parseInt(t / 60); | |
var m = t % 60; | |
return (h ? h + ':' : '') + (h ? ('0' + m).slice(-2) : m); | |
} | |
var total_minutes = 0; | |
$('div.caption2.singleline').filter(function () { | |
return regex.test($(this).text()); | |
}).map(function(){ | |
var matches = regex.exec($(this).text()); | |
return parseInt(matches[1]); | |
}).each(function () { | |
total_minutes += this; | |
}); | |
var time = minutes_to_hhmm(total_minutes); | |
$("head > title").text($("head > title").text() + " (" + time + ") "); | |
$("h2.ocseparatorbar")[0].innerText = $("h2")[0].innerText + " - " + time; | |
})(); |
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
javascript:(function() { var regex = new RegExp("([0-9]{2,}) min"); function hmsToSecondsOnly(str) { var p = str.split(':'), s = 0, m = 1; while (p.length > 0) { s += m * parseInt(p.pop(), 10); m *= 60; } return s; } function minutes_to_hhmm(t) { if (isNaN(t)) return '-:--'; var h = parseInt(t / 60); var m = t % 60; return (h ? h + ':' : '') + (h ? ('0' + m).slice(-2) : m); } var total_minutes = 0; $('div.caption2.singleline').filter(function () { return regex.test($(this).text()); }).map(function(){ var matches = regex.exec($(this).text()); return parseInt(matches[1]); }).each(function () { total_minutes += this; }); var time = minutes_to_hhmm(total_minutes); $("head > title").text($("head > title").text() + " (" + time + ") "); $("h2.ocseparatorbar")[0].innerText = $("h2")[0].innerText + " - " + time;})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment