-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.js
97 lines (87 loc) · 2.39 KB
/
terminal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { setVolume } from "./util/speak.js";
import { click } from "./sound/index.js";
import { on, off } from "./util/power.js";
import { toggleFullscreen } from "./util/screens.js";
import { type } from "./util/io.js";
// Check if query param is set and load that command
async function onload() {
const urlParams = new URLSearchParams(window.location.search);
const command = urlParams.get("command");
if (command) {
const { power } = await import("./util/power.js");
const { parse } = await import("./util/io.js");
power();
await type("> " + command, { initialWait: 3000, finalWait: 1500 });
await parse(command);
const { main } = await import("./util/screens.js");
main();
}
}
// Change the command passed to the parse function in order to directly load that command.
// Then visit /debug.html which calls this function in <body> onLoad().
async function debug() {
const { power } = await import("./util/power.js");
const { main } = await import("./util/screens.js");
const { parse } = await import("./util/io.js");
power();
main();
parse("fallout2");
}
function togglePower() {
let isOff = document.getElementById("crt").classList.contains("off");
if (isOff) {
on();
} else {
off();
}
}
function handleClick(event) {
if (event) {
event.preventDefault();
}
let input = document.querySelector("[contenteditable='true']");
if (input) {
input.focus();
}
}
function fly(event) {
event.target.classList.toggle("fly");
}
function theme(event) {
click();
let theme = event.target.dataset.theme;
[...document.getElementsByClassName("theme")].forEach((b) =>
b.classList.toggle("active", false)
);
event.target.classList.add("active");
document.body.classList = "theme-" + theme;
handleClick();
}
function fullscreen(event) {
toggleFullscreen();
event.target.blur();
}
function globalListener({ keyCode }) {
if (keyCode === 122) {
// F11
toggleFullscreen();
} else if (keyCode === 27) {
// ESC
toggleFullscreen(false);
}
}
document.addEventListener("keydown", globalListener);
document.getElementById("dial").addEventListener("input", (event) => {
let value = event.target.value;
setVolume(value);
});
// Define some stuff on the window so we can use it directly from the HTML
Object.assign(window, {
debug,
onload,
togglePower,
theme,
fly,
handleClick,
fullscreen
});