test.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>DCSW Server Map: Table Edition</title>
  6. </head>
  7. <body>
  8. <table border="1" cellpadding="5" cellspacing="0" id="myList" id="myTable"></table>
  9. <p id="notes">Notes go here.</p>
  10. <script>
  11. // Global Vars, cuzz we <3 anti-patterns
  12. const serverURL = "http://homeplate.close-air.support:8888/";
  13. var latest;
  14. var oldest;
  15. var Units;
  16. // Update, you know...the things.
  17. window.setInterval(updateContents, 5000);
  18. function updateContents() {
  19. var notifications = "";
  20. fetchContent();
  21. units_added = unitsAdded();
  22. if (units_added.length != 0) {
  23. notifications = notifications + "Units Added: "+units_added+"<br/>";
  24. };
  25. units_rmved = unitsRemoved();
  26. if (units_rmved != 0) {
  27. notifications = notifications + "Units Removed: "+units_rmved+"<br/>";
  28. };
  29. document.getElementById("notes").innerHTML = notifications;
  30. renderContents();
  31. }
  32. function fetchContent() {
  33. oldest = latest;
  34. Units = fetchData(serverURL);
  35. latest = convertJSON(Units);
  36. }
  37. function convertJSON(jsonFile) {
  38. var myArray = [];
  39. for (index in jsonFile) { myArray.push(jsonFile[index].UnitName); };
  40. return myArray;
  41. }
  42. function unitsRemoved() {
  43. var myArray = [];
  44. myArray = oldest.filter(x => !latest.includes(x));
  45. return myArray;
  46. }
  47. function unitsAdded() {
  48. var myArray = [];
  49. myArray = latest.filter(x => !oldest.includes(x));
  50. return myArray;
  51. }
  52. function renderContents() {
  53. var myTable
  54. for (unitIndex in Units)
  55. {
  56. myTable = myTable + "<tr><td>"+Units[unitIndex].UnitName+"</td><td>"+Units[unitIndex].Name+"</td><td>"+Units[unitIndex].SpeedInKnots+"</td>";
  57. };
  58. document.getElementById("myList").innerHTML = myTable;
  59. }
  60. function fetchData(url)
  61. {
  62. var xhr = new XMLHttpRequest();
  63. var retval;
  64. xhr.open("GET", url, false);
  65. xhr.send();
  66. return JSON.parse(xhr.responseText);
  67. }
  68. </script>
  69. </body>
  70. </html>