ari.lt/content/js/commands/index.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-07-02 04:03:52 +03:00
function reload(cmd) {
document.location.reload();
return "ReLoad: reloading the page"
}
function goto(cmd) {
cmd = cmd.split(' ');
try {
var loc = pages[cmd[1].toLocaleLowerCase()];
} catch (e) {
return "GOTO: cannot pass an empty location";
}
if (loc) {
document.location.assign(loc);
2021-07-03 23:25:21 +03:00
return `GOTO: redirecting to ${loc}`;
2021-07-02 04:03:52 +03:00
} else {
return `GOTO: ${cmd[1]} does not exist`;
}
}
2021-07-03 23:25:21 +03:00
function exit(cmd) {
2021-07-02 04:03:52 +03:00
let textbox = document.getElementById("mobileCmd");
2021-07-03 23:25:21 +03:00
textbox.blur();
2021-07-02 04:03:52 +03:00
textbox.value = '';
mobileMenu.classList.add("hiddenMobile");
}
function help(cmd) {
return `help - display help
goto [PAGE] - go to a specified page
reload - reload the page
exit - exit`
}
const pages = {
"random_things": "/page/random",
"javascript_apps": "/page/js",
2021-07-03 23:25:21 +03:00
"source_code": "/page/redirect?url=https://github.com/TruncatedDinosour/website",
"help": "/help",
2021-07-02 04:03:52 +03:00
"home": "/"
}
const commands = {
"help": help,
"goto": goto,
"reload": reload,
"exit": exit
}