2023-10-02 11:37:22 +00:00
|
|
|
import * as Terminal from "./terminal.js";
|
|
|
|
import * as Visual from "./visual.js";
|
2023-10-01 16:17:05 +00:00
|
|
|
|
2023-09-30 01:34:43 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
2024-01-19 03:12:54 +00:00
|
|
|
document.getElementById("version").textContent = Terminal.VERSION;
|
|
|
|
|
2023-10-02 11:37:22 +00:00
|
|
|
Visual.bind();
|
2023-10-02 11:40:48 +00:00
|
|
|
Terminal.start();
|
2023-10-02 12:56:26 +00:00
|
|
|
|
2023-10-03 00:21:34 +00:00
|
|
|
const dialog_backdrop = document.getElementById("dialog-backdrop");
|
2024-01-16 01:03:12 +00:00
|
|
|
|
2023-10-03 00:21:34 +00:00
|
|
|
const connect_button = document.getElementById("connect");
|
|
|
|
const connect_dialog = document.getElementById("connect-dialog");
|
|
|
|
const connect_url = document.getElementById("connect-url");
|
|
|
|
const connect_submit = document.getElementById("connect-submit");
|
2024-01-16 01:03:12 +00:00
|
|
|
const connect_close = connect_dialog.getElementsByClassName("dialog-close").item(0);
|
2023-10-03 00:21:34 +00:00
|
|
|
|
|
|
|
connect_url.placeholder = window.location.host;
|
|
|
|
|
|
|
|
connect_button.addEventListener("click", () => {
|
|
|
|
connect_url.value = "";
|
|
|
|
connect_dialog.classList.add("show");
|
|
|
|
dialog_backdrop.classList.add("show");
|
|
|
|
connect_url.focus();
|
|
|
|
Terminal.set_enable_input(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect_submit.addEventListener("click", () => {
|
|
|
|
connect_close.click();
|
2024-01-16 01:03:12 +00:00
|
|
|
const new_server = connect_url.value || window.location.host;
|
2023-10-02 12:56:26 +00:00
|
|
|
Terminal.connect(new_server);
|
|
|
|
});
|
2023-10-03 00:21:34 +00:00
|
|
|
|
|
|
|
connect_dialog.addEventListener("keydown", event => {
|
|
|
|
switch (event.key) {
|
|
|
|
case "Enter":
|
|
|
|
connect_submit.click();
|
|
|
|
break;
|
|
|
|
case "Escape":
|
|
|
|
connect_close.click();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
2024-01-16 01:03:12 +00:00
|
|
|
[...document.getElementsByClassName("dialog-close")].forEach(dialog_close => {
|
|
|
|
dialog_close.addEventListener("click", () => {
|
|
|
|
[...document.getElementsByClassName("dialog")].forEach(element => {
|
|
|
|
element.classList.remove("show");
|
|
|
|
});
|
|
|
|
dialog_backdrop.classList.remove("show");
|
|
|
|
Terminal.set_enable_input(true);
|
|
|
|
});
|
2023-10-03 00:21:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
dialog_backdrop.addEventListener("click", () => {
|
|
|
|
connect_close.click();
|
|
|
|
});
|
2023-09-30 01:34:43 +00:00
|
|
|
});
|
|
|
|
|
2024-01-19 03:12:54 +00:00
|
|
|
/**
|
|
|
|
* requests that the user confirm they wish to connect to an insecure (ws://) server.
|
|
|
|
* @returns a promise returning `true` or `false` based on user input.
|
|
|
|
*/
|
|
|
|
export async function user_confirm_insecure() {
|
|
|
|
const warn_dialog = document.getElementById("warn-dialog");
|
|
|
|
const warn_close = warn_dialog.getElementsByClassName("dialog-close").item(0);
|
|
|
|
const dialog_backdrop = document.getElementById("dialog-backdrop");
|
|
|
|
const warn_proceed = document.getElementById("warn-proceed");
|
|
|
|
const warn_cancel = document.getElementById("warn-cancel");
|
|
|
|
|
|
|
|
warn_dialog.classList.add("show");
|
|
|
|
dialog_backdrop.classList.add("show");
|
|
|
|
|
|
|
|
const user_input = await new Promise((Resolve, Reject) => {
|
|
|
|
warn_close.addEventListener('click', () => {
|
|
|
|
Resolve(false);
|
|
|
|
});
|
|
|
|
warn_cancel.addEventListener('click', () => {
|
|
|
|
warn_close.click();
|
|
|
|
});
|
|
|
|
dialog_backdrop.addEventListener("click", () => {
|
|
|
|
warn_close.click();
|
|
|
|
});
|
|
|
|
warn_proceed.addEventListener('click', () => {
|
|
|
|
Resolve(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
warn_dialog.classList.remove("show");
|
|
|
|
dialog_backdrop.classList.remove("show");
|
|
|
|
|
|
|
|
return user_input;
|
|
|
|
}
|