Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

comments

  • Loading branch information...
commit b5ede32e9d6f2d4f4deaf7eb88ab45789bd852a9 1 parent 08321fb
Simone Masiero authored
Showing with 62 additions and 62 deletions.
  1. +62 −62 script.js
124 script.js
View
@@ -7,7 +7,7 @@ $(
function(){
$( document ).keydown(
function ( event ) {
- Typer.addText( event );
+ Typer.addText( event ); //Capture the keydown event and call the addText, this is executed on page load
}
);
}
@@ -15,95 +15,95 @@ $(
var Typer={
text: null,
- altTimer:null,
- index:0,
- speed:2,
- file:"",
- altt:0,
- altd:0,
- init: function(){
- altTimer=setInterval(function(){Typer.updLstChr();},500);
- $.get(Typer.file,function(data){
- Typer.text=data;
+ accessCountimer:null,
+ index:0, // current cursor position
+ speed:2, // speed of the Typer
+ file:"", //file, must be setted
+ accessCount:0, //times alt is pressed for Access Granted
+ deniedCount:0, //times caps is pressed for Access Denied
+ init: function(){// inizialize Hacker Typer
+ accessCountimer=setInterval(function(){Typer.updLstChr();},500); // inizialize timer for blinking cursor
+ $.get(Typer.file,function(data){// get the text file
+ Typer.text=data;// save the textfile in Typer.text
});
},
content:function(){
- return $("#console").html();
+ return $("#console").html();// get console content
},
- write:function(str){
+ write:function(str){// append to console content
$("#console").append(str);
return false;
},
- makeAccess:function(){
- Typer.hidepop();
- Typer.altt=0;
- var ddiv=$("<div id='gran'>").html("");
- ddiv.attr("style","position:absolute;top:200px;background:#333;padding:20px;border:1px solid #999;width:300px;left:50%;margin-left:-150px;text-align:center;");
- ddiv.html("<h1>ACCESS GRANTED</h1>");
- $(document.body).prepend(ddiv);
+ makeAccess:function(){//create Access Granted popUp FIXME: popup is on top of the page and doesn't show is the page is scrolled
+ Typer.hidepop(); // hide all popups
+ Typer.accessCount=0; //reset count
+ var ddiv=$("<div id='gran'>").html(""); // create new blank div and id "gran"
+ ddiv.addClass("accessGranted"); // add class to the div
+ ddiv.html("<h1>ACCESS GRANTED</h1>"); // set content of div
+ $(document.body).prepend(ddiv); // prepend div to body
return false;
},
- makeDenied:function(){
- Typer.hidepop();
- Typer.altd=0;
- var ddiv=$("<div id='deni'>").html("");
- ddiv.attr("style","color:#F00;position:absolute;top:200px;background:#511;padding:20px;border:1px solid #F00;width:300px;left:50%;margin-left:-150px;text-align:center;");
- ddiv.html("<h1>ACCESS DENIED</h1>");
- $(document.body).prepend(ddiv);
+ makeDenied:function(){//create Access Denied popUp FIXME: popup is on top of the page and doesn't show is the page is scrolled
+ Typer.hidepop(); // hide all popups
+ Typer.deniedCount=0; //reset count
+ var ddiv=$("<div id='deni'>").html(""); // create new blank div and id "deni"
+ ddiv.addClass("accessDenied");// add class to the div
+ ddiv.html("<h1>ACCESS DENIED</h1>");// set content of div
+ $(document.body).prepend(ddiv);// prepend div to body
return false;
},
- hidepop:function(){
+ hidepop:function(){// remove all existing popups
$("#deni").remove();
$("#gran").remove();
},
- addText:function(e){
- if(e.keyCode==18){
- Typer.altt++;
- if(Typer.altt>=3){
- Typer.makeAccess();
+ addText:function(key){//Main function to add the code
+ if(key.keyCode==18){// key 18 = alt key
+ Typer.accessCount++; //increase counter
+ if(Typer.accessCount>=3){// if it's presed 3 times
+ Typer.makeAccess(); // make access popup
}
- }else if(e.keyCode==20){
- Typer.altd++;
- if(Typer.altd>=3){
- Typer.makeDenied();
+ }else if(key.keyCode==20){// key 20 = caps lock
+ Typer.deniedCount++; // increase counter
+ if(Typer.deniedCount>=3){ // if it's pressed 3 times
+ Typer.makeDenied(); // make denied popup
}
- }else if(e.keyCode==27){
- Typer.hidepop();
- }else if(Typer.text){
- var cont=Typer.content();
- if(cont.substring(cont.length-1,cont.length)=="|")
- $("#console").html($("#console").html().substring(0,cont.length-1));
- if(e.keyCode!=8){
- Typer.index+=Typer.speed;
+ }else if(key.keyCode==27){ // key 27 = esc key
+ Typer.hidepop(); // hide all popups
+ }else if(Typer.text){ // otherway if text is loaded
+ var cont=Typer.content(); // get the console content
+ if(cont.substring(cont.length-1,cont.length)=="|") // if the last char is the blinking cursor
+ $("#console").html($("#console").html().substring(0,cont.length-1)); // remove it before adding the text
+ if(key.keyCode!=8){ // if key is not backspace
+ Typer.index+=Typer.speed; // add to the index the speed
}else{
- if(Typer.index>0)
- Typer.index-=Typer.speed;
+ if(Typer.index>0) // else if index is not less than 0
+ Typer.index-=Typer.speed;// remove speed for deleting text
}
- var text=$("<div/>").text(Typer.text.substring(0,Typer.index)).html();
- var rtn= new RegExp("\n", "g");
- var rts= new RegExp("\\s", "g");
- var rtt= new RegExp("\\t", "g");
- $("#console").html(text.replace(rtn,"<br/>").replace(rtt,"&nbsp;&nbsp;&nbsp;&nbsp;").replace(rts,"&nbsp;"));
- window.scrollBy(0,50);
+ var text=$("<div/>").text(Typer.text.substring(0,Typer.index)).html();// parse the text for stripping html enities
+ var rtn= new RegExp("\n", "g"); // newline regex
+ var rts= new RegExp("\\s", "g"); // whitespace regex
+ var rtt= new RegExp("\\t", "g"); // tab regex
+ $("#console").html(text.replace(rtn,"<br/>").replace(rtt,"&nbsp;&nbsp;&nbsp;&nbsp;").replace(rts,"&nbsp;"));// replace newline chars with br, tabs with 4 space and blanks with an html blank
+ window.scrollBy(0,50); // scroll to make sure bottom is always visible
}
- if ( e.preventDefault && e.keyCode != 122 ) {
- e.preventDefault()
+ if ( key.preventDefault && key.keyCode != 122 ) { // prevent F11(fullscreen) from being blocked
+ key.preventDefault()
};
- if(e.keyCode != 122){
- e.returnValue = false;
+ if(key.keyCode != 122){ // otherway prevent keys default behavior
+ key.returnValue = false;
}
},
- updLstChr:function(){
- var cont=this.content();
- if(cont.substring(cont.length-1,cont.length)=="|")
- $("#console").html($("#console").html().substring(0,cont.length-1));
+ updLstChr:function(){ // blinking cursor
+ var cont=this.content(); // get console
+ if(cont.substring(cont.length-1,cont.length)=="|") // if last char is the cursor
+ $("#console").html($("#console").html().substring(0,cont.length-1)); // remove it
else
- this.write("|");
+ this.write("|"); // else write it
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.