Best Projects

Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)

Javascript Command Interpreter

alert("This program run on IE only, and require activeX enabled, choose yes in the confirm prompt");


/**** BASIC add ****/


function command_history(){
var el;
var count=1;
var command_arr=new Array('');
function init(){
}

String.prototype._triM=function(){
var a=this.replace(/^\s+/,'');
return this.replace(/^\s+$/,'');

}


var _tohtml=function(textcontent){//return textcontent;
if(textcontent==null)return;
//if(textcontent=="")return;
while(textcontent.indexOf("<")!=-1)
textcontent=textcontent.replace("<","<");
while(textcontent.indexOf(">")!=-1)
textcontent=textcontent.replace(">",">");
while(textcontent.indexOf("\t")!=-1)
textcontent=textcontent.replace("\t","");
while(textcontent.indexOf("\n")!=-1)
textcontent=textcontent.replace("\n","
");

//while(textcontent.indexOf("&")!=-1)
// textcontent=textcontent.replace("&","&");
return textcontent;

}



function _deleteemptycommand(){var ret=new Array;


for(var i=0; i<=command_arr.length-1;i++){
if(command_arr[i].length<4){
command_arr[i]._triM();
command_arr.splice(i,1);
i--;
}
}
count=command_arr.length;


}

this.out=function(x){
}
this.save2file=function(file){}
this.load4mfile=function(file){}
this.erase_current=function(){
command_arr.splice(count,1);


}
this.push_command=function(x){
x._triM();
while(x.indexOf("\n")!=-1)
x=x.replace("\n","");;
if(count!=command_arr.length){
var goto=count;
command_arr[count]=x;
this.rollback_command(goto);
return;}
command_arr.push(x);
count=command_arr.length;
_deleteemptycommand();

}
this.rollback_command=function(x){if(x)count=x+1;
if(count>0)count--;
el.innerHTML=_tohtml(command_arr[count]);
var max=command_arr.length-1;
this.out('history pos '+count+ ' from '+max);
}



this.rollfront_command=function(x){if(x)count=x-1;
if(count el.innerHTML=_tohtml(command_arr[count]);
var max=command_arr.length-1;
this.out('history pos '+count+ ' from '+max);
if(count==command_arr.length){
el.innerHTML='';
return;
}



}
this.outofend=function(){
if(count>=command_arr.length)return 1;
}
this.attachinnerEl=function(x){
el=x;

}}

function layar_output(){
var mes=document.createElement("div");
var tmp=new Array();
var togglelinedflag=1;

var _tohtml=function(textcontent){//return textcontent;
if(textcontent==null)return;
while(textcontent.indexOf("<")!=-1)
textcontent=textcontent.replace("<","<");
while(textcontent.indexOf(">")!=-1)
textcontent=textcontent.replace(">",">");
while(textcontent.indexOf("\t")!=-1)
textcontent=textcontent.replace("\t","");
while(textcontent.indexOf("\n")!=-1)
textcontent=textcontent.replace("\n","
");

//while(textcontent.indexOf("&")!=-1)
// textcontent=textcontent.replace("&","&");
return textcontent;

}

mes.baris=24;
mes.showbaris=24;
var showbaris_b=1;;
mes.maxLength=70;
mes.style.height=40;
mes.style.width=900;
mes.promptcharcode=19;
mes.style.fontFamily='fixedsys';
mes.toggleshowall=function(x){
if(x=='all')togglelinedflag=0;
if(x=='hide')togglelinedflag=1;
if(!x)x='';
if(!togglelinedflag){
mes.showalllines();
togglelinedflag=1;
showbaris_b=mes.showbaris;
mes.showbaris=24;
return;}
if(togglelinedflag){
mes.showbaris=showbaris_b;
togglelinedflag=0;
mes.hide();
return;}

}
mes.showalllines=function(){
for(var x=0;x<=mes.baris;x++){if(!mes.childNodes[x])break;
mes.childNodes[x].style.visibility='visible';
mes.childNodes[x].style.position='relative';
}
}

mes.hide=function(){
var tohidelimit=mes.childNodes.length-mes.showbaris;
//alert('th'+tohidelimit);
for(var x=0;x var tohide=mes.childNodes[x];
tohide.style.visibility='hidden';
tohide.style.position='absolute';}

}
mes.setshowbaris=function(x){
mes.showbaris=x;showbaris_b=x
mes.toggleshowall('hide');
}
mes.out=function(x,color){if(!color)color='white';
if(color=='white')x=x.substr(0,mes.maxLength);
var line=document.createElement("span");
line.name='line';
var f=document.createElement("span");
var p=document.createElement("span");
p.style.fontFamily='webdings';
if(color!="help"){
p.appendChild(document.createTextNode(String.fromCharCode(mes.promptcharcode)));



p.style.color='red';}

if(color=='help'){color='yellow';
f.style.color='yellow';
f.style.fontFamily='fixedsys';
f.style.fontSize=13;
f.style.left=30;
//f.style.fontWeight='bold';
f1="Filter: DropShadow(Color=#FF0000, OffX=2, OffY=2, Positive=1)";
f.style.filter=f1+'Filter: Blur(Add = 2, Direction = 225, Strength = 10)';
}

f.style.margin=3;
var br=document.createElement("br");
x=_tohtml(x);
f.innerHTML=x+"
";
f.style.color=color;
line.appendChild(p);line.appendChild(f);

mes.appendChild(line);

var currenthistlength=mes.childNodes.length-1;
if(currenthistlength>=mes.showbaris){
var tohide=mes.childNodes[currenthistlength-mes.showbaris];
tohide.style.visibility='hidden';
tohide.style.position='absolute';
}
while(mes.childNodes.length>mes.baris){
mes.removeChild(mes.firstChild);}


}
mes.echo=function(x){mes.out(x,'red');}
return mes;
}

/**** END OF ****/


function evaliframe(docbody,id){
if(!id)id="evaliframe_holder_el";
if(!docbody)docbody=document.body;
var holder_el=document.createElement("div");
holder_el.setAttribute("id",id)
docbody.appendChild(holder_el);

holder_el.style.background='blue';
var sCifrm=document.createElement("iframe");
sCifrm.isFrameReady=0;

var sCmes=document.createElement("div");
sCmes.out=function(x){sCmes.innerHTML=x;}


var sCcommand;
var comHs;
var thi=this;
var sCmultiline=0;
var lined_mode_flag=1;
var with_with;
var sCdelhidden=new Array(0,'');
holder_el.appendChild(sCmes);
holder_el.appendChild(sCifrm);
holder_el.style.top=0;
holder_el.style.position='absolute';


this.E=new Object();
this.E.holder_el=holder_el;
this.E.iframe_el=sCifrm;
this.E.upkeyprocess=new Array();
this.E.downkeyprocess=new Array();
this.E._focus=_focus;
document.attachEvent("onkeyup",this.E._focus );
document.attachEvent("onkeyup",function(){
if(window.event.keyCode==27){
thi.E.holder_el.style.visibility='visible';}} );


var _init=function(){

window.status+='jsci init';


thi.E.iframeDocument=sCifrm.contentWindow.document;
thi.E.iframeWin=sCifrm.contentWindow;

thi.E._runscript;
thi.E.upkeyprocess.unshift(_defaultupprocess);
thi.E.downkeyprocess.unshift(_defaultdownprocess);

window.status+='init start...';
/***** add class init */
if(typeof(layar_output)=="undefined"){}
else{
var dmes=new layar_output;
var dmesF=new layar_output;
holder_el.replaceChild(dmes,sCmes);
//sCmes=dmes;
thi.E.mes=dmes;
sCmes=thi.E.mes;
thi.E.mesF=dmesF;
thi.echo=sCmes.out;
//sCmes.out("message history add detected");
thi.E.togglesecondmode=function(){
thi.E.mes.swapNode(thi.E.mesF);
sCmes=thi.E.mes;

}
}

if(typeof(command_history)!="undefined"){
thi.E.comHs=new command_history;}
else{thi.E.comHs=new Object();
thi.E.comHs.push_command=function(){};
thi.E.comHs.rollback_command=function(){};
thi.E.comHs.rollfront_command=function(){}
thi.E.comHs.attachinnerEl=function(){}
thi.E.comHs.isLoadedflag=0;
}


/*************/
var l=document.createElement("div");
l.style.position='absolute';
l.innerHTML='jsci, JavaScript Command Interpreter created by Rachmat Fardian, hope this software usefull';
l.style.color='white';
l.style.fontFamily='Arial';
l.style.fontSize=13;
l.style.left=30;
l.style.fontWeight='bold';
var f1="Filter: DropShadow(Color=#FF0000, OffX=2, OffY=2, Positive=1)";
l.style.filter=f1+'Filter: Blur(Add = 2, Direction = 225, Strength = 10)';
sCmes.appendChild(l);
thi.echo('');
thi.echo('use [esc] key to hide');

thi.E.comHs.attachinnerEl(sCifrm.contentWindow.document.body);
sCifrm.contentWindow.focus();
sCmes.onmouseover=sCifrm.contentWindow.focus;
_readadd();
};

this.E._init=_init;

function _runinit(){
thi.E._init();}
setTimeout(_runinit,300);

this.E.togglemessage=function(x){
if(x=='all'){sCmes.toggleshowall('all');
var t=thi.E.comHs;
thi.E.comHs=thi.E.comHs_tmp;
thi.E.comHs_tmp=t;
thi.E.iframe_el.height_b=thi.E.iframe_el.style.height;
thi.E.iframe_el.style.height=40; return;

}
if(x=='hide'){
var t=thi.E.comHs;
thi.E.comHs=thi.E.comHs_tmp;
thi.E.comHs_tmp=t;

if(!thi.E.iframe_el.height_b)
thi.E.iframe_el.height_b=thi.E.iframe_el.style.height;

thi.E.iframe_el.style.height=thi.E.iframe_el.height_b;
sCmes.toggleshowall('hide');
return;
}
}



this.E._focus=function(){
this.iframe_el.contentWindow.document.body.contentEditable=true;
this.iframe_el.contentWindow.focus();

}


function _text2script(sc){
return sc;
var ret;var com;var arg1;var arg2;
/* if class declaration return */
if(sc.indexOf("new ")>1)return sc;
if(sc.indexOf(")")>1)return sc;
if(sc.indexOf("(")>1)return sc;
if(sc.indexOf(";")>1)return sc;
if(sc.length<=1){;return sc;}
return _easytype(sc);
function _easytype(scrip){ var ret;
var com=scrip.split(" ");
var arg1='';var arg2='';
if(com[1] && typeof( eval(com[1]) )=='undefined')com[1]="'"+com[1]+"'";
if(com[1])arg1=com[1];
if(com[2] && typeof( eval(com[2]) )=='undefined')com[2]="'"+com[2]+"'";
if(com[2])arg2=","+com[2];
if(com[0])ret=com[0]+"("+arg1+arg2+");";
return ret;
}

}

function _getfolder( s ) {
if(!s)s=document.URL;
//s = trim( s ) || 'C:';
var fso = new ActiveXObject( 'Scripting.FileSystemObject' ),
e, f, i, r = [];
if( fso.FolderExists( s ) ) {
f = fso.GetFolder( s );
e = new Enumerator(f.SubFolders);
for( ; !e.atEnd(); e.moveNext() ) {
if( ( i = e.item() ) ) { r.push( ' ' + i ); }
}
e = new Enumerator(f.files);
for( ; !e.atEnd(); e.moveNext() ) {
if( ( i = e.item() ) ) { r.push( '' + i ); }
}
}
return r;
}

var _readadd=function(){
var x=document.URL;
var arra=x.split("//");
var arra2=arra[1].split("\\");
arra2.pop();
path=arra2.join("\\");
path+="\\add\\";

var adds=_getfolder(path);
for(var x in adds)evaliframe._importscript(adds[x],holder_el);

}


function _showallmess(x){
sCmes.toggleshowall(x);
}



var _defaultupprocess=function() {
var sCfrwin=sCifrm.contentWindow;

var run_script=(sCfrwin.event.keyCode==13 && !sCmultiline);
if(sCfrwin.event.keyCode==27){
if(thi.E.holder_el.style.visibility=='hidden')
{thi.E.holder_el.style.visibility='visible';}
else{ thi.E.holder_el.style.visibility='hidden';

}
}


if(sCmultiline){;return;}
if(run_script){
_runscript();
}

}



function _upprocess(){
var cancel;
for(var x in thi.E.upkeyprocess){
cancel=thi.E.upkeyprocess[x].call();
if(cancel==-1)return;
}
}

var _defaultdownprocess=function(){
var sCfrbody=sCifrm.contentWindow.document.body;
var sCfrdoc=sCifrm.contentWindow.document;
var sCfrwin=sCifrm.contentWindow;
//alert(sCfrwin.event.keyCode);



if(sCfrwin.keyCode==65)sCfrwin.event.keyCode='';




if(sCfrwin.event.keyCode==33 && !sCmultiline){
sCdelhidden[0]=0;
//sCmes.promptcharcode=89;
if(sCfrbody.innerText.length<3)thi.E.comHs.erase_current();
thi.E.comHs.rollback_command();_focus();return;}
if(sCfrwin.event.keyCode==34 && !sCmultiline){
sCdelhidden[0]=0;
thi.E.comHs.rollfront_command();
if(thi.E.comHs.currentpos){var histInfo=thi.E.comHs.currentpos();
var sCclr='gray';var add='';
if(histInfo[0]>histInfo[1]){


sCclr='lightblue';add=' >> Ready For new Input ';sCmes.out(add,sCclr);}
}
_focus();
return;

}



}



function _downprocess(){
var cancel;
for(var x in thi.E.downkeyprocess){
cancel=thi.E.downkeyprocess[x].call();
if(cancel==-1)return;
}
}

function _focus(){
sCifrm.contentWindow.document.body.contentEditable=true;
sCifrm.contentWindow.focus();

}
function _runscript(){
var sCfrbody=sCifrm.contentWindow.document.body;
var sCfrdoc=sCifrm.contentWindow.document;
var sCfrwin=sCifrm.contentWindow;
var sCcommand=String(sCfrbody.innerText);
var comHTML=sCfrbody.innerHTML;
if(sCcommand.charAt(0)=="?"){
sCcommand=sCcommand.replace("?","alert ");
}
if(thi.E.comHs.outofend())_clear();

if(sCcommand.length)thi.E.comHs.push_command(sCcommand);
sCcommand=_text2script(sCcommand);
sCmes.out(sCcommand);

evaliframe._runscript(sCcommand,sCmes);

}


function _clear(){
var t=sCifrm.contentWindow.document.body;
while(t.firstChild)t.removeChild(t.firstChild);

}
function _always_on_top(){
var lc=document.body.lastChild;
if(lc.id=='evaliframe_holder_el')return;
var evn=document.getElementById('evaliframe_holder_el');
lc.swapNode(evn);
}

var instab=function(){

var tAB='';

var instab_sel=sCifrm.contentWindow.document.selection;
var instabd=instab_sel.createRange();
var res=tAB;//alert(instabd.htmlText);
if(instabd.htmlText.indexOf("
")){
var arr=instabd.htmlText.split("
");
for(var x=0 ; x arr[x]=tAB+arr[x];
var res=arr.join("
");}


instabd.pasteHTML(res);
instabd.select();
sCifrm.focus(); }



function _iframeinit(){

sCifrm.style.width=900;
sCifrm.style.height=30;
sCifrm.style.border=2;;

holder_el.style.top=0;
holder_el.style.left=0;
holder_el.style.margin=3;
sCifrm.contentWindow.document.body.contentEditable='true';


sCifrm.contentWindow.document.body.style.margin=3;
sCifrm.contentWindow.document.body.style.allowTransparency=true;
sCifrm.contentWindow.document.body.style.background='blue';
sCifrm.contentWindow.document.body.style.border=3;
sCifrm.contentWindow.document.body.style.fontFamily='fixedsys';
sCifrm.contentWindow.document.body.style.color='red';
sCifrm.contentWindow.document.attachEvent("onkeyup",_upprocess);
sCifrm.contentWindow.document.attachEvent("onkeydown",_downprocess);
sCifrm.isFrameReady=1;
function hidescrollbar(x){
sCifrm.contentWindow.document.body.style.scrollbarBaseColor = x;
sCifrm.contentWindow.document.body.style.scrollbarTrackColor = x;
sCifrm.contentWindow.document.body.style.scrollbarDarkShadowColor = x;
sCifrm.contentWindow.document.body.style.scrollbar3dLightColor = x;
sCifrm.contentWindow.document.body.style.scrollbarArrowColor= x;
sCifrm.contentWindow.document.body.style.scrollbarShadowColor = x;
sCifrm.contentWindow.document.body.style.scrollbarFaceColor = x;
sCifrm.contentWindow.document.body.style.scrollbarHighlightColor = x;}
hidescrollbar('blue');

sCifrm.contentWindow.document.body.focus();
};setTimeout(_iframeinit,500);















}



evaliframe._runscript=function(x,message_screen){
var out;
try{

out=eval(x); if(out)message_screen.out('>'+out,'yellow');

}catch(err){
message_screen.out(err.description,'red');
return out; }
// if(x)message_screen.out(out,'green');

return out;
}



evaliframe._importscript=function(x,el_to_attach){
var sc=document.createElement("script");
sc.setAttribute("src",x);
el_to_attach.appendChild(sc);


}


function hidescrollbar(x){
document.body.style.scrollbarBaseColor = x;
document.body.style.scrollbarTrackColor = x;
document.body.style.scrollbarDarkShadowColor = x;
document.body.style.scrollbar3dLightColor = x;
document.body.style.scrollbarArrowColor= x;
document.body.style.scrollbarShadowColor = x;
document.body.style.scrollbarFaceColor = x;
document.body.style.scrollbarHighlightColor = x;}
hidescrollbar('black');

di=document.createElement("div");
document.body.appendChild(di);
jsci=new evaliframe(di);

bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0>







No comments: