Created
April 5, 2014 13:19
-
-
Save luke-john/9991825 to your computer and use it in GitHub Desktop.
ABC election count with aec data auto fill
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 ABC election count with aec data auto fill | |
// @namespace ? | |
// @description Auto fills the candidates. | |
// @include http://www2b.abc.net.au/Elections/View/SenateCalculator.aspx?e=34&ca=wa | |
// @version 1 | |
// @grant GM_xmlhttpRequest | |
// @require http://code.jquery.com/jquery-1.11.0.min.js | |
// ==/UserScript== | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "http://vtr.aec.gov.au/", | |
onload: function(response) { | |
var page = jQuery(response.responseText) | |
var total = 100 | |
results = page.find('table.results tbody tr.rownorm') | |
results.each(function(index, result) { | |
var cells = Array.prototype.slice.call( result.children); | |
var percentage = cells[2].textContent; | |
total = total - parseFloat(cells[2].textContent) | |
console.log(cells[0].textContent) | |
if (index == 32) { // Unendorsed/Ungrouped Amalgamated | |
var party = "Ungrouped Candidates"; | |
$("td:contains('" + party + "')").next().find('input').val(percentage); | |
} | |
else if (index == 33) { // Senate Ghost Groups Amalgamated | |
} | |
else { | |
var party = cells[0].textContent; | |
$("td:contains('" + party + "')").next().find('input').val(percentage); | |
} | |
}) | |
console.log(total) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment