-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathjsify.js
346 lines (316 loc) · 11.5 KB
/
jsify.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
var tilt = 0;
var Teacher = "Taylor Hudson ";
var ClubPresident = "Zach Gray";
var ClubVP = "Ayush Agarwal";
var Secretary = "Deep Desai";
var Historian = "Ryan Noeske";
var Secretary = "Ryan King";
var advisor= "Nathan Wander";
var AntiDeep = "Chris Delagarza";
var HighSchool = "Allen High School";
var ASCII = function(){
/*return" ___ __ __ __ ___ ___ __ __ __ ___ __ ___"+"\n"+
" /\ | | |__ |\ | / ` / \ |\/| |__) | | | |__ |__) /__` / ` | |__ |\ | / ` |__"+"\n"+
"/--\ |___ |___ |___ | \| \__, \__/ | | | \__/ | |___ | \ .__/ \__, | |___ | \| \__, |___"+"\n"
*/
return " $$$$$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$\\ $$\\ " + "\n" +
"$$ __$$\\ $$ |$$ | $$ __$$\\ $$ __$$\\ \\__|" + "\n" +
"$$ / $$ |$$ |$$ | $$$$$$\\ $$$$$$$\\ $$ / \\__| $$$$$$\\ $$$$$$\\$$$$\\ $$$$$$\\ $$ / \\__| $$$$$$$\\ $$\\ " + "\n" +
"$$$$$$$$ |$$ |$$ |$$ __$$\\ $$ __$$\\ $$ | $$ __$$\\ $$ _$$ _$$\\ $$ __$$\\ \\$$$$$$\\ $$ _____|$$ |" + "\n" +
"$$ __$$ |$$ |$$ |$$$$$$$$ |$$ | $$ | $$ | $$ / $$ |$$ / $$ / $$ |$$ / $$ | \\____$$\\ $$ / $$ |" + "\n" +
"$$ | $$ |$$ |$$ |$$ ____|$$ | $$ | $$ | $$\\ $$ | $$ |$$ | $$ | $$ |$$ | $$ | $$\\ $$ |$$ | $$ |" + "\n" +
"$$ | $$ |$$ |$$ |\\$$$$$$$\\ $$ | $$ | \\$$$$$$ |\\$$$$$$ |$$ | $$ | $$ |$$$$$$$ | \\$$$$$$ |\\$$$$$$$\\ $$ |" + "\n" +
"\\__| \\__|\\__|\\__| \\_______|\\__| \\__| \\______/ \\______/ \\__| \\__| \\__|$$ ____/ \\______/ \\_______|\\__|" + "\n" +
" $$ | " + "\n" +
" $$ | " + "\n" +
" \\__| " + "\n" ;
};
var linkify = function(text, url) {
return "<a target='_blank' href='" + url + "'>" + text + "</a>";
};
var specialify = function(text) {
return "<span class='special'>" + text + "</span>";
};
var data = {
hello: "Welcome to Allen Computer Science, where we " + specialify("promote Computer Science, development and innovation") + "\n\tin the Allen community by providing " + specialify("an place to soar") + " for those interested in furthering their \n\tpursuit of the field and attending " + specialify("competitions") + " ranging from " + specialify("hackathons") + " to " + specialify("algorithm contests") + ". \n\tComputer Science club meets every Wednesday from 3:35 to 5, and works on multifaceted projects, \n\tranging from app to web to even game development.",
help: [ {
name: specialify("hello"),
description: "Our mission statement"
}, {
name: specialify("team"),
description: "Our board and members"
}, {
name: specialify("competitions"),
description: "Info about upcoming competitions and hackathons"
}, {
name: specialify("links"),
description: "Displays links to permission slips, resources, and more"
},{
name: specialify("showcase"),
description: "HS students\' cool projects"
},{
name: specialify("contact"),
description: "Get in touch for outreach and info on projects"
}, {
name: specialify("twitter"),
description: "Follow us " + linkify("@Allen_CompSci", "https://twitter.com/allen_compsci")
},
{
name: specialify("help"),
description: "Displays all commands"
}],
contact:
[
{
name:"Contact <a href='mailto:Taylor.Hudson@allenisd.org'>Taylor Hudson</a>.",
},{
name:"Contact <a href='mailto:Allencomputerscience@gmail.com'>Computer Science Club</a>."
}],
team:
[{
name: specialify("Taylor") + " Hudson",
position: "Club Sponsor"
},
{
name: specialify("Zach") + " Gray",
position: "President"
},
{
name: specialify("Ayush") + " Agarwal",
position: "Vice President"
},
{
name: specialify("Deep") + " Desai",
position: "Secretary"
},{
name: specialify("Ryan") + " Noeske",
position: "Historian"
},{
name: specialify("Ryan") + " King",
position: "Treasurer"
},{
name: specialify("Chris") + " Delegarza",
position: "AntiDeep"
},{
name: specialify("Nathan") + " Wander",
position: "Advisor"
},
],
competitions: "Competition schedule coming soon!",
links: [
{
name : linkify("CS Classes' Github", "https://github.com/AllenCompSci"),
description: "Github for all CS classes, where projects and assignments are hosted."
},
{
name : linkify("CompSci Club Github", "https://github.com/orgs/allen-computer-science/dashboard"),
description: "Github for CompSci Club, where project and ideas are hosted."
},
{
name : linkify("Allen High School", "http://www.allenisd.org/allenhs"),
},
{
name : linkify("Taylor Hudson", "https://www.allenisd.org/Domain/3279"),
},
{
name : linkify("CSCI 1 : Aug - Sept", "https://github.com/AllenCompSci/August_September-2017"),
},
{
name : linkify("CSCI 1 : Oct - Dec", "https://github.com/AllenCompSci/October_December_2017"),
}
],
showcase: [{
name: linkify("Cool Projects we've made.","http://github.com/AllenCompSci"),
authors: "Look at projects which <span class='special'>highschool students</span> have made!"
}],
invalid: "That's not a valid command! Type <span class='special'>help</span> for a list of commands."
};
var describify = function(obj) {
var output = "";
properties = [];
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
properties.push(obj[property]);
}
}
output += properties.join(" | ");
return output;
};
var listify = function(list) {
var output = "";
for (var i = 0; i < list.length; i++) {
output += "\t• ";
var described = describify(list[i]);
output += described;
output += "\n";
}
return output;
};
var format = function(field) {
var unformatted = data[field];
if (typeof unformatted == 'string') {
return "\n\t" + unformatted + "\n\n";
}
return "\n" + listify(unformatted) + "\n";
};
var lambdify = function(format_string) {
return function() { return format(format_string) }
}
var options = {
include: ["score"],
shouldSort: true,
threshold: 0.3,
location: 0,
distance: 100,
maxPatternLength: 32,
keys: ['command']
};
var search = function(list, searchitem) {
options.distance = (searchitem.length<=2? 0 : 100)
return new Fuse(list, options).search(searchitem)
}
$(function() {
var intro = ASCII() +"\n"+ "Welcome to the Computer Science department at " + "Allen High School" +"!\nType 'hello' below to learn what we're all about! \nTry '?' for more.\n\n";
var jqconsole = $('#console').jqconsole(intro, 'C:\\Users\\Eagles> ');
var cout = function(input){
jqconsole.Write(" "+input.replace(/\n/g,'\n ')+'\n', 'jqconsole-output', false);
}
function process(input) {
var parsed = input.split(" ");
var commands = [
[["help", "?", "ls"], lambdify('help')],
[["hello", "mission", "description", "why"], lambdify('hello')],
[["team", "execs", "executives", "officers"], lambdify('team')],
[["competitions", "hackathons", "events"], lambdify('competitions')],
[["links", "forms", "info"], lambdify('links')],
[["projects", "showcase"], lambdify('showcase')],
[["contact"], lambdify('contact')],
[["soar"], lambdify('soar')],
[["clear", "cls"], function() { jqconsole.Clear(); return '\r'; }],
[["fb", "facebook"], function() {
window.location.href = "https://www.facebook.com/groups/";
return '\r';
}],
[["tilt"], function() {
tilt += 7;
$(document.documentElement).addClass('rotate_please');
document.documentElement.setAttribute('style', 'transform: rotate(' + String(tilt) + 'deg);');
return "\n\n";
}],
[["qt"], function() {
tilt += 70;
$(document.documentElement).addClass('qt_please');
document.documentElement.setAttribute('style', 'transform: rotate(' + String(tilt) + 'deg);');
return "\n\n";
}],
[["untilt"], function() {
tilt = 0;
$(document.documentElement).removeClass('rotate_please');
$(document.documentElement).removeClass('qt_please');
document.documentElement.setAttribute('style', 'transform: rotate(' + String(tilt) + 'deg);');
return "\n\n";
}],
[["js", "javascript", "code"], function() {}], //since this is processed directly, there is no need for a function here
];
var response = null;
commands.forEach(function(key, index, commands) {
key[0].forEach(function(term, tindex) {
if (term === parsed[0]) {
response = key[1]();
}
});
});
if (response) {
return response;
} else {
var commands_list = [];
commands.forEach(function(key, index, commands) {
key[0].forEach(function(term, tindex) {
if (term !== "qt") {
commands_list.push({
'command': term,
'callback': key[1]
});
}
})
});
var results = search(commands_list, parsed[0]);
if (results.length > 0) {
response = '\nThat command doesn\'t exist. Did you mean ';
results.forEach(function(result, index) {
if (index === results.length - 1 && results.length == 2) {
response = response.substring(0, response.length - 2);
response += ' or ' + specialify(result['item']['command']) + ', ';
} else if (index === results.length - 1 && results.length > 1) {
response = response.substring(0, response.length - 2);
response += ', or ' + specialify(result['item']['command']) + ', ';
} else {
response += specialify(result['item']['command']) + ', ';
}
});
response = response.substring(0, response.length - 2);
response += '?\n\n';
return response;
} else {
return '\nThat command doesn\'t exist. Here is a list of commands you can use:\n' + format('help');
}
}
};
var jsmode = false;
var blockQuery = false;
var block = "";
var processJs = function(input){
if(input.match(/exit/) || input.match(/process.exit\(/)){
jsmode = false;
jqconsole.SetPromptLabel("C:\Users\Eagles> ");
jqconsole.Write('\n');
startPrompt();
return;
}
if(!blockQuery){
block = "";
}
block+=input;
var leftParens = (block.match(/\{/g)? block.match(/\{/g).length: 0);
var rightParens = (block.match(/\}/g)? block.match(/\}/g).length: 0);
if(leftParens > rightParens){
blockQuery = true;
startPrompt();
return;
}else{
blockQuery = false;
}
var result;
try{
result = eval('eval')(block); //indirect call so it's global
}catch(err){
result = err;
}
result = String(result);
cout(result);
}
var processQuery = function(input) {
if(jsmode){
processJs(input);
startPrompt();
return;
}
if (input) {
if(input == "javascript" || input == "js" || input == "code" || input == "node"){
jsmode = true;
jqconsole.SetPromptLabel(" > ");
jqconsole.Write('\n');
startPrompt();
return;
}
jqconsole.Write(process(input),'jqconsole-output',false);
} else {
jqconsole.Write('\n Here is a list of commands:\n' + format('help'), 'jqconsole-output', false);
}
startPrompt();
}
var startPrompt = function() {
jqconsole.Prompt(true, processQuery);
};
startPrompt();
});