maotube/public/header.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-01-19 02:59:53 +00:00
function displayHeader() {
const links = [
{
href: "/",
name: "Home",
2024-02-10 20:39:54 +00:00
accessKey: "h",
2024-01-19 02:59:53 +00:00
},
{
href: "/register/",
name: "Register",
2024-02-10 20:39:54 +00:00
accessKey: "r",
2024-01-19 02:59:53 +00:00
},
{
href: "/login/",
name: "Login",
2024-02-10 20:39:54 +00:00
accessKey: "l",
2024-01-19 02:59:53 +00:00
},
{
href: "/upload/",
name: "Upload",
2024-02-10 20:39:54 +00:00
accessKey: "u",
2024-01-19 02:59:53 +00:00
},
2024-02-10 20:39:54 +00:00
].map(({name, href, accessKey}) => {
2024-01-19 02:59:53 +00:00
if (href === window.location.pathname) {
2024-02-10 20:39:54 +00:00
return `<a href="${href}" accesskey="${accessKey}"><b>${name}</b></a>`
2024-01-19 02:59:53 +00:00
} else {
2024-02-10 20:39:54 +00:00
return `<a href="${href}" accesskey="${accessKey}">${name}</a>`
2024-01-19 02:59:53 +00:00
}
}).join(" - ");
document.querySelector("h1").outerHTML = `
<header>
2024-01-19 20:56:47 +00:00
<a href="/">
<h1 id="app-name">MaoTube</h1>
</a>
<nav>
${links}
</nav>
<form method="GET" target="_self" action="/search">
<input type="text" id="search" name="query" placeholder="Search">
<input type="submit" value="Search">
</form>
2024-01-19 02:59:53 +00:00
</header>
`
}
displayHeader();