-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.js
88 lines (85 loc) · 3.63 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
document.addEventListener("DOMContentLoaded", function () {
var output = document.getElementById("output");
output.innerHTML +=
"Welcome to my interactive web terminal.<br>For a list of available commands, type 'help'.<br>";
// Define an object to hold the available commands
var commands = {
whois: function () {
return "<p class='banner'>Hi 👋, I am FormalSnake 🐍!<br>I am a software and game developer, and I make some interesting projects, like this one!<br>I also make YouTube videos about Game development 🎮!</p>";
},
whoami: function () {
return "<p class='banner'>The paradox of “Who am I?” is: we never know, but, we constantly find out.</p>";
},
video: function () {
return "<p class='banner'>Opening YouTube...</p>";
},
social: function () {
return "<p class='banner'><a href='https://discord.gg/JAPhfQgu9J' target='_blank' aria-label='Discord'><i class='uil uil-discord'></i></a><br><a href='https://twitter.com/formalsnake' target=''_blank' aria-label='Twitter'><i class='uil uil-twitter'></i></a><br><a href='https://github.com/FormalSnake' target='_blank' aria-label='Github'><i class='uil uil-github'></i></a></p>";
},
projects: function () {
return "<p class='banner'>I am working on... <br> 🧟 A game called Zombie Siege, <br> 💬 A dialog system for Unity.</p>";
},
history: function () {
return commandHistory.join("<br>");
},
help: function () {
var keys = Object.keys(commands);
var result = "";
for (var i = 0; i < keys.length; i++) {
result += "<p class='command-output'>" + keys[i] + "</p>";
}
return result;
},
email: function () {
window.location.href = "mailto:[email protected]";
return "<p class='banner'>Opening mailto:[email protected]...</p>";
},
clear: function () {
var output = document.getElementById("output");
output.innerHTML = "";
return "";
},
banner: function () {
return "<p class='banner'>Welcome to my interactive web terminal.<br>For a list of available commands, type 'help'.</p>";
},
formalfetch: function () {
var os = window.navigator.platform; // You can use the window.navigator.platform to get the os
var browser = window.navigator.userAgent; // You can use the window.navigator.userAgent to get the browser
return "OS: " + os + "<br>" + "Browser: " + browser;
},
ls: function () {
return "'homework'/ hal9000.sh";
},
};
var commandHistory = [];
// Function to handle input and execute commands
function executeCommand() {
var input = document.getElementById("input").value.toLowerCase();
var output = document.getElementById("output");
commandHistory.push(input);
if (commands[input]) {
if (input === "video") {
window.open("https://www.youtube.com/channel/UCTwepsPzsXWSpYW5M1jlbgg");
}
if (input === "clear") {
output.innerHTML = "";
} else {
output.innerHTML +=
"<span id='user'>[email protected]:~$ " + input + "</span>";
output.innerHTML +=
"<p class='command-output'>" + commands[input]() + "</p>";
}
} else {
output.innerHTML +=
"<span id='user'>[email protected]:~$ " + input + "</span>";
output.innerHTML +=
"<p>Command not found. For a list of commands, type 'help'.</p>";
}
// Clear the input field
document.getElementById("input").value = "";
window.scrollTo(0, document.body.scrollHeight);
}
document.getElementById("input").onkeydown = function (e) {
if (e.key === "Enter") executeCommand();
};
});