12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <!DOCTYPE html>
- <html>
- <head>
- <!-- Standard Meta -->
- <meta charset="utf-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
- <!-- Site Properties -->
- <title>Octave</title>
- <script src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
- <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
- </head>
- <body>
- <div class="ui form">
- <div class="field">
- <div id="log" contenteditable="true" style="white-space: pre;overflow-x: scroll;font-family: monospace;"></div>
- </div>
- </div>
- <br>
- <div class="ui fluid action input">
- <input type="text" id="command" placeholder="Command here (e.g. give @a minecraft:wooden_axe)">
- <div class="ui button" onclick="sendCmd()">Send</div>
- </div>
- </body>
- <script>
- var currentLogID = 0;
- var loading = false;
- //to fix the fucking log textbox size.
- $("#log").height(window.innerHeight - $("#command").height() - 50)
- $(window).on('resize', function() {
- $("#log").height(window.innerHeight - $("#command").height() - 50)
- });
- refreshLog();
- setInterval(function() {
- refreshLog()
- }, 1000);
- function refreshLog() {
- if (!loading) {
- loading = true;
- $.get("log/from?start=" + currentLogID, function(data) {
- previd = currentLogID;
- $.each(data, function(index, value) {
- //to prevent something like octave:1> octave:2> x=3
- const regex = /(?:.(?!octave:[0-9]*> ))+$/g;
- const processedLog = value.Log.match(regex);
- $("#log").append(processedLog + "<br>");
- currentLogID = value.ID + 1;
- });
- $("#log").scrollTop($("#log")[0].scrollHeight);
- loading = false;
- });
- }
- }
- function sendCmd() {
- var cmdVal = $("#command").val();
- $.get("sendcommand?command=" + cmdVal);
- $("#log").append("octave> " + cmdVal + "\n");
- $("#command").val("");
- }
- $('#command').on("keypress", function(e) {
- if (e.keyCode == 13) {
- sendCmd();
- //$("#command").val("");
- return false; // prevent the button click from happening
- }
- });
- </script>
- </html>
|