log.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. function refreshLog() {
  29. $.get("log/from?start=" + currentLogID, function(data) {
  30. $.each(data, function(index, value) {
  31. $("#log").append(value.Log + "\n");
  32. currentLogID = value.ID + 1;
  33. });
  34. $('#log').scrollTop($('#log')[0].scrollHeight);
  35. });
  36. }
  37. setInterval(function() {
  38. refreshLog()
  39. }, 3000);
  40. function sendCmd() {
  41. var cmdVal = $("#command").val();
  42. $.get("sendcommand?command=" + cmdVal, function(data) {
  43. $("#log").append("Command: [" + cmdVal + "] sent\n");
  44. $("#command").val("");
  45. //increase the refresh speed immd after sending command
  46. setTimeout(refreshLog, 1000);
  47. });
  48. }
  49. $('#command').on("keypress", function(e) {
  50. if (e.keyCode == 13) {
  51. sendCmd();
  52. return false; // prevent the button click from happening
  53. }
  54. });
  55. </script>
  56. </html>