Skip to content

Commit 2034968

Browse files
committed
chang erepo link and fix tab issues, and add hash linking
1 parent 948756c commit 2034968

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ <h2>PAGNAI: Procedural Audio Generation, Not Artificial Intelligence</h2>
349349

350350
<footer class="site-footer">
351351
<div class="footer-content">
352-
<a href="https://github.com/Aspenini/JS-Media-Tool" target="_blank" rel="noopener noreferrer" class="github-link">
352+
<a href="https://github.com/Aspenini/Media-Tool" target="_blank" rel="noopener noreferrer" class="github-link">
353353
<img src="/img/github.png" alt="GitHub" class="github-icon">
354354
<span>View on GitHub</span>
355355
</a>

src/ui/tabs.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import { showNotification } from './notification.js';
22

3+
const HASH_TO_TAB: Record<string, string> = {
4+
scaler: 'scalerTab',
5+
slicer: 'slicerTab',
6+
audio: 'audioTab',
7+
palette: 'paletteTab',
8+
csv: 'csvTab',
9+
qrcode: 'qrcodeTab',
10+
brainfuck: 'brainfuckTab',
11+
pagnai: 'pagnaiTab',
12+
};
13+
14+
function tabIdToHash(tabId: string): string {
15+
const entry = Object.entries(HASH_TO_TAB).find(([, id]) => id === tabId);
16+
return entry ? entry[0] : '';
17+
}
18+
319
export function openTab(tabId: string): void {
420
try {
521
const allTabs = document.querySelectorAll<HTMLElement>('.tabcontent');
@@ -13,15 +29,16 @@ export function openTab(tabId: string): void {
1329
const allButtons = document.querySelectorAll('.tab-button');
1430
allButtons.forEach((btn) => btn.classList.remove('active'));
1531

16-
const targetButton = document.querySelector(`[data-tab="${tabId}"]`);
17-
if (targetButton) {
18-
targetButton.classList.add('active');
19-
}
32+
document.querySelectorAll(`[data-tab="${tabId}"]`).forEach((btn) => btn.classList.add('active'));
2033

2134
const selectedTab = document.getElementById(tabId);
2235
if (selectedTab) {
2336
selectedTab.style.display = 'block';
2437
selectedTab.classList.add('active');
38+
const hash = tabIdToHash(tabId);
39+
if (hash) {
40+
history.replaceState(null, '', `#${hash}`);
41+
}
2542
} else {
2643
console.error(`Tab with id "${tabId}" not found`);
2744
showNotification('Tab not found', 'error');
@@ -36,14 +53,20 @@ export function selectMobileTab(tabId: string): void {
3653
openTab(tabId);
3754
const mobileMenu = document.getElementById('mobileMenu');
3855
if (mobileMenu) mobileMenu.style.display = 'none';
39-
const button = document.querySelector(`[data-tab="${tabId}"]`);
40-
if (button) {
41-
document.querySelectorAll('.tab-button').forEach((btn) => btn.classList.remove('active'));
42-
button.classList.add('active');
43-
}
4456
}
4557

4658
export function initTabs(): void {
59+
function openFromHash(): void {
60+
const hash = window.location.hash.slice(1).toLowerCase();
61+
const tabId = hash ? HASH_TO_TAB[hash] : null;
62+
if (tabId) {
63+
openTab(tabId);
64+
}
65+
}
66+
67+
openFromHash();
68+
window.addEventListener('hashchange', openFromHash);
69+
4770
document.querySelectorAll<HTMLElement>('#tabs .tab-button[data-tab]').forEach((btn) => {
4871
const tabId = btn.dataset.tab;
4972
if (tabId) {

0 commit comments

Comments
 (0)