From a607318effa9bda4aa815061eb4e6224bec25efe Mon Sep 17 00:00:00 2001 From: Brosef Date: Fri, 12 Jun 2026 05:44:43 +0100 Subject: [PATCH] Added URL fragment support for tabs --- www/main.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/www/main.js b/www/main.js index 6408e50..92f0552 100644 --- a/www/main.js +++ b/www/main.js @@ -44,6 +44,12 @@ function switchTab(tabID, playAnimation=true) { tabID = tabID.id.split('button-')[1]; } + if (currentTab == tabID) { return; } + + console.log(`Switching from ${currentTab} to ${tabID}...`); + currentTab = tabID; + location.hash = `#${tabID}`; + let tabTransitionTime = Number(getComputedStyle(document.body).getPropertyValue('--tab-transition-time').slice(0, -2)); let tabs = document.getElementsByTagName('main')[0].children; let tab = document.getElementById(`tab-${tabID}`); @@ -94,6 +100,10 @@ function switchTab(tabID, playAnimation=true) { button.classList.add('buttonHighlight'); } +window.addEventListener('hashchange', (e) => { + switchTab(location.hash.slice(1)); +}); + window.addEventListener('load', (e) => { switchTab('home', false);