var util = util || {}; var infinateLoopDetect; var i = 0; var f = 0; var moduleTypeFlag = 0; var cmdString = ""; var modules = []; var moduleCode = []; var modInstall; var firstLine = ""; util.toArray = function(list) { return Array.prototype.slice.call(list || [], 0); }; function show_image(src, width, height, alt) { var img = document.createElement("img"); img.src = src; img.width = width; img.height = height; img.alt = alt; // This next line will just add it to the
tag document.body.appendChild(img); } var Terminal = Terminal || function(cmdLineContainer, outputContainer) { window.URL = window.URL || window.webkitURL; window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; var cmdLine_ = document.querySelector(cmdLineContainer); var output_ = document.querySelector(outputContainer); cmds = [ 'cat', 'clear', 'clock', 'date', 'echo', 'help', 'uname', 'cmd_fm', 'procman', 'insmod', 'rmmod', 'swaptheme', 'cowsay' ]; var fs_ = null; var cwd_ = null; var history_ = []; var histpos_ = 0; var histtemp_ = 0; window.addEventListener('click', function(e) { cmdLine_.focus(); }, false); cmdLine_.addEventListener('click', inputTextClick_, false); cmdLine_.addEventListener('keydown', historyHandler_, false); cmdLine_.addEventListener('keydown', processNewCommand_, false); // function inputTextClick_(e) { this.value = this.value; } // function historyHandler_(e) { if (history_.length) { if (e.keyCode == 38 || e.keyCode == 40) { if (history_[histpos_]) { history_[histpos_] = this.value; } else { histtemp_ = this.value; } } if (e.keyCode == 38) { // up histpos_--; if (histpos_ < 0) { histpos_ = 0; } } else if (e.keyCode == 40) { // down histpos_++; if (histpos_ > history_.length) { histpos_ = history_.length; } } if (e.keyCode == 38 || e.keyCode == 40) { this.value = history_[histpos_] ? history_[histpos_] : histtemp_; this.value = this.value; // Sets cursor to end of input. } } } // function processNewCommand_(e) { if (e.keyCode == 9) { // tab e.preventDefault(); // Implement tab suggest. } else if (e.keyCode == 13) { // enter // Save shell history. if (this.value) { history_[history_.length] = this.value; histpos_ = history_.length; } // Duplicate current input and append to output section. var line = this.parentNode.parentNode.cloneNode(true); line.removeAttribute('id') line.classList.add('line'); var input = line.querySelector('input.cmdline'); input.autofocus = false; input.readOnly = true; output_.appendChild(line); if (this.value && this.value.trim()) { /*var args = this.value.split(' ').filter(function(val, i) { return val; });*/ var args = [].concat.apply([], this.value.split('"').map(function(v,i){ return i%2 ? v : v.split(' ') })).filter(Boolean); var cmd = args[0].toLowerCase(); args = args.splice(1); // Remove cmd from arg list. } //infinateLoopDetect = setTimeout(function(){ alert("Infinate Loop!"); }, 10000); switch (cmd) { case 'cat': var url = args.join(' '); if (!url) { output('Usage: ' + cmd + ' https://s.codepen.io/...'); output('Example: ' + cmd + ' https://s.codepen.io/AndrewBarfield/pen/LEbPJx.js'); break; } $.get( url, function(data) { var encodedStr = data.replace(/[\u00A0-\u9999<>\&]/gim, function(i) { return ''+i.charCodeAt(0)+';'; }); output('' + encodedStr + ''); }); break; case 'clear': output_.innerHTML = ''; this.value = ''; return; case 'clock': var appendDiv = jQuery($('.clock-container')[0].outerHTML); appendDiv.attr('style', 'display:inline-block'); output_.appendChild(appendDiv[0]); break; case 'date': output( new Date() ); break; case 'echo': output( args.join(' ') ); break; case 'help': if (!arguments || (args[0] != "modules")) { cmdString = ""; output('DremJS Terminal Help Menu'); output('All default commands (without modules) for the terminal are as follows:'); for (i = 0; i < cmds.length; i++) cmdString += cmds[i] + " "; output(cmdString); cmdString = ""; output('Module commands:'); for (i = 0; i < modules.length; i++) cmdString += modules[i] + " "; output(cmdString); cmdString = ""; output('For information on Modules, run "help modules"'); } else if (args[0] == "modules") { output('DremJS Terminal Help Menu - Modules'); output('What are Modules?'); output('Modules are a simple way to temporarily add new functionality to DremJS. Modules have a .djsm (DremJS Module) file extension and contain JavaScript code which can be ran immediately or from a terminal. DremJS Modules can also be installed in batch with a .djsms (DremJS Module Script). These scripts will automatically handle installations of modules that may be too complex to fit into one file and therefor have multiple modules.\n\n'); output('Currently, there are three different types of modules: immediate, terminal, and parentscript. An immediate module does exactly what it says: run the code immediately. A terminal module adds functionality to the terminal, such as a new command. However, terminal modules are not persistent after you close the terminal (yet). A parentscript module adds functionality to the main Agenda WM script.\n\n'); output('The pros and cons of modules'); output('The pros of modules is that you can add new functionality to DremJS or the terminal without having to install an application.'); output('The cons of a module is that, since it adds or runs code on-the-fly to DremJS, they are very insecure. A man-in-the-middle attack or other naughty module can cause your data to be stolen (please never use DremJS with any personal data), DremJS to become unstable, or completely crash. This is why we made it so modules are not permanently installed. If you want code that stays put, it is recommended to use an application.'); } break; case 'uname': output(navigator.appVersion); break; /*case 'whoami': var result = "
' + html + '
'); } function sleep(delay) { var start = new Date().getTime(); while (new Date().getTime() < start + delay); } // Cyclefucker 1000 function fileToVar(t) { modInstall = t; alert(modInstall); } // Cross-browser impl to get document's height. function getDocHeight_() { var d = document; return Math.max( Math.max(d.body.scrollHeight, d.documentElement.scrollHeight), Math.max(d.body.offsetHeight, d.documentElement.offsetHeight), Math.max(d.body.clientHeight, d.documentElement.clientHeight) ); } // return { init: function() { jQuery.get('terminal/configs/theme.conf', function(data) { if(data == "1") { output('' + new Date() + '
Enter "help" for more information.
'); } else { output('' + new Date() + '
Enter "help" for more information.
'); } }); }, output: output } };