pgsh.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. function pgsh() {
  2. this.prompt = '<span style="color:purple">pgs </span><span style="color:green">$ </span>'
  3. this.welcome = ''
  4. this.responses = {
  5. 'about': function() {
  6. return 'This website belongs to Weiyi Lou ' + new Date().getFullYear()
  7. },
  8. 'version': function() {
  9. return 'Parsley Gardens Shell (pgsh) 1.0.0'
  10. },
  11. 'git': function() {
  12. return 'Self-Hosted Code repository at <a target="_blank" href="https://code.parsleygardens.net">code.parsleygardens.net</a>'
  13. },
  14. 'hello': function() {
  15. return 'Hello to you too'
  16. },
  17. 'magic': function() {
  18. return 'Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
  19. },
  20. 'su': function() {
  21. var output = ''
  22. if (!this.Parent.su) {
  23. this.Parent.oldprompt = this.Parent.prompt
  24. this.Parent.prompt = '<span style="color:purple">root </span><span style="color:red">% </span>'
  25. this.Parent.su = true
  26. output = 'With Great Power comes Great'
  27. }
  28. return output
  29. },
  30. 'exit': function() {
  31. var output = 'Close browser window to exit'
  32. if (this.Parent.su) {
  33. this.Parent.prompt = this.Parent.oldprompt
  34. this.Parent.su = false
  35. output = ''
  36. }
  37. return output
  38. },
  39. 'help': function() {
  40. var functions = [];
  41. for(var name in this.Parent.responses) {
  42. if (name !== 'Parent') {
  43. functions.push(name);
  44. }
  45. }
  46. functions.sort();
  47. return 'Available commands:\n' + functions.join(' ')
  48. }
  49. }
  50. this.process = function(input) {
  51. var output = ''
  52. if (input in this.responses) {
  53. this.responses.Parent = this
  54. output += this.responses[input]()
  55. }
  56. return output
  57. }
  58. }
  59. var pgsh = new pgsh()