log.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. function refreshLog() {
  30. if (!loading) {
  31. loading = true;
  32. $.get("log/from?start=" + currentLogID, function(data) {
  33. $.each(data, function(index, value) {
  34. $("#log").append(escapeHtml(value.Log) + "\n");
  35. currentLogID = value.ID + 1;
  36. });
  37. $('#log').scrollTop($('#log')[0].scrollHeight);
  38. loading = false;
  39. });
  40. }
  41. }
  42. setInterval(function() {
  43. refreshLog()
  44. }, 1000);
  45. function sendCmd() {
  46. var cmdVal = $("#command").val();
  47. $.get("sendcommand?command=" + cmdVal, function(data) {
  48. $("#log").append("Command: [" + cmdVal + "] sent\n");
  49. //increase the refresh speed immd after sending command
  50. setTimeout(refreshLog, 200);
  51. });
  52. }
  53. $('#command').on("keypress", function(e) {
  54. if (e.keyCode == 13) {
  55. sendCmd();
  56. $("#command").val("");
  57. return false; // prevent the button click from happening
  58. }
  59. });
  60. function escapeHtml(text) {
  61. return text
  62. .replace(/&/g, "&amp;")
  63. .replace(/</g, "&lt;")
  64. .replace(/>/g, "&gt;")
  65. .replace(/"/g, "&quot;")
  66. .replace(/'/g, "&#039;");
  67. }
  68. </script>
  69. </html>