- Removed AngularJS 1.4.8 completely — no more framework dependency - Extracted core RCON logic into pure vanilla JS (js/rcon.js) - Added lightweight hash-based SPA router (js/router.js) - Rewrote all 6 pages as vanilla JS modules in js/pages/ - Migrated Bootstrap 3 → Bootstrap 5 (cards instead of panels, bootstrap-icons instead of glyphicons) - Removed jQuery dependency (Bootstrap 5 is vanilla JS) - Purged all Angular templates from html/ - Removed npm artifacts (package.json, node_modules) - Added nginx.example.conf for static hosting - Updated rcon.css dark theme for BS5 variables - Static file only — no Node.js backend required Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
81 lines
2.6 KiB
JavaScript
81 lines
2.6 KiB
JavaScript
/**
|
|
* Console page — live console output with command input and history.
|
|
*/
|
|
function ConsolePage(params, container) {
|
|
var html =
|
|
'<div id="ConsoleController">' +
|
|
'<div id="console-output" style="height:600px" class="Output scrollable"></div>' +
|
|
'<form id="console-form">' +
|
|
'<input type="text" id="console-input" class="form-control" autocomplete="off">' +
|
|
'</form>' +
|
|
'</div>';
|
|
container.innerHTML = html;
|
|
|
|
var outputEl = document.getElementById('console-output');
|
|
var inputEl = document.getElementById('console-input');
|
|
var commandHistory = [];
|
|
var historyIndex = 0;
|
|
|
|
function addOutput(msg) {
|
|
var div = document.createElement('div');
|
|
div.className = msg.Type;
|
|
div.textContent = stripHtml(msg.Message);
|
|
outputEl.appendChild(div);
|
|
if (isScrolledToBottom(outputEl)) outputEl.scrollTop = outputEl.scrollHeight;
|
|
}
|
|
|
|
function onSubmit() {
|
|
var cmd = inputEl.value.trim();
|
|
if (!cmd) return;
|
|
addOutput({ Message: cmd, Type: 'Command' });
|
|
commandHistory.push(cmd);
|
|
historyIndex = commandHistory.length;
|
|
Rcon.command(cmd, 1);
|
|
inputEl.value = '';
|
|
}
|
|
|
|
function onKeyDown(e) {
|
|
if (commandHistory.length === 0) return;
|
|
if (e.keyCode === 38) { // Up
|
|
historyIndex--;
|
|
if (historyIndex < 0) historyIndex = commandHistory.length - 1;
|
|
inputEl.value = commandHistory[historyIndex] || '';
|
|
e.preventDefault();
|
|
} else if (e.keyCode === 40) { // Down
|
|
historyIndex++;
|
|
if (historyIndex >= commandHistory.length) historyIndex = 0;
|
|
inputEl.value = commandHistory[historyIndex] || '';
|
|
e.preventDefault();
|
|
} else {
|
|
historyIndex = commandHistory.length;
|
|
}
|
|
}
|
|
|
|
function onMessage(msg) {
|
|
if (msg.Message && msg.Message.indexOf('[rcon] ') === 0) return;
|
|
switch (msg.Type) {
|
|
case 'Generic': case 'Log': case 'Error': case 'Warning':
|
|
addOutput(msg); break;
|
|
}
|
|
}
|
|
|
|
function fetchHistory() {
|
|
Rcon.request('console.tail 128', function (response) {
|
|
var messages = JSON.parse(response.Message);
|
|
for (var i = 0; i < messages.length; i++) onMessage(messages[i]);
|
|
outputEl.scrollTop = outputEl.scrollHeight;
|
|
});
|
|
}
|
|
|
|
document.getElementById('console-form').addEventListener('submit', function (e) {
|
|
e.preventDefault(); onSubmit();
|
|
});
|
|
inputEl.addEventListener('keydown', onKeyDown);
|
|
Rcon.on('message', onMessage);
|
|
|
|
if (Rcon.isConnected()) fetchHistory();
|
|
else { var _c = function () { fetchHistory(); Rcon.off('connected', _c); }; Rcon.on('connected', _c); }
|
|
|
|
return function cleanup() { Rcon.off('message', onMessage); };
|
|
}
|