From 98afdc4673f616bc61f9ef673580ca3933bdef8a Mon Sep 17 00:00:00 2001 From: Bobby Date: Mon, 7 Jul 2025 15:18:49 +0530 Subject: refactor to y2k retro style with django templates --- static/scripts/theme.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 static/scripts/theme.js (limited to 'static/scripts/theme.js') diff --git a/static/scripts/theme.js b/static/scripts/theme.js new file mode 100644 index 0000000..0ba6625 --- /dev/null +++ b/static/scripts/theme.js @@ -0,0 +1,37 @@ +document.addEventListener('DOMContentLoaded', function () { + const savedTheme = localStorage.getItem('theme') || 'light'; + document.documentElement.setAttribute('data-theme', savedTheme); + + const preferencesForm = document.getElementById('preferences-form'); + if (preferencesForm) { + const themeRadios = document.querySelectorAll('input[name="theme"]'); + themeRadios.forEach(radio => { + if (radio.value === savedTheme) { + radio.checked = true; + } + }); + + preferencesForm.addEventListener('submit', function (e) { + e.preventDefault(); + const selectedTheme = document.querySelector('input[name="theme"]:checked').value; + localStorage.setItem('theme', selectedTheme); + document.documentElement.setAttribute('data-theme', selectedTheme); + + let successMsg = document.querySelector('.success-message'); + if (successMsg) { + successMsg.remove(); + } + + const message = document.createElement('div'); + message.className = 'success-message'; + message.textContent = 'Preferences saved successfully!'; + preferencesForm.parentNode.insertBefore(message, preferencesForm); + + setTimeout(() => { + if (message.parentNode) { + message.remove(); + } + }, 3000); + }); + } +}); \ No newline at end of file -- cgit v1.2.3