const user = '216.73.216.34'; const server = 'butt0n.click'; const root = '~'; let cwd = root; const font = 'ANSI Shadow'; figlet.defaults({ fontPath: 'https://unpkg.com/figlet/fonts/' }); figlet.preloadFonts([font], ready); $.terminal.xml_formatter.tags.green = (attrs) => { return `[[;#44D544;]`; }; function prompt() { return `${user}@${server}:${cwd} $ `; } function rainbow(string) { return lolcat.rainbow(function(char, color) { char = $.terminal.escape_brackets(char); return `[[;${hex(color)};]${char}]`; }, string).join('\n'); } function render(text) { const cols = term.cols(); return figlet.textSync(text, { font: font, width: cols, whitespaceBreak: true }); } function hex(color) { return '#' + [color.red, color.green, color.blue].map(n => { return n.toString(16).padStart(2, '0'); }).join(''); } const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction', }); const commands = { clear () { term.clear(); term.echo(() => rainbow(render(greetings))+'\nWelcome! Get started by reading .README\nA list of commands are available with the help command.\nIf you have any suggestions or bug reports feel free to report them to butt0n@butt0n.click', { ansi: true }).resume(); }, cd(dir = '.') { term.pause() fulldir = cwd + '/' + dir; $.ajax({ url: 'https://butt0n.click/scripts/cmds.php', type: "POST", data: { cmd: 'cd', path: fulldir }, dataType: "json", success: function (data) { if(data['status'] == 0) { term.echo(data['error'], { ansi: true }).resume(); } else { cwd = data['cwd']; term.resume(); } }, error: function (error) { term.error(`Error ${error}`).resume(); } }); }, help() { term.echo(`List of available commands: ${help}`, { ansi: true }); }, cat(file = '.') { term.pause() fullfile = cwd + '/' +file; $.ajax({ url: 'https://butt0n.click/scripts/cmds.php', type: "POST", data: { cmd: 'cat', path: fullfile }, success: function (data) { term.echo(data, { ansi: true }).resume(); }, error: function (error) { term.error(`Error ${error}`).resume(); } }); }, ls(dir = '.') { term.pause() fulldir = cwd + '/' +dir; $.ajax({ url: 'https://butt0n.click/scripts/cmds.php', type: "POST", data: { cmd: 'ls', path: fulldir }, success: function (data) { term.echo(data, { ansi: true }).resume(); }, error: function (error) { term.error(`Error ${error}`).resume(); } }); } }; const command_list = Object.keys(commands); const help = formatter.format(command_list); const greetings = ` Welcome To butt0n.click ` const term = $('body').terminal(commands, { greetings: false, checkArity: false, clear: false, exit: false, completion: true, prompt }); term.pause(); function ready() { term.echo(() => rainbow(render(greetings))+'\nWelcome! Get started by reading .README\nA list of commands are available with the help command.\nIf you have any suggestions or bug reports feel free to report them to butt0n@butt0n.click', { ansi: true }).resume(); }