Last active
April 20, 2018 10:13
-
-
Save Tro95/2faa6837ecb17ccb611f610cf9bd0a35 to your computer and use it in GitHub Desktop.
Pardus Starbase Watcher
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 Pardus Starbase Watcher | |
// @namespace Tro | |
// @description Monitors the population of starbases in the PFC | |
// @include https://*.pardus.at/logout.php | |
// @version 1.1 | |
// @downloadURL https://gist.github.com/Tro95/2faa6837ecb17ccb611f610cf9bd0a35/raw/pardus_starbase_watcher.user.js | |
// @grant GM_xmlhttpRequest | |
// @connect artemis.pardus.at | |
// @connect orion.pardus.at | |
// @connect pegasus.pardus.at | |
// ==/UserScript== | |
// 1.1 - Support for Tampermonkey | |
// 1.0 - Initial script | |
var universe; | |
switch (document.location.hostname) { | |
case "orion.pardus.at": | |
universe = "orion"; | |
break; | |
case "artemis.pardus.at": | |
universe = "artemis"; | |
break; | |
case "pegasus.pardus.at": | |
universe = "pegasus"; | |
break; | |
} | |
var faction_to_load; | |
switch (universe) { | |
case "artemis": | |
faction_to_load = 0; // fed | |
break; | |
case "orion": | |
faction_to_load = -1; // emp | |
break; | |
case "pegasus": | |
faction_to_load = 2; // uni | |
} | |
if (faction_to_load != -1) { | |
document.getElementsByTagName('table')[0].childNodes[0].rows[0].cells[1].setAttribute('colspan', 3); | |
document.getElementsByTagName('table')[0].childNodes[0].rows[2].cells[1].setAttribute('colspan', 3); | |
document.getElementsByTagName('table')[0].childNodes[0].rows[2].cells[1].setAttribute('colspan', 3); | |
document.getElementsByTagName('table')[0].childNodes[0].rows[1].cells[1].style.width = "70%"; | |
var cell_1 = document.createElement('td'); | |
var cell_2 = document.createElement('td'); | |
document.getElementsByTagName('table')[0].childNodes[0].rows[1].appendChild(cell_1); | |
document.getElementsByTagName('table')[0].childNodes[0].rows[1].appendChild(document.getElementsByTagName('table')[0].childNodes[0].rows[1].cells[1]); | |
document.getElementsByTagName('table')[0].childNodes[0].rows[1].appendChild(cell_2); | |
document.getElementsByTagName('table')[0].childNodes[0].rows[1].appendChild(document.getElementsByTagName('table')[0].childNodes[0].rows[1].cells[1]); | |
var bad_sbs_box = document.createElement('table'); | |
var good_sbs_box = document.createElement('table'); | |
cell_1.appendChild(bad_sbs_box); | |
cell_2.appendChild(good_sbs_box); | |
bad_sbs_box.align = "center"; | |
bad_sbs_box.id = 'bad_starbases'; | |
bad_sbs_box.innerHTML = "<tbody><tr><th colspan=2>Bad Starbases</th></tr></tbody>"; | |
good_sbs_box.align = "center"; | |
good_sbs_box.id = 'bad_starbases'; | |
good_sbs_box.innerHTML = "<tbody><tr><th colspan=2>Good Starbases</th></tr></tbody>"; | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "https://" + universe + ".pardus.at/statistics.php?display=parduscluster", | |
overrideMimeType: "text/html", | |
onload: function(response) { | |
var stats_doc = new DOMParser().parseFromString(response.responseText, "text/html"); | |
var fed_SBs_table = stats_doc.getElementsByTagName('table')[9 + faction_to_load]; | |
for (var i = 0; i < fed_SBs_table.childNodes[0].rows.length - 1; i++) { | |
var val = parse_pop(fed_SBs_table.childNodes[0].rows[fed_SBs_table.childNodes[0].rows.length - 1 - i].cells[3].innerText); | |
if (val > 500 && val < 1000) { | |
add_bad_sb(fed_SBs_table.childNodes[0].rows[fed_SBs_table.childNodes[0].rows.length - 1 - i].cells[2].innerText, val); | |
} else if (val > 5000 && val < 6000) { | |
add_bad_sb(fed_SBs_table.childNodes[0].rows[fed_SBs_table.childNodes[0].rows.length - 1 - i].cells[2].innerText, val); | |
} else if (val > 15000 && val < 17500) { | |
add_bad_sb(fed_SBs_table.childNodes[0].rows[fed_SBs_table.childNodes[0].rows.length - 1 - i].cells[2].innerText, val); | |
} else if (val > 30000 && val < 33000) { | |
add_bad_sb(fed_SBs_table.childNodes[0].rows[fed_SBs_table.childNodes[0].rows.length - 1 - i].cells[2].innerText, val); | |
} else { | |
add_good_sb(fed_SBs_table.childNodes[0].rows[fed_SBs_table.childNodes[0].rows.length - 1 - i].cells[2].innerText, val); | |
} | |
} | |
} | |
}); | |
} | |
function add_bad_sb(name, population) { | |
var new_row = document.createElement('tr'); | |
new_row.innerHTML = "<td>" + name + "</td><td>" + format_pop(population) + "</td>"; | |
bad_sbs_box.childNodes[0].appendChild(new_row); | |
} | |
function add_good_sb(name, population) { | |
var new_row = document.createElement('tr'); | |
new_row.innerHTML = "<td>" + name + "</td><td>" + format_pop(population) + "</td>"; | |
good_sbs_box.childNodes[0].appendChild(new_row); | |
} | |
function parse_pop(population) { | |
return population.split(',').join(''); | |
} | |
function format_pop(population) { | |
var return_string = ""; | |
while (population.length > 3) { | |
return_string = "," + population.substr(population.length - 3) + return_string; | |
population = population.substr(0, population.length - 3); | |
} | |
return_string = population + return_string; | |
return return_string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment