diff --git a/js/terminal.js b/js/terminal.js index 7f19442..de3037e 100755 --- a/js/terminal.js +++ b/js/terminal.js @@ -8,7 +8,7 @@ $(function() { if (did == null) { did = "did:plc:4hqjfn7m6n5hno3doamuhgef" }; if (user) { prompt = "[[b;#87cefa;]" + user + "][[b;#FFFF00;]@aios] ~$ " }; var tab = "[[b;#87cefa;]]"; - var command_all = ["ai","timeline", "bsky_ver", "handle", "did", "plc"]; + var command_all = ["ai", "timeline", "bsky_ver", "handle", "did", "plc"]; var handle = "yui.syui.ai"; var ascii_logo = '\n\ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠉⠀⠀⠀⠀⠀⠈⠉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀\⠀ \n⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣦⣤⣤⣤⣤⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀\⠀ \n⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀\⠀ \n⠀⠀⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆\⠀ \n⠀⠀⠘⠛⠛⠛⠛⠉⠉⠉⠉⠁⠀⠀⠀⠀⠈⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⠀⠀⠀⠀⠀⠉⠉⠉⠉⠙⠛⠛⠛⠛\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠛⠿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀ \n\n'; @@ -60,32 +60,36 @@ $(function() { "; let list = 'https://bsky.social/xrpc/com.atproto.repo.listRecords?repo='; - axios.get(list + handle + '&collection=app.bsky.feed.post&limit=1') + axios.get(list + did + '&collection=app.bsky.feed.post&limit=1') .then(function (response) { timeline = JSON.stringify(response.data.records[0].value,null,"\t"); - }) + }) axios.get('https://bsky.social/xrpc/_health') - .then(function (response) { + .then(function (response) { bsky_ver = JSON.stringify(response.data,null,"\t"); - }) + }) let plc_server = "https://plc.directory/" axios.get(plc_server + did + '/log') - .then(function (response) { + .then(function (response) { plc = JSON.stringify(response.data,null,"\t"); - }) + }) let desc = 'https://bsky.social/xrpc/com.atproto.repo.describeRepo?repo='; axios.get(desc + did + '&collection=app.bsky.actor.profile') - .then(function (response) { - bsky_did = JSON.stringify(response.data,null,"\t"); - }) - - axios.get('/json/ai.json') .then(function (response) { - user_profile = JSON.stringify(response.data,null,"\t"); - }) + bsky_did = JSON.stringify(response.data,null,"\t"); + }) + + function test_json() { + var u; + u = axios.get('/json/ai.json') + .then(function (response) { + return JSON.stringify(response.data,null,"\t"); + }) + return u; + } function print_slowly(term, paragraph, callback) { var foo, i, lines; @@ -123,96 +127,95 @@ $(function() { command = inputs[0]; if (inputs[0] === 'ai') { print_slowly(term, ascii_logo); - term.echo(user_profile); - + term.echo(test_json()); } else if (inputs[0] === 'plc' && inputs[1] != undefined) { - url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; - $.ajaxSetup({async: false}); - $.getJSON(url, function(data) { + url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; + $.ajaxSetup({async: false}); + $.getJSON(url, function(data) { did = JSON.stringify(data.did,null,"\t").replaceAll('"', '') url = plc_server + did + '/log'; - $.ajaxSetup({async: false}); + $.ajaxSetup({async: false}); $.getJSON(url, function(data) { - term.echo(JSON.stringify(data,null,"\t")); - });$.ajaxSetup({async: true}); + term.echo(JSON.stringify(data,null,"\t")); });$.ajaxSetup({async: true}); + });$.ajaxSetup({async: true}); } else if (inputs[0] === 'plc') { - term.echo(plc); - term.echo("$ plc "); + term.echo(plc); + term.echo("$ plc "); } else if (inputs[0] === 'timeline' && inputs[1] != undefined) { - url = list + inputs[1] + '&collection=app.bsky.feed.post&limit=1'; - $.ajaxSetup({async: false}); - $.getJSON(url, function(data) { + url = list + inputs[1] + '&collection=app.bsky.feed.post&limit=1'; + $.ajaxSetup({async: false}); + $.getJSON(url, function(data) { term.echo(JSON.stringify(data,null,"\t")); - });$.ajaxSetup({async: true}); + });$.ajaxSetup({async: true}); } else if (inputs[0] === 'timeline') { - term.echo(timeline); - term.echo("$ timeline "); + term.echo(timeline); + term.echo("$ timeline "); } else if (inputs[0] === 'did' && inputs[1] != undefined) { - url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; - $.ajaxSetup({async: false}); - $.getJSON(url, function(data) { + url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; + $.ajaxSetup({async: false}); + $.getJSON(url, function(data) { term.echo(JSON.stringify(data.did,null,"\t")); - });$.ajaxSetup({async: true}); + });$.ajaxSetup({async: true}); } else if (inputs[0] === 'did') { - url = desc + did + '&collection=app.bsky.actor.profile'; - $.ajaxSetup({async: false}); - $.getJSON(url, function(data) { + url = desc + did + '&collection=app.bsky.actor.profile'; + $.ajaxSetup({async: false}); + $.getJSON(url, function(data) { term.echo(JSON.stringify(data.did,null,"\t")); - });$.ajaxSetup({async: true}); - term.echo("$ did "); + });$.ajaxSetup({async: true}); + term.echo("$ did "); } else if (inputs[0] === 'handle' && inputs[1] != undefined) { - url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; - $.ajaxSetup({async: false}); - $.getJSON(url, function(data) { + url = desc + inputs[1] + '&collection=app.bsky.actor.profile'; + $.ajaxSetup({async: false}); + $.getJSON(url, function(data) { term.echo(JSON.stringify(data,null,"\t")); - });$.ajaxSetup({async: true}); + });$.ajaxSetup({async: true}); } else if (inputs[0] === 'handle') { - term.echo(bsky_did); - term.echo("$ handle "); + term.echo(bsky_did); + term.echo("$ handle "); } else if (inputs[0] === 'bsky_ver') { - term.echo(bsky_ver); + term.echo(bsky_ver); } else { term.error(command + " is not a valid command"); term.echo(command_all); } } -function bash(inputs, term) { - var argument, echo, insert; - echo = term.echo; - insert = term.insert; - if (!inputs[1]) { - //return console.log("none"); - } else { - argument = inputs[1]; - if (/^\.\./.test(argument)) { - return echo("-bash: cd: " + argument + ": Permission denied"); + function bash(inputs, term) { + var argument, echo, insert; + echo = term.echo; + insert = term.insert; + if (!inputs[1]) { + //return console.log("none"); } else { - return echo("-bash: cd: " + argument + ": No such file or directory"); + argument = inputs[1]; + if (/^\.\./.test(argument)) { + return echo("-bash: cd: " + argument + ": Permission denied"); + } else { + return echo("-bash: cd: " + argument + ": No such file or directory"); + } } } -} -$('#terminal').terminal(interpreter, { - prompt: prompt, - name: 'test', - greetings: "", - exit: false, - height: 450, - onInit: function(term) { - //term.insert("ai"); - //print_slowly(term, ascii_ai); - }, - completion: function(term, string, callback) { - var t = $(term[0]).text(); - if (t.match(/none/)) { - term.clear(); - } else { - callback(command_all); - term.history().clear(); - } - }, - tabcompletion: true -}); + $('#terminal').terminal(interpreter, { + prompt: prompt, + name: 'test', + greetings: "", + exit: false, + height: 450, + onInit: function(term) { + //term.insert("ai"); + //print_slowly(term, ascii_ai); + }, + completion: function(term, string, callback) { + var t = $(term[0]).text(); + if (t.match(/none/)) { + term.clear(); + } else { + callback(command_all); + term.history().clear(); + } + }, + tabcompletion: true + }); });