This commit is contained in:
traveler 2025-12-23 15:37:09 -06:00
parent fb2883c8ff
commit aeaab4780c
2 changed files with 14 additions and 27 deletions

View file

@ -1,6 +1,5 @@
/* custom.css */
/* Make background cover nicely */
body {
background-size: cover !important;
background-position: center center !important;
@ -13,7 +12,7 @@ body {
}
body.tab-pncharris {
background-image: url("pncharris-bg.png") !important;
background-image: url("/images/pncharris-bg.png") !important;
}
body.tab-netgrimoire {
@ -21,6 +20,6 @@ body {
}
body.tab-wasted-bandwidth {
background-image: url("/images/bg-wasted.jpg") !important;
background-image: url("/images/bg-wasted-bandwidth.jpg") !important;
}

View file

@ -1,38 +1,26 @@
// custom.js
(function () {
const tabClasses = [
"tab-glance",
"tab-pncharris",
"tab-netgrimoire",
"tab-wasted-bandwidth",
];
(() => {
const TAB_CLASS_PREFIX = "tab-";
const knownTabs = new Set(["glance", "pncharris", "netgrimoire", "wasted-bandwidth"]);
function normalize(s) {
return (s || "")
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/(^-|-$)/g, "");
function clearTabClasses() {
document.body.classList.forEach((c) => {
if (c.startsWith(TAB_CLASS_PREFIX)) document.body.classList.remove(c);
});
}
function applyTabClass() {
// Tabs commonly appear in the URL hash with Homepage tabs
// We'll derive the active tab from location.hash as best-effort.
const hash = (location.hash || "").replace(/^#/, "");
const slug = normalize(hash) || "glance";
// Your URLs look like: https://homepage.netgrimoire.com/#pncharris
const hash = (window.location.hash || "").replace(/^#/, "").trim().toLowerCase();
const tab = knownTabs.has(hash) ? hash : "glance";
document.body.classList.remove(...tabClasses);
if (slug.includes("pncharris")) document.body.classList.add("tab-pncharris");
else if (slug.includes("netgrimoire")) document.body.classList.add("tab-netgrimoire");
else if (slug.includes("wasted") || slug.includes("bandwidth"))
document.body.classList.add("tab-wasted-bandwidth");
else document.body.classList.add("tab-glance");
clearTabClasses();
document.body.classList.add(`${TAB_CLASS_PREFIX}${tab}`);
}
window.addEventListener("hashchange", applyTabClass);
window.addEventListener("load", applyTabClass);
// Initial run
applyTabClass();
})();