Skip to content

Instantly share code, notes, and snippets.

@fhfaa
Created June 10, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhfaa/0422e14e5eccb89e72cea692b7bd2acf to your computer and use it in GitHub Desktop.
Save fhfaa/0422e14e5eccb89e72cea692b7bd2acf to your computer and use it in GitHub Desktop.
Global Corp. Challenge: fix mini leagues by accounting for missed entries
// content script for /event/mini-league/individual/
;(function () {
var maxEntries = 0,
sep = '',
$t = $('.table-responsive'),
sorted,
strideLength = [];
$t.find('th:eq(3)').text('FIXED');
sorted = $t.find('tr').slice(1).each(function (i, e) {
e.dataset.steps = +e.cells[4].innerText.replace(/\D/g, '');
e.dataset.avg = +e.cells[5].innerText.replace(/\D/g, '');
e.dataset.entries = Math.round(e.dataset.steps / e.dataset.avg);
strideLength.push(+e.cells[6].innerText.replace(/\D/g,'') / +e.dataset.steps);
maxEntries = Math.max(maxEntries, e.dataset.entries);
sep = e.cells[5].innerText.replace(/\d/g, '');
}).each(function (i, e) {
var name = e.cells[1].innerText,
up2date = +e.dataset.entries === maxEntries ? '1' : '';
e.dataset.fixed = up2date ? +e.dataset.steps : +e.dataset.avg * maxEntries;
e.cells[3].style.fontWeight = 'bold';
e.cells[3].style.color = up2date ? 'green' : 'red';
e.cells[3].innerText = e.dataset.fixed.toString().replace(/\B(?=(\d{3})+(?!\d))/g, sep);
if (!up2date) {
e.cells[6].style.color = 'red';
e.cells[6].style.fontWeight = 'bold';
e.cells[6].innerText = Math.round(e.dataset.fixed * (strideLength.reduce(function(a,b){return a+b}) / strideLength.length) ) + ' km';
}
}).get().sort(function (a, b) {
return +a.dataset.fixed < +b.dataset.fixed ? 1 : -1;
});
$(sorted).each(function (i, e) {
var old = +e.cells[0].innerText;
e.cells[0].innerText = '' + (i + 1) + (old !== i + 1 ? ' (' + old + ')' : '');
}).appendTo($t.find('tbody'));
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment