From aeaab4780c4ddc5e5b7d0a88ef2cb439b380f8b5 Mon Sep 17 00:00:00 2001 From: traveler Date: Tue, 23 Dec 2025 15:37:09 -0600 Subject: [PATCH] sd --- custom.css | 5 ++--- custom.js | 36 ++++++++++++------------------------ 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/custom.css b/custom.css index 933aa18..501f92a 100755 --- a/custom.css +++ b/custom.css @@ -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; } \ No newline at end of file diff --git a/custom.js b/custom.js index 6364936..986f5dd 100755 --- a/custom.js +++ b/custom.js @@ -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(); })(); \ No newline at end of file