-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrTerm.min.js
1 lines (1 loc) · 9.37 KB
/
rTerm.min.js
1
rTerm=function(a){return this.file=a.file,this.divid=a.div||'rterm',this.username=a.username||'user',this.hostname=a.hostname||'hostname',this.fsstart=a.fsstart||'/home/'+this.username,this.height=a.height||400,this.maxStrings=a.maxStrings||15,this.saveStrings=a.saveStrings||!1,this.loggerAppPort=a.loggerAppPort||9091,this.chartime=250,this.cdir=this.fsstart,this.uhsername=this.username+'@'+this.hostname,this.data={},this.clicked=!1,this.init=function(){$.getJSON(this.file,function(b){if(this.data=b,window.onblur=function(){window.blurred=!0},window.onfocus=function(){window.blurred=!1},'undefined'!==this.data.upstart){var d=this.callUpstart();setTimeout(function(){$(document).keydown(this.keyCallback)},d)}else $(document).keydown(this.keyCallback)}.bind(this)),$('#'+this.divid).html('<div id="term"> <span id="termcli">'+this.termPrev+'</span><span class="cursor">█</span></div>')},this.termPrev='<b>'+this.uhsername+'</b>:~$ ',this.oldInput='',this.input='',this.nStrings=0,this.callUpstart=function(){var b=0;for(cid in this.upcid=0,this.upstartInterrupted=!1,this.data.upstart)0<cid&&(b+=(this.data.upstart[cid-1].length+1)*this.chartime),setTimeout(function(){return window.blurred&&!this.upstartInterrupted?(this.callUpstartImmediately(this.data.upstart.slice(this.upcid)),void(this.upstartInterrupted=!0)):void(this.upstartInterrupted||this.enterCommand(this.data.upstart[this.upcid]),this.upcid++)},b);return b+=(this.data.upstart[this.data.upstart.length-1].length+1)*this.chartime,b},this.callUpstartImmediately=function(b){for(c of b)this.enterCommandImmediately(c)},this.enterCommand=function(b){for(lid in this.currlid=0,this.interruptCommand=!1,b)setTimeout(function(){return window.blurred&&!this.interruptCommand?(this.enterCommandImmediately(b.slice(this.currlid)),void(this.interruptCommand=!0)):void(this.interruptCommand||this.addCallback(b[this.currlid]),this.currlid++)},this.chartime*lid);setTimeout(function(){this.interruptCommand||this.enterCallback()},this.chartime*b.length)},this.enterCommandImmediately=function(b){for(l of b)this.addCallback(l);this.enterCallback()},this.updateTerm=function(){for($('#termcli').html(this.oldInput+this.termPrev+this.input);$('#term').height()>this.height;)this.delFristString(),$('#termcli').html(this.oldInput+this.termPrev+this.input)},this.delFristString=function(){var b=this.oldInput.indexOf('<br>');this.oldInput=this.oldInput.slice(b+4,-4)+'<br>',this.nStrings--},this.keyCallback=function(b){1==b.key.length?this.addCallback(b.key):8==b.which||46==b.which||110==b.which?this.delCallback():13==b.which&&this.enterCallback()}.bind(this),this.addCallback=function(b){this.input+=b,this.updateTerm()}.bind(this),this.delCallback=function(){this.input=this.input.slice(0,-1),this.updateTerm()}.bind(this),this.enterCallback=function(){if(''==this.input)this.emptyCallback();else{this.saveStrings&&this.sendString(this.input);var b=this.input.split(' ');b[0]in this.funcMap?this.funcMap[b[0]](b):this.unknownCallback()}}.bind(this),this.emptyCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>',this.nStrings++,this.updateTerm()}.bind(this),this.unknownCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>'+this.input+': command not found<br>',this.input='',this.nStrings+=2,this.updateTerm()}.bind(this),this.sendString=function(b){$.ajax({url:'https://'+window.location.hostname+':'+this.loggerAppPort+'?'+b,dataType:'jsonp'})}.bind(this),this.getByPath=function(b){var d='';d=b.startsWith('/')?b:b.startsWith('~')?this.fsstart+'/'+b.slice(1):this.cdir+'/'+b,d.endsWith('/')&&(d=d.slice(0,-1));var e=d.split('/').slice(1),f=[];for(i in e)if('..'==e[i]){if(0<f.length)f.splice(-1,1);else continue;}else if('.'==e[i])continue;else f.push(e[i]);d='/'+f.join('/');var g=this.data.fs;for(folder of f)g=g[folder];return[g,d]}.bind(this),this.lsCallback=function(b){this.oldInput+=this.termPrev+this.input+'<br>',this.nStrings++;var d=!1,e=!1,f=this.cdir;for(arg of b.slice(1))arg.startsWith('-')?'-a'==arg?d=!0:'-l'==arg&&(e=!0):f=arg.startsWith('/')?arg:f+'/'+arg;var g=this.getByPath(f)[0];if('undefined'==typeof g)this.oldInput+='ls: cannot access \''+f+'\': No such file or directory<br>',this.nStrings++;else for(item in g)(!item.startsWith('.')||d)&&(this.oldInput+='string'==typeof g[item]?g[item].startsWith('_link:')?'<a class="link" href="'+g[item].slice(6)+'" target="_blank">'+item+'</a><br>':item+'<br>':'<font color="#729FCF">'+item+'</font><br>',this.nStrings++);this.input='',this.updateTerm()}.bind(this),this.catCallback=function(b){var d=this.getByPath(b[1])[0];if(''==d||'undefined'==typeof d)this.oldInput+=this.termPrev+this.input+'<br>'+this.input+': No such file or directory<br>';else if(d.startsWith('_call:')){var b=d.slice(6).split(' ');if(b[0]in this.funcMap)return void this.funcMap[b[0]](b);this.oldInput+=this.termPrev+this.input+'<br>'+d+'<br>'}else this.oldInput+=this.termPrev+this.input+'<br>'+d+'<br>';this.input='',this.nStrings+=2,this.updateTerm()}.bind(this),this.cdCallback=function(b){var d='';d=2>b.length||' '==b[1]?'~':b[1];var[e,f]=this.getByPath(d);if('undefined'==typeof e)this.oldInput+=this.termPrev+this.input+'<br>'+this.input+': No such file or directory<br>',this.input='',this.nStrings+=2;else if('string'==typeof e)e.startsWith('_link:')?(this.oldInput+=this.termPrev+this.input+'<br>',this.input='',this.nStrings++,window.open(e.slice(6),'_blank').focus()):(this.oldInput+=this.termPrev+this.input+'<br>'+this.input+': Not a directory<br>',this.input='',this.nStrings+=2);else if('object'==typeof e){this.cdir=f,this.oldInput+=this.termPrev+this.input+'<br>',this.input='',this.nStrings++;var g=this.cdir;g==this.fsstart&&(g='~'),this.termPrev='<b>'+this.uhsername+'</b>:'+g+'$ '}this.updateTerm()}.bind(this),this.pwdCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>'+this.cdir+'<br>',this.input='',this.nStrings+=2,this.updateTerm()}.bind(this),this.whoamiCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>',this.nStrings++;for(item of this.data.whoami)this.oldInput+=item+'<br>',this.nStrings++;this.input='',this.updateTerm()}.bind(this),this.unameCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>'+this.data.uname+'<br>',this.input='',this.nStrings+=2,this.updateTerm()}.bind(this),this.randomCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>'+(Math.random()+'<br>'),this.input='',this.nStrings+=2,this.updateTerm()}.bind(this),this.idkCallback=function(){for(item in this.oldInput+=this.termPrev+this.input+'<br>',this.nStrings++,this.funcMap)this.oldInput+=item+'<br>',this.nStrings++;this.input='',this.updateTerm()}.bind(this),this.exitCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>',this.nStrings++,$(document).unbind('keydown',this.keyCallback),this.input='',this.updateTerm()}.bind(this),this.echoCallback=function(){var b=this.input.slice(5);this.oldInput+=this.termPrev+this.input+'<br>'+b+'<br>',this.nStrings+=2,this.input='',this.updateTerm()}.bind(this),this.hiCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>hiii!<br>',this.nStrings+=2,this.input='',this.updateTerm()}.bind(this),this.manCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>What manual page do you want?<br>',this.nStrings+=2,this.input='',this.updateTerm()}.bind(this),this.ohYouCallback=function(){this.oldInput+=this.termPrev+this.input+'<br>oh you!<br>',this.nStrings+=2,$(document).unbind('keydown',this.keyCallback),this.input='',this.updateTerm()}.bind(this),this.poweroffCallback=function(){$(document).unbind('keydown',this.keyCallback),this.termPrev='',this.oldInput='',this.input='',this.nStrings=0,this.updateTerm()}.bind(this),this.rebootCallback=function(){$(document).unbind('keydown',this.keyCallback),setTimeout(function(){this.oldInput='',this.input='',this.nStrings=0,this.updateTerm(),$(document).keydown(this.keyCallback)},1e3)}.bind(this),this.sudoCallback=function(b){b[0]in this.funcMap?this.funcMap[b[0]](b.slice(1)):this.unknownCallback()}.bind(this),this.aptCallback=function(b){1==b.length?(this.oldInput+=this.termPrev+this.input+'<br>apt 1.2.34 (amd64)<br>Usage: apt [options] command<br>This APT has Super Cow Powers.<br>',this.nStrings+=4):'update'==b[1]?(this.oldInput+=this.termPrev+this.input+'<br>Reading package lists... Done<br>E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)<br>E: Unable to lock directory /var/lib/apt/lists/<br>',this.nStrings+=4):'upgrade'==b[1]?(this.oldInput+=this.termPrev+this.input+'<br>E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)<br>E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?<br>',this.nStrings+=3):'install'==b[1]?(this.oldInput+=this.termPrev+this.input+'<br>Reading package lists... Done<br>Building dependency tree<br>Reading state information... Done<br>E: Unable to locate package '+b[2]+'<br>',this.nStrings+=5):(this.oldInput+=this.termPrev+this.input+'<br>E: Invalid operation '+b[1]+'<br>',this.nStrings+=2),this.input='',this.updateTerm()}.bind(this),this.funcMap={ls:this.lsCallback,cd:this.cdCallback,cat:this.catCallback,whoami:this.whoamiCallback,uname:this.unameCallback,idk:this.idkCallback,help:this.idkCallback,random:this.randomCallback,pwd:this.pwdCallback,exit:this.exitCallback,echo:this.echoCallback,hi:this.hiCallback,man:this.manCallback,ohyou:this.ohYouCallback,fuck:this.ohYouCallback,poweroff:this.poweroffCallback,reboot:this.rebootCallback,sudo:this.sudoCallback,apt:this.aptCallback,'apt-get':this.aptCallback},this.init(),this};