index.html 2.5 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>Octave</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. <div id="log" contenteditable="true" style="white-space: pre;overflow-x: scroll;font-family: monospace;"></div>
  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. $("#log").height(window.innerHeight - $("#command").height() - 50)
  31. $(window).on('resize', function() {
  32. $("#log").height(window.innerHeight - $("#command").height() - 50)
  33. });
  34. refreshLog();
  35. setInterval(function() {
  36. refreshLog()
  37. }, 1000);
  38. function refreshLog() {
  39. if (!loading) {
  40. loading = true;
  41. $.get("log/from?start=" + currentLogID, function(data) {
  42. previd = currentLogID;
  43. $.each(data, function(index, value) {
  44. //to prevent something like octave:1> octave:2> x=3
  45. const regex = /(?:.(?!octave:[0-9]*> ))+$/g;
  46. const processedLog = value.Log.match(regex);
  47. $("#log").append(processedLog + "<br>");
  48. currentLogID = value.ID + 1;
  49. });
  50. $("#log").scrollTop($("#log")[0].scrollHeight);
  51. loading = false;
  52. });
  53. }
  54. }
  55. function sendCmd() {
  56. var cmdVal = $("#command").val();
  57. $.get("sendcommand?command=" + cmdVal);
  58. $("#log").append("octave> " + cmdVal + "\n");
  59. $("#command").val("");
  60. }
  61. $('#command').on("keypress", function(e) {
  62. if (e.keyCode == 13) {
  63. sendCmd();
  64. //$("#command").val("");
  65. return false; // prevent the button click from happening
  66. }
  67. });
  68. </script>
  69. </html>