axios.defaults.withCredentials = true; let appearance = {}; appearance.sheetElement = null; appearance.prepare = () => { appearance.sheetElement = document.getElementById('appearance-sheet'); let lightbulb = document.getElementById('appearance-switch'); lightbulb.addEventListener('click', appearance.toggleLightMode); }; appearance.toggleLightMode = (e) => { e.preventDefault(); axios.post('/api/appearance/toggle').then(res => { let newStyle = res.data.currentStyle; appearance.sheetElement.setAttribute("href", `/css/style_${newStyle}.css`); appearance.currentStyle = newStyle; }); }; window.addEventListener('load', () => { appearance.prepare(); });