import { SETTINGS_KEY, DEFAULT_SETTINGS } from "../constants"; import { cloneObject, removeTags } from "../helpers"; import { usePhondueDigraphs } from "./KeyboardFire/phondue/ipaField"; import { renderWords } from "./render/words"; import { addMessage, hasToken, objectValuesAreDifferent } from "./utilities"; import { enableHotKeys, disableHotKeys } from "./hotkeys"; import { showTemplateEditor, renderTemplateSelectOptions, showSelectedTemplate } from "./render/settings"; export function loadSettings() { const storedSettings = window.localStorage.getItem(SETTINGS_KEY); window.settings = storedSettings ? JSON.parse(storedSettings) : cloneObject(DEFAULT_SETTINGS); toggleIPAPronunciationFields(false); toggleShowAdvancedFields(); } export function saveSettings() { window.localStorage.setItem(SETTINGS_KEY, JSON.stringify(window.settings)); addMessage('Settings Saved!'); } export function openSettingsModal() { const { useIPAPronunciationField, useHotkeys, showAdvanced, defaultTheme, templates } = window.settings; document.getElementById('settingsUseIPA').checked = useIPAPronunciationField; document.getElementById('settingsUseHotkeys').checked = useHotkeys; document.getElementById('settingsShowAdvanced').checked = showAdvanced; document.getElementById('settingsDefaultTheme').value = defaultTheme; renderTemplateSelectOptions(); showTemplateEditor(false); document.getElementById('settingsModal').style.display = ''; } export function updateTemplateSelects() { const { templates } = window.settings; if (typeof templates !== 'undefined') { const templatesOptionsHTML = templates.map((template, index) => { return `