import apiConnector from "./connector.js" export default async function initSettings(settingsPageContainer) { const inputList = Array.from(settingsPageContainer.querySelectorAll("[name]")) const inputs = Object.fromEntries(inputList.map(e => [e.name, e])) const currentConfig = await apiConnector.fetchConfig() for (const [name, value] of Object.entries(currentConfig)) if (inputs[name]) inputs[name].value = value settingsPageContainer.querySelector("#settings-submit").addEventListener("click", e => { e.preventDefault() apiConnector.updateConfig(Object.fromEntries(inputList.map(el => [el.name, el.type === "number" ? parseFloat(el.value) : el.value]))) }) }