-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
86 lines (68 loc) · 2.22 KB
/
script.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
let input = document.querySelector("input");
let terminalBody = document.querySelector("#terminalBody");
let commandList = ['bio', 'github', 'name', 'projects', 'socials'];
functionCalls();
function functionCalls() {
checkWindowClick();
checkPressedEnter();
}
function checkWindowClick() {
terminalBody.addEventListener ('click', function(event){
input.focus();
});
}
function checkPressedEnter() {
input.addEventListener('keydown', function(e){
if (e.key === 'Enter') {
execute(input.value);
}
});
}
function execute(inputValue) {
let temp = input.value;
input.remove();
terminalBody.innerHTML += temp;
checkCommand(temp);
addInput();
}
function executeCommand(command){
terminalBody.innerHTML += '<br><br>'
for(let i=0; i<data[command].length; ++i){
terminalBody.innerHTML += `${data[command][i].name}: ` ;
if(data[command][i].value.includes('http')){
terminalBody.innerHTML += `<a href="${data[command][i].value}" target="_blank">${data[command][i].value}</a><br>` ;
} else{
terminalBody.innerHTML += `${data[command][i].value}<br>` ;
}
}
}
function checkCommand(inputCommand){
let command = inputCommand.split(" ")[0];
if(command){
if(command === 'github'){ commandGithub(command)}
else if(command === 'help'){ commandHelp();}
else if(commandList.includes(command)){ executeCommand(command);}
else{
terminalBody.innerHTML += '<br>' + inputCommand + ' is not a command. Please try another command! Maybe "help"<br>';
}
}
else {
terminalBody.innerHTML += '<br>';
}
}
function addInput() {
terminalBody.innerHTML += ' > <input type="text" autofocus />';
input = document.querySelector("input");
input.focus();
functionCalls();
}
function commandHelp() {
terminalBody.innerHTML += '<br><br>';
for(let i=0; i<commandList.length; i++) {
terminalBody.innerHTML += `${commandList[i]}<br>`
}
}
function commandGithub() {
terminalBody.innerHTML += `<hr><a href="https://github.com/${data.github[0].value}" target="_blank">${data.github[0].value}</a><br>`;
terminalBody.innerHTML += '<br>';
}