Created
June 20, 2012 11:55
-
-
Save 4ndrew/2959532 to your computer and use it in GitHub Desktop.
RunKeeperMaxSpeed user script, http://userscripts.org/scripts/show/136206
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
// ==UserScript== | |
// @name RunKeeperMaxSpeed | |
// @description Add max speed value in activity stats | |
// @id me.4ndrew.RunKeeperMaxSpeed | |
// @version 2012.06.15 | |
// @author nopox | |
// @homepageURL http://userscripts.org/scripts/show/136206 | |
// @supportURL http://userscripts.org/scripts/discuss/136206 | |
// @updateURL http://userscripts.org/scripts/source/136206.meta.js | |
// @include *runkeeper.com/user/*/activity/* | |
// ==/UserScript== | |
(function(){ | |
var execute = function() { | |
var counter = 0; | |
var timer = setInterval( function() { | |
if (chartData && typeof chartData.series !== "undefined") { | |
clearInterval(timer); | |
var maxSpeed = 0; | |
var speedData = chartData.series["SPEED"].data; | |
for (i = 0; i < speedData.length; i++) { | |
if (speedData[i][1] > maxSpeed) { | |
maxSpeed = speedData[i][1]; | |
} | |
} | |
$('#statsSpeed').after('<div class="activityStatsDivider"></div>' + | |
'<div id="statsMaxSpeed" class="activityStatsItem">'+ | |
' <div class="labelText">Max. Speed</div>'+ | |
' <div class="mainText">' + Math.floor(maxSpeed*100)/100 + '</div>'+ | |
' <div class="unitText">km/h</div>'+ | |
'</div>'); | |
$('.activityStatsItem').css('width', 'auto'); | |
// workaround: dynamic elements width (fill all space) inside div with static width | |
// I know it looks terrible but I don't know how to improve that | |
var totalWidth = 0; | |
var totalElements = 0; | |
$('.activityStatsItem:visible').each(function(i, v) { | |
totalWidth += $(this).outerWidth(); | |
totalElements++; | |
}); | |
var proportionalDelta = ($('#activityStats').width() - totalWidth) / totalElements - 2; | |
if (proportionalDelta > 1) { | |
$('.activityStatsItem:visible').width(function(i, elWidth) { | |
$(this).width(elWidth + proportionalDelta); | |
}); | |
} | |
} else if (counter++ > 10) { | |
clearInterval(timer); | |
} | |
}, 1000); | |
}; | |
var script = document.createElement("script"); | |
script.innerHTML = '(' + execute.toString() + ')();'; | |
document.head.appendChild(script); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment