Created
November 5, 2020 16:25
-
-
Save appelgran/d1cf2b19d1da8ba5e41ae751bd04cd86 to your computer and use it in GitHub Desktop.
Garmin Connect, Activity Comparison. Better splits. #bookmarklet
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
// run on for example https://connect.garmin.com/modern/comparison?activityId=111&activityId2=222&activityId3=333 | |
(function() { | |
function str2time(text) { | |
var t = text.trim().replace(',', '.').split(':').reverse(); | |
return (parseInt(t[2]) || 0) * 3600 + (parseInt(t[1]) || 0) * 60 + (parseFloat(t[0]) || 0); | |
} | |
function time2str(time) { | |
var s = (time % 60).toFixed(0); | |
return Math.floor(time / 60) +':'+ (s < 10 ? '0' + s : s) | |
} | |
var lapsTable = document.querySelector("table.laps.table"); | |
var columns = lapsTable.querySelectorAll("th"); | |
var races = []; | |
for (var x = 0; x < columns.length; x++) { | |
if (columns[x].getAttribute("title") === "t:m:s") { | |
races.push({index:x, elapsed:0}); | |
} | |
} | |
var rows = lapsTable.querySelectorAll("tbody tr"); | |
for (var x = 0; x < rows.length; x++) { | |
var columns = rows[x].querySelectorAll("td"); | |
var fastestSplit = 9999999; | |
var fastestElapsed = 9999999; | |
for (var y = 0; y < races.length; y++) { | |
races[y].split = str2time(columns[races[y].index].innerText); | |
races[y].elapsed += races[y].split; | |
fastestSplit = races[y].split < fastestSplit ? races[y].split : fastestSplit; | |
fastestElapsed = races[y].elapsed < fastestElapsed ? races[y].elapsed : fastestElapsed; | |
} | |
for (var y = 0; y < races.length; y++) { | |
columns[races[y].index].innerHTML = (races[y].split === fastestSplit ? '<span style="color:green">' : '<span>') | |
+ time2str(races[y].split) | |
+ '</span> ' | |
+ (races[y].elapsed === fastestElapsed ? '<span style="color:green">(' : '<span>(') | |
+ time2str(races[y].elapsed) | |
+ ')</span>'; | |
columns[races[y].index].setAttribute("title", "+" | |
+ time2str(races[y].split - fastestSplit) | |
+ " (+" | |
+ time2str(races[y].elapsed - fastestElapsed) | |
+ ")"); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment