appearance.js 870 B

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