jerous' ::1

I sometimes look at the intervals table of my workouts of my favourite run log http://runningahead.com. It's missing a speed column though, which I sometimes prefer over a pace. This little script adds it :)

I've only run it so far in

Download

Read the entire post to view the source.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// ==UserScript==
// @name        runningahead-speed-column
// @author jerous
// @include https://www.runningahead.com/logs/*
// @downloadURL https://jerous.org/att/2017/02/24/runningahead-speed-column/runningahead-speed-column.js
// @version     1.3.2
// @copyright  2017 jerous
// ==/UserScript==

// Version history:
// 1.3.2 add route distances
// 1.3.1 fix logs
// 1.3 trying to add some helper on the new run page
// 1.2 add speed to training log summary
// 1.1 add speed to summary
// 1.0 initial version

function paceToSpeed(pace) {
   // Assuming km here!
   pace=pace.replace(" km","");
   var min=parseInt(pace.split(':')[0]);
   var sec=parseInt(pace.split(':')[1]);
    if (min*60+sec==0) { 
       return "0 km/h";
    } else {
       return Math.round(3600/(min*60+sec)*100)/100+" km/h";
    }
}

function create(type, child) {
    var ret=document.createElement(type);
    if (child) { ret.appendChild(child); }
    return ret;
}
function text(txt) { return document.createTextNode(txt); }

function addSpeedColumn() {
    var table=document.getElementsByClassName("Intervals")[0];
    var tbody=table.childNodes[0];
    
    for(var i=0; i<tbody.childNodes.length; i++) {
        var row=tbody.childNodes[i];
        var el=create(
            i==0 ? 'th' : 'td',
            text(i==0 ? 'Speed' : paceToSpeed(row.childNodes[5].innerText)));
        row.insertBefore(el, row.lastChild);
    }
};

function addSpeedSummary() {
    var div=document.getElementsByClassName("SummaryBanner")[0];
    var div2=document.createElement('div');
       div2.appendChild(create('p', text(paceToSpeed(div.childNodes[9].innerText))));
       div2.appendChild(create('label', create('span', text('Speed'))));
    div.appendChild(div2);
};

function addSpeedSummary() {
    var tables=document.getElementsByClassName("Result");
    for(var i=0; i<tables.length; i++) {
        var tbody=tables[i].childNodes[0];
        for(var j=0; j<tbody.childNodes.length; j++) {
            var tr=tbody.childNodes[j];
            tr.appendChild(create('td', text(paceToSpeed(tr.childNodes[3].innerText))));
        }
    }
};


var all_distances={
    '7km boho (Rivierenhof)': [2.35, 1.47, 0.64, 2, 0.68],
	'8km (5mi) boho (Rivierenhof, Ruggeveldlaan)': [2.35, 2.04, 0.94, 2, 0.68],
};
function addIntervalHelper() {
    var div=document.getElementById('ctl00_ctl00_ctl00_SiteContent_PageContent_TrainingLogContent_Notesc');
    if (!div) { return; }
    
    var input=create("div");
        input.appendChild(text("Enter timings (space separated): "));
        var txt=create("input");
            txt.setAttribute("id", "timings");
            txt.setAttribute("value", "1 2 3 4 5");
            txt.setAttribute("style", "width:500px");
        var cmbDistances=create("select")
            cmbDistances.setAttribute("id", "distances");
            Object.keys(all_distances).map(function(key) { 
                var e=create("option", text(key+" --> "+all_distances[key]));
                e.setAttribute("id",key);
                cmbDistances.appendChild(e);
            });
        var cmdDo=create("input");
            cmdDo.setAttribute("value", "Do!");
            cmdDo.setAttribute("type", "button");
            cmdDo.setAttribute("onclick", " \
                var all_distances={'7km boho (Rivierenhof)':[2.35, 1.47, 0.64, 2, 0.68]}; \
                \
                let insertDistances=function() { \
                    var cmdSave=document.getElementById('SaveInterval'); \
                    var cmbDistances=document.getElementById('distances'); \
                    var timings=document.getElementById('timings').value.split(' '); \
                    var cur_dsts=all_distances[cmbDistances.options[cmbDistances.selectedIndex].getAttribute('id')]; \
                    for(var i=0; i<timings.length; i++) { \
                        var dst=document.getElementById('ctl00_ctl00_ctl00_SiteContent_PageContent_TrainingLogContent_IntDistance'); \
                        var dur=document.getElementById('ctl00_ctl00_ctl00_SiteContent_PageContent_TrainingLogContent_IntDuration'); \
                        dst.value=cur_dsts[i]; \
                        dur.value=timings[i]; \
                        cmdSave.click(); \
                    } \
                }; \
            insertDistances(); return false; ");
    
        input.appendChild(txt);
        input.appendChild(cmbDistances);
        input.appendChild(cmdDo);
    
    div.parentNode.insertBefore(input, div);
}

window.addEventListener('load', function() {
   addIntervalHelper();
   // Least hassly way to be sure our data has loaded in the table ...
   setTimeout(addSpeedColumn, 500);
   setTimeout(addSpeedSummary, 500);
   setTimeout(addSpeedResults, 500);
}, false);

Add a comment

Name (required)
Email (optional, not shown)
Comment (max 1000 characters)

[printer friendly] [static version] [Post listing] [Page listing] [Tags: music tab jazz travel wdb europe code live programming youtube record ]