mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Overhauled entire website with 0 change in looks
So I can finally work on implementing #35 but it feels like I did nothing :(
This commit is contained in:
1 parent
cc6ff973b5
commit
9edf4dc18e
12 files changed
+138
-268
No files matched your search
@@ -0,0 +1,37 @@
|
||||
// function to draw data we recieve from ajax requests
|
||||
function drawcontents(data) {
|
||||
var data = sortByKey(data, "count");
|
||||
result = "<table>";
|
||||
for(i = 0;i < data.length; i++) {
|
||||
var img = "";
|
||||
if(imagedata[data[i].name]){
|
||||
img = "https://wiki.factorio.com/images/" + imagedata[data[i].name] + ".png"
|
||||
} else {
|
||||
img = "https://wiki.factorio.com/images/" + capitalizeFirstLetter(data[i].name) + ".png";
|
||||
}
|
||||
result = result + "<tr><td><image src='" + img + "' onerror='hideThis(this);'></td><td>" + data[i].name + "</td><td>" + data[i].count + "</td></tr>";
|
||||
}
|
||||
result = result + "</table>"
|
||||
document.getElementById("contents").innerHTML = result;
|
||||
}
|
||||
|
||||
// get cluster inventory from master
|
||||
setInterval(function() {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
data = JSON.parse(xmlhttp.responseText);
|
||||
drawcontents(data);
|
||||
}
|
||||
}
|
||||
xmlhttp.open("GET", "inventory", true);
|
||||
xmlhttp.send();
|
||||
}, 500)
|
||||
|
||||
// function to sort arrays of objects after a keys value
|
||||
function sortByKey(array, key) {
|
||||
return array.sort(function(a, b) {
|
||||
var x = Number(a[key]); var y = Number(b[key]);
|
||||
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user