log.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <!-- Standard Meta -->
  5. <meta charset="utf-8" />
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  8. <!-- Site Properties -->
  9. <title>Minecraft Server</title>
  10. <script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
  11. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
  12. <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
  13. </head>
  14. <body>
  15. <div class="ui form">
  16. <div class="field">
  17. <textarea id="log" rows="30"></textarea>
  18. </div>
  19. </div>
  20. <br>
  21. <div class="ui fluid action input">
  22. <input type="text" id="command" placeholder="Command here (e.g. give @a minecraft:wooden_axe)">
  23. <div class="ui button" onclick="sendCmd()">Send</div>
  24. </div>
  25. </body>
  26. <script>
  27. var currentLogID = 0;
  28. var loading = false;
  29. //to fix the fucking log textbox size.
  30. $(window).on('resize', function() {
  31. $("#log").height(window.innerHeight - $("#command").height() - 105)
  32. });
  33. refreshLog();
  34. setInterval(function() {
  35. refreshLog()
  36. }, 1000);
  37. function refreshLog() {
  38. if (!loading) {
  39. loading = true;
  40. $.get("log/from?start=" + currentLogID, function(data) {
  41. previd = currentLogID;
  42. /*
  43. prevHeight = $('#log')[0].scrollHeight;
  44. prevTop = $('#log').scrollTop;
  45. prevScrolled = prevHeight == prevTop ? false : true;
  46. */
  47. $.each(data, function(index, value) {
  48. $("#log").append(escapeHtml(value.Log) + "\n");
  49. currentLogID = value.ID + 1;
  50. });
  51. //check if people scrolled up
  52. //scroll only if updated
  53. /*
  54. if (previd != currentLogID && prevScrolled) {
  55. $('#log').scrollTop($('#log')[0].scrollHeight);
  56. }
  57. */
  58. //remove lines if more than 1000 lines here
  59. var data = $("#log").val().split("\n");
  60. if (data.length > 3001) {
  61. $("#log").val("---Log timmeed---\n");
  62. data = data.splice(data.length - 2000, data.length - 1);
  63. $("#log").val(data.join("\n"));
  64. }
  65. loading = false;
  66. });
  67. }
  68. }
  69. function sendCmd() {
  70. var cmdVal = $("#command").val();
  71. $.get("sendcommand?command=" + cmdVal);
  72. $("#log").append("Command: [" + cmdVal + "] sent\n");
  73. $("#command").val("");
  74. }
  75. $('#command').on("keypress", function(e) {
  76. if (e.keyCode == 13) {
  77. sendCmd();
  78. //$("#command").val("");
  79. return false; // prevent the button click from happening
  80. }
  81. });
  82. function escapeHtml(text) {
  83. return text
  84. .replace(/&/g, "&amp;")
  85. .replace(/</g, "&lt;")
  86. .replace(/>/g, "&gt;")
  87. .replace(/"/g, "&quot;")
  88. .replace(/'/g, "&#039;");
  89. }
  90. </script>
  91. </html>