about summary refs log tree commit diff stats
path: root/src/pages/options/index.js
blob: 39f9c8f38a7b3a275f5da5da0fec7a76abf24ca6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
for (const a of document.getElementById('links').getElementsByTagName('a')) {
    a.addEventListener('click', e => {
        const path = a.getAttribute('href').replace('#', '');
        loadPage(path);
        e.preventDefault();
    })
}

function loadPage(path) {
    for (const section of document.getElementById('pages').getElementsByTagName('section'))
        section.style.display = 'none';
    document.getElementById(`${path}_page`).style.display = 'block';

    for (const a of document.getElementById('links').getElementsByTagName('a'))
        if (a.getAttribute('href') == `#${path}`) a.classList.add('selected')
        else a.classList.remove('selected')

    let stateObj = { id: "100" };
    window.history.pushState(stateObj, "Page 2", `/pages/options/index.html#${path}`);
}

const r = window.location.href.match(/#(.*)/)
if (r) loadPage(r[1]);
else loadPage('general');