-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
105 lines (98 loc) · 2.4 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var programCommand = "darcy";
var container = document.getElementsByClassName("container")[0];
var input;
var msg = document.createElement("p");
var msgText = document.createTextNode(" ");
msg.appendChild(msgText);
var createCl = function () {
var cl = document.createElement("P");
var bold = document.createElement("span");
var boldText = document.createTextNode("fitzdarcy@home:~$ ");
bold.appendChild(boldText);
bold.style.color = "blue";
var i = document.createElement("span");
i.tabIndex = "0";
i.contentEditable = "true";
i.style.outline = "none";
i.className = "input";
cl.appendChild(bold);
cl.appendChild(i);
container.appendChild(cl);
return i;
};
input = createCl();
//Check if program command is typed correctly
checkCommand = function (i) {
if (i.innerText.substring(0, 5).includes(programCommand)) {
return true;
}
return false;
};
//check which flag is typed
checkFlag = function (i) {
switch (i.innerText.substring(6)) {
case "--about":
return 1;
case "--quotes":
return 2;
case "--contact":
return 3;
case "--gui":
return 4;
case "--hilal":
return 5;
case "--help":
return 6;
case "--home":
return 7;
}
};
runFlag = function (e) {
window.open(e, "_self");
};
notFound = function (type, e) {
if (type === "flag") {
msgText.textContent =
"darcy: unrecognized option '" +
e +
"' Try 'darcy --help' for more information. ";
} else if (type === "command") {
msgText.textContent = e + ": command not found";
}
container.appendChild(msg);
input.innerText = "";
};
input.addEventListener("keypress", function (e) {
if (e.key === "Enter" || e.keyCode === 13) {
e.preventDefault();
if (!checkCommand(input)) {
//command not found
notFound("command", input.innerText);
} else if (checkCommand(input)) {
switch (checkFlag(input)) {
case 1:
runFlag("about.html");
break;
case 2:
runFlag("quotes.html");
break;
case 3:
runFlag("contact.html");
break;
case 4:
runFlag();
break;
case 5:
runFlag("developer.html");
break;
case 6:
runFlag("help.html");
break;
case 7:
runFlag("index.html");
default:
notFound("flag", input.innerText.substring(6));
}
}
}
});