Created
April 5, 2014 15:10
-
-
Save luke-john/9993205 to your computer and use it in GitHub Desktop.
Better table formatting for AEC's Virtual Tally Room (with sort)
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 Better table formatting for AEC's Virtual Tally Room | |
// @namespace ? | |
// @description Makes the table easier to read and adds sort. | |
// @include http://vtr.aec.gov.au/Default.htm | |
// @version 1 | |
// @grant none | |
// @require http://code.jquery.com/jquery-1.11.0.min.js | |
// ==/UserScript== | |
// based on script by blha303 @ http://blha303.biz/c3Ri.user.js | |
function addGlobalStyle(css) { | |
var head, style; | |
head = document.getElementsByTagName('head')[0]; | |
if (!head) { return; } | |
style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = css; | |
head.appendChild(style); | |
} | |
addGlobalStyle("tr:nth-child(even) { background-color: #ddd; }"); | |
addGlobalStyle("tr:nth-child(odd) { background-color: #eee; }"); | |
var $td = jQuery('table.results tbody tr.rownorm'); | |
function addSort(col) { | |
var $th = jQuery('table.results tbody tr th:nth-child(' + col + ')'); | |
$th.wrapInner('<a href="#' + $th.text() + '" />') | |
$th.on('click', function() { | |
jQuery('table.results tbody tr.rownorm').remove(); | |
var order = [] | |
$td.each(function(index, item) { | |
order.push(item) | |
}) | |
order.sort(function(a, b) { | |
var a = parseFloat($(a).find('td:nth-child(' + col + ')').text().replace(/\,/g,"")); | |
var b = parseFloat($(b).find('td:nth-child(' + col + ')').text().replace(/\,/g,"")); | |
if (a < b) { | |
return 1; | |
} | |
if (a > b) { | |
return -1; | |
} | |
return 0; | |
}) | |
jQuery('table.results tbody tr:nth-child(' + 1 + ')').after(order); | |
}) | |
} | |
addSort(2) | |
addSort(3) | |
addSort(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment