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);