/** * Settings. */ import { assertNotNull, assertNotUndefined } from './utils/assert'; import { $, $$ } from './utils/dom'; import store from './utils/store'; export function setupSettings() { if (!$('#js-setting-table')) return; const localCheckboxes = $$('[data-tab="local"] input[type="checkbox"]'); const themeSelect = assertNotNull($('#user_theme')); const styleSheet = assertNotNull($('head link[rel="stylesheet"]')); // Local settings localCheckboxes.forEach(checkbox => { checkbox.addEventListener('change', () => { store.set(checkbox.id.replace('user_', ''), checkbox.checked); }); }); // Theme preview if (themeSelect) { themeSelect.addEventListener('change', () => { styleSheet.href = assertNotUndefined(themeSelect.options[themeSelect.selectedIndex].dataset.themePath); }); } }