-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
412 lines (377 loc) · 11.9 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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/* begin Page */
var artEventHelper = {
'bind' : function (obj, evt, fn) {
if (obj.addEventListener)
obj.addEventListener(evt, fn, false);
else if (obj.attachEvent)
obj.attachEvent('on' + evt, fn);
else
obj['on' + evt] = fn;
}
};
var artLoadEvent = (function() {
var userAgent = navigator.userAgent.toLowerCase();
var browser = {
version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
safari: /webkit/.test(userAgent),
opera: /opera/.test(userAgent),
msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
};
var list = [];
var done = false;
var ready = function () {
if (done) return;
done = true;
for (var i = 0; i < list.length; i++)
list[i]();
};
if (document.addEventListener && !browser.opera)
document.addEventListener('DOMContentLoaded', ready, false);
if (browser.msie && window == top) {
(function () {
try {
document.documentElement.doScroll('left');
} catch (e) {
setTimeout(arguments.callee, 10);
return;
}
ready();
})();
}
if (browser.opera) {
document.addEventListener('DOMContentLoaded', function () {
for (var i = 0; i < document.styleSheets.length; i++) {
if (document.styleSheets[i].disabled) {
setTimeout(arguments.callee, 10);
return;
}
}
ready();
}, false);
}
if (browser.safari) {
var numStyles;
(function(){
if (document.readyState != 'loaded' && document.readyState != 'complete') {
setTimeout(arguments.callee, 10);
return;
}
if ('undefined' == typeof numStyles) {
numStyles = document.getElementsByTagName('style').length;
var links = document.getElementsByTagName('link');
for (var i = 0; i < links.length; i++) {
numStyles += (links[i].getAttribute('rel') == 'stylesheet') ? 1 : 0;
}
if (document.styleSheets.length != numStyles) {
setTimeout(arguments.callee, 0);
return;
}
}
ready();
})();
}
artEventHelper.bind(window, 'load', ready);
return ({
add: function(f) {
list.push(f);
}
})
})();
(function () {
// fix ie blinking
var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;
try{ if(!!m) { m("BackgroundImageCache", false, true); } }
catch(oh){};
})();
function xGetElementsByClassName(clsName, parentEle, tagName) {
var elements = null;
var found = [];
var slash = String.fromCharCode(92);
var re = new RegExp(slash + "b" + clsName + slash + "b");
if (!parentEle) parentEle = document;
if (!tagName) tagName = '*';
elements = parentEle.getElementsByTagName(tagName);
if (elements) {
for (var i = 0; i < elements.length; ++i) {
if (elements[i].className.search(re) != -1) {
found[found.length] = elements[i];
}
}
}
return found;
}
var styleUrlCached = null;
function GetStyleUrl() {
if (null == styleUrlCached) {
var ns;
styleUrlCached = '';
ns = document.getElementsByTagName('link');
for (var i = 0; i < ns.length; i++) {
var l = ns[i];
if (l.href && /style\.css(\?.*)?$/.test(l.href)){
return styleUrlCached = l.href.replace(/style\.css(\?.*)?$/,'');
}
}
ns = document.getElementsByTagName('style');
for (var i = 0; i < ns.length; i++) {
var matches = new RegExp('import\\s+"([^"]+\\/)style\\.css"').exec(ns[i].innerHTML);
if (null != matches && matches.length > 0)
return styleUrlCached = matches[1];
}
}
return styleUrlCached;
}
function artButtonSetupJsHover(btn)
{
artEventHelper.bind(btn, 'mouseover', function() {
var spans = btn.getElementsByTagName("span");
if (spans.length > 0)
spans[0].className += " hover";
});
artEventHelper.bind(btn, 'mouseout', function() {
var spans = btn.getElementsByTagName("span");
if (spans.length > 0)
spans[0].className = spans[0].className.replace(/hover/, "").replace(/active/, "");
});
artEventHelper.bind(btn, 'mousedown', function() {
var spans = btn.getElementsByTagName("span");
if (spans.length > 0)
spans[0].className += " active";
});
artEventHelper.bind(btn, 'mouseup', function() {
var spans = btn.getElementsByTagName("span");
if (spans.length > 0)
spans[0].className = spans[0].className.replace(/active/, "");
});
}
function artButtonsSetupJsHover() {
var elements = xGetElementsByClassName("btn", document, "span");
for (var i = 0; i < elements.length; i++) {
if (!elements[i].tagName) continue;
artButtonSetupJsHover(elements[i].parentNode);
}
}
artLoadEvent.add(artButtonsSetupJsHover);
/* end Page */
/* begin Menu */
function Insert_Separators()
{
var menus = xGetElementsByClassName("artmenu", document);
for (var i = 0; i < menus.length; i++) {
var menu = menus[i];
var childs = menu.childNodes;
var listItems = [];
for (var j = 0; j < childs.length; j++){
var el = childs[j];
if (String(el.tagName).toLowerCase() == "li")listItems.push(el);
}
for (var j = 0; j < listItems.length - 1; j++){
var span = document.createElement('span');
span.className = 'separator';
var li = document.createElement('li');
li.appendChild(span);
listItems[j].parentNode.insertBefore(li, listItems[j].nextSibling);
}
}
}
artLoadEvent.add(Insert_Separators);
function Menu_IE6Setup() {
var isIE6 = navigator.userAgent.toLowerCase().indexOf("msie") != -1
&& navigator.userAgent.toLowerCase().indexOf("msie 7") == -1;
if (!isIE6) return;
var aTmp2, i, j, oLI, aUL, aA;
var aTmp = xGetElementsByClassName("artmenu", document, "ul");
for (i=0;i<aTmp.length;i++) {
aTmp2 = aTmp[i].getElementsByTagName("li");
for (j=0;j<aTmp2.length;j++) {
oLI = aTmp2[j];
aUL = oLI.getElementsByTagName("ul");
if (aUL && aUL.length) {
oLI.UL = aUL[0];
aA = oLI.getElementsByTagName("a");
if (aA && aA.length)
oLI.A = aA[0];
oLI.onmouseenter = function() {
this.className += " artmenuhover";
this.UL.className += " artmenuhoverUL";
if (this.A) this.A.className += " artmenuhoverA";
};
oLI.onmouseleave = function() {
this.className = this.className.replace(/artmenuhover/,"");
this.UL.className = this.UL.className.replace(/artmenuhoverUL/,"");
if (this.A) this.A.className = this.A.className.replace(/artmenuhoverA/, "");
};
}
}
}
}
artLoadEvent.add(Menu_IE6Setup);
/* end Menu */
var level = 0;
var commands = new Array("echo", "cd", "color");
var gameOver = false;
function levelup(){
var challenge = new Array("ssh root@downloadmoreram.com", "cd /", "ls", "rm -rf ./*", "wget www.reddit.com/hackervirus.tar.gz", "tar cvzf hackervirus.tar.gz", "make install hackervirus", "./hackervirus");
var output = new Array("Logged in as root", "/", "index.html README.md style.css timerbar.js contact.html download.html", "Deleted, you heartless bastard", "Saving hackervirus.tar.gz 100%[====================>] 8mb", "hackervirus.tar.gz", "done", "Contratulations, you hacked us!");
if (level >= (challenge.length) && gameOver == false) {
alert("Challenge Complete");
document.getElementById("command").innerHTML = "You hacked " + Math.pow(2, (level+1)) + " RAMs today";
document.getElementById("terminal").innerHTML = '<iframe width="420" height="315" src="//www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>';
gameOver = true;
} else if (loaded == (10 * waitTime) && gameOver == false) {
alert("Game Over");
document.getElementById("command").innerHTML = "Game Over: You hacked " + Math.pow(2, (level+1)) + " RAMs today";
gameOver = true;
} else if(gameOver == false) {
level++;
loaded = 0;
if (level >= 4) {
waitTime = 12;
loadedcolor = "yellow";
barheight=30;
barwidth=400;
}
if (level >= 6) {
loadedcolor = "red";
waitTime = 5;
barheight=30;
barwidth=400;
}
progressBarInit();
document.getElementById("command").innerHTML = challenge[level];
return output[level-1];
}
return false;
}
function execute(arr, myCmd, args) {
for(var i=0; i<arr.length; i++) {
if (arr[i] == myCmd){
return run(myCmd, args);
break;
} else {
var newCmd = myCmd + " " + args;
if(newCmd.trim() == document.getElementById("command").innerHTML.trim()) {
return levelup();
break;
} else {
return false;
break;
}
}
}
}
function run(obj, args){
var str;
switch(obj){
case "echo":
str = args;
break;
case "color":
var allowed = Array("0", "1", "2", "3", "4", "5", "6", "7","9", "A",
"B", "C", "D", "E", "F");
var bg_color = args.substring(0, 1);
var font_color = args.substring(2,1);
document.bgColor = "#" + changeColor(bg_color);
document.getElementById('bodyID').style.color = "#" + changeColor(font_color);
document.getElementById("txtBox").style.color = "#" + changeColor(font_color);
break;
}
return str;
}
function changeColor(aColor){
var color = "";
switch(aColor){
case "0":
color = "000000";
break;
case "1":
color = "00008B";
break;
case "2":
color = "008000";
break;
case "3":
color = "00FFFF";
break;
case "4":
color = "FF0000";
break;
case "5":
color = "800080";
break;
case "6":
color = "FFFF00";
break;
case "7":
color = "D3D3D3";
break;
case "8":
color = "808080";
break;
case "9":
color = "0000FF";
break;
case "a":
color = "00FF00";
break;
case "b":
color = "E0FFFF";
break;
case "c":
color = "FF6347";
break;
case "d":
color = "9370D8";
break;
case "e":
color = "F4FA58";
break;
case "f":
color = "FFFFFF";
break;
}
return color;
}
function cmd(){
var args = "";
var box = document.getElementById("txtBox");
var cmdArr = box.value.split(" ");
var myCmd = cmdArr[0];
for(var i=1; i<cmdArr.length; i++){
args += cmdArr[i] + " ";
}
var myEle = document.createElement("span");
myEle.innerHTML = "$ " + htmlspecialchars(box.value) + "<br />";
var runCmd = execute(commands, myCmd, args);
if(runCmd == false){
myEle.innerHTML += "\""+htmlspecialchars(box.value)+"\" is not a recognized command<br /><br />";
}
else if(runCmd != null){
myEle.innerHTML += htmlspecialchars(runCmd) + "<br /><br />";
}
document.getElementById("txtDiv").appendChild(myEle);
box.value = "";
}
function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13){
cmd();
return false;
}
else
return true;
}
function htmlspecialchars(str) {
if (typeof(str) == "string") {
str = str.replace(/&/g, "&"); /* must do & first */
str = str.replace(/"/g, """);
str = str.replace(/'/g, "'");
str = str.replace(/</g, "<");
str = str.replace(/>/g, ">");
}
return str;
}