srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/settings.js
blob: 37e10f0f6fa68d768cffe65bd5cd564e545e5df8 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const STORAGE_KEY = 'typerpunk:settings';

function load() {
    try {
        const raw = JSON.parse(localStorage.getItem(STORAGE_KEY));
        return raw && typeof raw === 'object' ? raw : {};
    } catch {
        return {};
    }
}

let settings = {
    skipMenu: false,
    favoriteMode: null,
    wordCount: 25,
    timeDuration: 30,
    wordsPunctuation: false,
    wordsNumbers: false,
    caretBlink: true,
    hideLiveStats: false,
    blindMode: false,
    soundTheme: 'off',
    wordListTier: 'common',
    // Which vocabulary the generated-word modes draw from (see languages.js).
    language: 'en',
    ...load(),
};

function save() {
    try { localStorage.setItem(STORAGE_KEY, JSON.stringify(settings)); } catch {}
}

export function getSettings() {
    return { ...settings };
}

export function updateSettings(patch) {
    settings = { ...settings, ...patch };
    save();
}