67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
const localTime = document.querySelector("#localTime");
|
|
const activeCommand = document.querySelector("#activeCommand");
|
|
const commandForm = document.querySelector("#commandForm");
|
|
const commandInput = document.querySelector("#commandInput");
|
|
const tabs = Array.from(document.querySelectorAll(".command-tab"));
|
|
const pages = Array.from(document.querySelectorAll(".terminal-page"));
|
|
|
|
const pageAliases = {
|
|
about: "home",
|
|
profile: "home",
|
|
experience: "work",
|
|
jobs: "work",
|
|
tech: "stack",
|
|
skills: "stack",
|
|
project: "projects",
|
|
social: "contact",
|
|
email: "contact",
|
|
};
|
|
|
|
function updateTime() {
|
|
if (!localTime) return;
|
|
|
|
localTime.textContent = new Intl.DateTimeFormat("en-GB", {
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
second: "2-digit",
|
|
}).format(new Date());
|
|
}
|
|
|
|
function setPage(pageName) {
|
|
const page = pageAliases[pageName] || pageName;
|
|
const nextPage = document.querySelector(`#page-${page}`);
|
|
|
|
if (!nextPage) {
|
|
activeCommand.textContent = `unknown command: ${pageName}`;
|
|
return;
|
|
}
|
|
|
|
tabs.forEach((tab) => {
|
|
tab.classList.toggle("active", tab.dataset.page === page);
|
|
});
|
|
|
|
pages.forEach((currentPage) => {
|
|
currentPage.classList.toggle("active", currentPage.id === `page-${page}`);
|
|
});
|
|
|
|
activeCommand.textContent = `open ${page}`;
|
|
}
|
|
|
|
tabs.forEach((tab) => {
|
|
tab.addEventListener("click", () => setPage(tab.dataset.page));
|
|
});
|
|
|
|
commandForm?.addEventListener("submit", (event) => {
|
|
event.preventDefault();
|
|
const command = commandInput.value.trim().toLowerCase();
|
|
|
|
if (command) {
|
|
setPage(command);
|
|
}
|
|
|
|
commandInput.value = "";
|
|
});
|
|
|
|
updateTime();
|
|
window.setInterval(updateTime, 1000);
|