de.bie.pieter / Strava pace to speed

// ==UserScript==
// @name         Strava pace to speed
// @namespace    http://pieterdb.be/
// @version      0.1
// @description  Add speed next to pace on strava
// @author       Pieter De Bie
// @license MIT
// @match        https://www.strava.com/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.2.1.min.js
// ==/UserScript==

(function() {
    'use strict';
    //Dashboard
    $('div.stat-subtext:contains("Average Pace")')
    .parent('div.stat')
    .each(function(){
        var paceAsArray = $(this).find('b.stat-text').text().trim().split(':');
        var minutes = parseInt(paceAsArray[0]);
        var seconds = parseInt(paceAsArray[1].replace(new RegExp('\D','g'),''));
        var secondsPerKilometer = (minutes * 60) + seconds;
        var kilometersPerHour = (1 / secondsPerKilometer) * 60 * 60;
        var formattedKmH = Math.round(kilometersPerHour * 100) / 100;
        $(this).parent().parent()
            .append('<li><div class="stat"><div class="stat-subtext">Average speed</div><b class="stat-text">'+formattedKmH+' km/h</b></div></li>');
    });
    //Detail
    $('abbr.unit[title="minutes per kilometer"]')
    .parent().parent()
    .each(function(){
        var paceAsArray = $(this).find('strong').text().trim().split(':');
        var minutes = parseInt(paceAsArray[0]);
        var seconds = parseInt(paceAsArray[1].replace(new RegExp('\D','g'),''));
        var secondsPerKilometer = (minutes * 60) + seconds;
        var kilometersPerHour = (1 / secondsPerKilometer) * 60 * 60;
        var formattedKmH = Math.round(kilometersPerHour * 100) / 100;
        $(this).parent()
            .append('<li><strong>'+formattedKmH+'<abbr class="unit" title="kilometer per hour"> km/h</strong></li>');
    });
})();