log.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $.each(data, function(index, value) {
  42. $("#log").append(escapeHtml(value.Log) + "\n");
  43. currentLogID = value.ID + 1;
  44. });
  45. $('#log').scrollTop($('#log')[0].scrollHeight);
  46. loading = false;
  47. });
  48. }
  49. }
  50. function sendCmd() {
  51. var cmdVal = $("#command").val();
  52. $.get("sendcommand?command=" + cmdVal);
  53. $("#log").append("Command: [" + cmdVal + "] sent\n");
  54. $("#command").val("");
  55. }
  56. $('#command').on("keypress", function(e) {
  57. if (e.keyCode == 13) {
  58. sendCmd();
  59. //$("#command").val("");
  60. return false; // prevent the button click from happening
  61. }
  62. });
  63. function escapeHtml(text) {
  64. return text
  65. .replace(/&/g, "&amp;")
  66. .replace(/</g, "&lt;")
  67. .replace(/>/g, "&gt;")
  68. .replace(/"/g, "&quot;")
  69. .replace(/'/g, "&#039;");
  70. }
  71. </script>
  72. </html>