summaryrefslogtreecommitdiff
path: root/public/static/scripts/options.js
blob: e460f292515c9f427dc4c4f3da3cac69ce03a711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
let options = JSON.parse(localStorage.getItem('options') ?? '{}');

document.querySelectorAll('input[type=checkbox]').forEach((c) => {
    const id = c.getAttribute('name');

    c.addEventListener('change', () => {
        options[id] = c.checked;
        localStorage.setItem('options', JSON.stringify(options));
    });

    if (options[id] !== undefined) {
        c.checked = options[id];
    }
});

document.querySelectorAll('select').forEach((c) => {
    const id = c.getAttribute('name');

    c.addEventListener('change', () => {
        options[id] = c.value;
        localStorage.setItem('options', JSON.stringify(options));
    });

    if (options[id] !== undefined) {
        c.value = options[id];
    }
});