Spaces:
Sleeping
Sleeping
Upload theme-fix.js
Browse files- frontend/theme-fix.js +118 -0
frontend/theme-fix.js
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// This is a standalone script to fix theme issues
|
2 |
+
// Add this script to your HTML before the closing body tag
|
3 |
+
|
4 |
+
document.addEventListener("DOMContentLoaded", () => {
|
5 |
+
console.log("Theme fix script loaded")
|
6 |
+
|
7 |
+
// Fix theme toggle button
|
8 |
+
const themeToggle = document.getElementById("theme-toggle")
|
9 |
+
if (themeToggle) {
|
10 |
+
// Remove any existing event listeners by cloning and replacing
|
11 |
+
const newThemeToggle = themeToggle.cloneNode(true)
|
12 |
+
themeToggle.parentNode.replaceChild(newThemeToggle, themeToggle)
|
13 |
+
|
14 |
+
// Add event listener to the new button
|
15 |
+
newThemeToggle.addEventListener("click", () => {
|
16 |
+
console.log("Theme toggle clicked")
|
17 |
+
toggleTheme()
|
18 |
+
})
|
19 |
+
}
|
20 |
+
|
21 |
+
// Make sure theme is initialized
|
22 |
+
initTheme()
|
23 |
+
|
24 |
+
// Global theme toggle function
|
25 |
+
window.toggleTheme = () => {
|
26 |
+
console.log("Toggle theme called")
|
27 |
+
|
28 |
+
// Toggle dark class
|
29 |
+
document.documentElement.classList.toggle("dark")
|
30 |
+
|
31 |
+
// Update icons
|
32 |
+
const sunIcon = document.getElementById("sun-icon")
|
33 |
+
const moonIcon = document.getElementById("moon-icon")
|
34 |
+
|
35 |
+
if (document.documentElement.classList.contains("dark")) {
|
36 |
+
// Dark mode active
|
37 |
+
if (sunIcon) sunIcon.classList.remove("hidden")
|
38 |
+
if (moonIcon) moonIcon.classList.add("hidden")
|
39 |
+
localStorage.setItem("theme", "dark")
|
40 |
+
console.log("Dark mode activated")
|
41 |
+
} else {
|
42 |
+
// Light mode active
|
43 |
+
if (sunIcon) sunIcon.classList.add("hidden")
|
44 |
+
if (moonIcon) moonIcon.classList.remove("hidden")
|
45 |
+
localStorage.setItem("theme", "light")
|
46 |
+
console.log("Light mode activated")
|
47 |
+
}
|
48 |
+
|
49 |
+
// Show notification
|
50 |
+
const message = document.documentElement.classList.contains("dark") ? "Dark mode activated" : "Light mode activated"
|
51 |
+
|
52 |
+
showNotification(message)
|
53 |
+
}
|
54 |
+
|
55 |
+
// Global init theme function
|
56 |
+
window.initTheme = () => {
|
57 |
+
const savedTheme = localStorage.getItem("theme")
|
58 |
+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches
|
59 |
+
|
60 |
+
console.log("Init theme - Saved theme:", savedTheme, "System prefers dark:", prefersDark)
|
61 |
+
|
62 |
+
if (savedTheme === "dark" || (!savedTheme && prefersDark)) {
|
63 |
+
document.documentElement.classList.add("dark")
|
64 |
+
const sunIcon = document.getElementById("sun-icon")
|
65 |
+
const moonIcon = document.getElementById("moon-icon")
|
66 |
+
if (sunIcon) sunIcon.classList.remove("hidden")
|
67 |
+
if (moonIcon) moonIcon.classList.add("hidden")
|
68 |
+
} else {
|
69 |
+
document.documentElement.classList.remove("dark")
|
70 |
+
const sunIcon = document.getElementById("sun-icon")
|
71 |
+
const moonIcon = document.getElementById("moon-icon")
|
72 |
+
if (sunIcon) sunIcon.classList.add("hidden")
|
73 |
+
if (moonIcon) moonIcon.classList.remove("hidden")
|
74 |
+
}
|
75 |
+
}
|
76 |
+
})
|
77 |
+
|
78 |
+
// Ensure notification function is available
|
79 |
+
if (typeof showNotification !== "function") {
|
80 |
+
window.showNotification = (message, type = "success") => {
|
81 |
+
console.log("Notification:", message, type)
|
82 |
+
|
83 |
+
// Create notification element
|
84 |
+
const notification = document.createElement("div")
|
85 |
+
|
86 |
+
// Set class based on notification type
|
87 |
+
if (type === "success") {
|
88 |
+
notification.className =
|
89 |
+
"notification fixed top-4 right-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded shadow-md dark:bg-green-900 dark:text-green-100 dark:border-green-400"
|
90 |
+
} else if (type === "error") {
|
91 |
+
notification.className =
|
92 |
+
"notification fixed top-4 right-4 bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded shadow-md dark:bg-red-900 dark:text-red-100 dark:border-red-400"
|
93 |
+
} else if (type === "warning") {
|
94 |
+
notification.className =
|
95 |
+
"notification fixed top-4 right-4 bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4 rounded shadow-md dark:bg-yellow-900 dark:text-yellow-100 dark:border-yellow-400"
|
96 |
+
} else if (type === "info") {
|
97 |
+
notification.className =
|
98 |
+
"notification fixed top-4 right-4 bg-blue-100 border-l-4 border-blue-500 text-blue-700 p-4 rounded shadow-md dark:bg-blue-900 dark:text-blue-100 dark:border-blue-400"
|
99 |
+
}
|
100 |
+
|
101 |
+
notification.innerHTML = message
|
102 |
+
|
103 |
+
// Add to document
|
104 |
+
document.body.appendChild(notification)
|
105 |
+
|
106 |
+
// Remove after 3 seconds
|
107 |
+
setTimeout(() => {
|
108 |
+
notification.style.opacity = "0"
|
109 |
+
notification.style.transform = "translateY(-20px)"
|
110 |
+
notification.style.transition = "opacity 0.5s, transform 0.5s"
|
111 |
+
|
112 |
+
setTimeout(() => {
|
113 |
+
notification.remove()
|
114 |
+
}, 500)
|
115 |
+
}, 3000)
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|