44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
function cmd_help() {
|
|
// Display 'help' message
|
|
return "Commands list:<br>" +
|
|
" -about Information about this website<br>"+
|
|
" -clear Clear terminal screen<br>" +
|
|
" -exec Execute arbitrary math and logic equations";
|
|
}
|
|
|
|
function cmd_about() {
|
|
// Display 'about' message
|
|
return "This website is based on the general idea and design of a terminal.<br>" +
|
|
"It serves the purpose of a homepage. It exists just for the fun of creating it.";
|
|
}
|
|
|
|
function cmd_clear() {
|
|
// Clear terminal by reloading page
|
|
window.location.reload();
|
|
return "";
|
|
}
|
|
|
|
function cmd_exec(input) {
|
|
// No input was given
|
|
if (input === undefined)
|
|
return "You must enter parameters!";
|
|
// Input contains letters or invalid characters
|
|
const str = input.join(' ');
|
|
if (/[',:;a-zA-Z]/.test(str) || str === "")
|
|
return "Invalid input!";
|
|
// Input is inside of character range with exceptions
|
|
const chars = str.split('').filter(e => {
|
|
const code = e.charCodeAt(0);
|
|
const s = code === 32;
|
|
const a = code > 36;
|
|
const b = code < 63;
|
|
const c = code === 94;
|
|
const d = code === 124;
|
|
return !(s || a && b || c || d);
|
|
});
|
|
// If exceptions remain, invalid input was given
|
|
if (chars.length > 0)
|
|
return "Invalid input!";
|
|
// Execute input and return output
|
|
return (new Function(`return ${str}`))();
|
|
} |