appearance.js 711 B

12345678910111213141516171819202122232425
  1. axios.defaults.withCredentials = true;
  2. let appearance = {};
  3. appearance.sheetElement = null;
  4. appearance.prepare = () => {
  5. appearance.sheetElement = document.getElementById('appearance-sheet');
  6. let lightbulb = document.getElementById('appearance-switch');
  7. lightbulb.addEventListener('click', appearance.toggleLightMode);
  8. };
  9. appearance.toggleLightMode = (e) => {
  10. e.preventDefault();
  11. axios.post('/api/appearance/toggle').then(res => {
  12. let newStyle = res.data.currentStyle;
  13. appearance.sheetElement.setAttribute("href", `/css/style_${newStyle}.css`);
  14. appearance.currentStyle = newStyle;
  15. });
  16. };
  17. window.addEventListener('load', () => {
  18. appearance.prepare();
  19. });