-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
227 lines (190 loc) · 8.11 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
document.addEventListener('DOMContentLoaded', function() {
document.getElementsByTagName('form')[0].onsubmit = function(evt) {
evt.preventDefault(); // Preventing the form from submitting
checkWord(); // Do your magic and check the entered word/sentence
window.scrollTo(0,150);
}
// Get the focus to the text input to enter a word right away.
document.getElementById('terminalTextInput').focus();
// Getting the text from the input
var textInputValue = document.getElementById('terminalTextInput').value.trim();
//Getting the text from the results div
var textResultsValue = document.getElementById('terminalReslutsCont').innerHTML;
// Clear text input
var clearInput = function(){
document.getElementById('terminalTextInput').value = "";
}
// Scrtoll to the bottom of the results div
var scrollToBottomOfResults = function(){
var terminalResultsDiv = document.getElementById('terminalReslutsCont');
terminalResultsDiv.scrollTop = terminalResultsDiv.scrollHeight;
}
// Scroll to the bottom of the results
scrollToBottomOfResults();
// Add text to the results div
var addTextToResults = function(textToAdd){
document.getElementById('terminalReslutsCont').innerHTML += "<p>" + textToAdd + "</p>";
scrollToBottomOfResults();
}
// Getting the list of keywords for help & posting it to the screen
var postHelpList = function(){
// Array of all the help keywords
var helpKeyWords = [
"- Open + website URL to open it in the browser (ex. open discord.com)",
"- Google + keyword to search directly in Google (ex. google web development)",
"- YouTube + keyword to search directly in YouTube (ex. ProgrammingWithNiko)",
"- Wiki + keyword to search directly in Wikipedia (ex. wiki numbers)",
"- 'Time' will display the current time.",
"- 'Date' will display the current date.",
"- 'tech' will make you expert by watching videos",
"* There are more keywords that you have to discover by yourself.",
"* Developed by Delta Labs."
].join('<br>');
addTextToResults(helpKeyWords);
}
// Getting the time and date and post it depending on what you request for
var getTimeAndDate = function(postTimeDay){
var timeAndDate = new Date();
var timeHours = timeAndDate.getHours();
var timeMinutes = timeAndDate.getMinutes();
var dateDay = timeAndDate.getDate();
console.log(dateDay);
var dateMonth = timeAndDate.getMonth() + 1; // Because JS starts counting months from 0
var dateYear = timeAndDate.getFullYear(); // Otherwise we'll get the count like 98,99,100,101...etc.
if (timeHours < 10){ // if 1 number display 0 before it.
timeHours = "0" + timeHours;
}
if (timeMinutes < 10){ // if 1 number display 0 before it.
timeMinutes = "0" + timeMinutes;
}
var currentTime = timeHours + ":" + timeMinutes;
var currentDate = dateDay + "/" + dateMonth + "/" + dateYear;
if (postTimeDay == "time"){
addTextToResults(currentTime);
}
if (postTimeDay == "date"){
addTextToResults(currentDate);
}
}
// Opening links in a new window
var openLinkInNewWindow = function(linkToOpen){
window.open(linkToOpen, '_blank');
clearInput();
}
// Having a specific text reply to specific strings
var textReplies = function() {
switch(textInputValueLowerCase){
// replies
case "code":
clearInput();
addTextToResults("Get web elements source code at <a target='_blank' href='</a>");
break;
case "founder":
clearInput();
addTextToResults("Niko and PWN Team are the founders");
break;
case "i love you":
case "love you":
case "love":
clearInput();
addTextToResults("Aww! Love you too ❤");
break;
case "ProgrammingWithNiko":
case "PWN":
case "programming":
case "python":
clearInput();
addTextToResults('Web development examples!');
openLinkInNewWindow('https://www.youtube.com/results?search_query=Web+development+examples');
break;
case "creator":
case "author":
case "who is your author":
case "who is your creator":
case "who is your designer":
case "who is your developer":
case "designer":
case "developer":
clearInput();
addTextToResults('this is my developer JustControl1900 aka BUDDHI ASHEN');
openLinkInNewWindow('https://www.reddit.com/user/JustControl1900');
break;
case "hello":
case "hi":
case "hola":
clearInput();
addTextToResults("Hello, I am EWA... I am based on pure JavaScript.");
break;
case "hey":
case "whats up":
clearInput();
addTextToResults("oh !! hi there cutie!!");
break;
case "what the":
case "wtf":
clearInput();
addTextToResults("F***.");
break;
case "shit":
case "poop":
case "💩":
clearInput();
addTextToResults("💩");
break;
// replies
case "youtube":
clearInput();
addTextToResults("Type youtube + something to search for.");
break;
case "google":
clearInput();
addTextToResults("Type google + something to search for.");
break;
case "wiki":
case "wikipedia":
clearInput();
addTextToResults("Type wiki + something to search for.");
break;
case "time":
clearInput();
getTimeAndDate("time");
break;
case "date":
clearInput();
getTimeAndDate("date");
break;
case "help":
case "?":
clearInput();
postHelpList();
break;
default:
clearInput();
addTextToResults("<p><i>The command " + "<b>" + textInputValue + "</b>" + " was not found. Type <b>Help</b> to see all commands.</i></p>");
break;
}
}
// Main function to check the entered text and assign it to the correct function
var checkWord = function() {
textInputValue = document.getElementById('terminalTextInput').value.trim(); //get the text from the text input to a variable
textInputValueLowerCase = textInputValue.toLowerCase(); //get the lower case of the string
if (textInputValue != ""){ //checking if text was entered
addTextToResults("<p class='userEnteredText'>> " + textInputValue + "</p>");
if (textInputValueLowerCase.substr(0,5) == "open ") { //if the first 5 characters = open + space
openLinkInNewWindow('http://' + textInputValueLowerCase.substr(5));
addTextToResults("<i>The URL " + "<b>" + textInputValue.substr(5) + "</b>" + " should be opened now.</i>");
} else if (textInputValueLowerCase.substr(0,8) == "youtube ") {
openLinkInNewWindow('https://www.youtube.com/results?search_query=' + textInputValueLowerCase.substr(8));
addTextToResults("<i>I've searched on YouTube for " + "<b>" + textInputValue.substr(8) + "</b>" + " it should be opened now.</i>");
} else if (textInputValueLowerCase.substr(0,7) == "google ") {
openLinkInNewWindow('https://www.google.com/search?q=' + textInputValueLowerCase.substr(7));
addTextToResults("<i>I've searched on Google for " + "<b>" + textInputValue.substr(7) + "</b>" + " it should be opened now.</i>");
} else if (textInputValueLowerCase.substr(0,5) == "wiki "){
openLinkInNewWindow('https://wikipedia.org/w/index.php?search=' + textInputValueLowerCase.substr(5));
addTextToResults("<i>I've searched on Wikipedia for " + "<b>" + textInputValue.substr(5) + "</b>" + " it should be opened now.</i>");
} else{
textReplies();
}
}
};
});