|
1 | 1 | <!DOCTYPE html> |
2 | | -<html lang="en" class="light"> |
| 2 | +<html lang="en" class="dark"> |
3 | 3 | <head> |
4 | 4 | <meta charset="UTF-8"> |
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
79 | 79 | <div class="container mx-auto px-4 py-8"> |
80 | 80 | <div class="flex justify-center items-center mb-8 relative"> |
81 | 81 | <h1 class="text-4xl font-bold text-gray-800">DumbWhois</h1> |
82 | | - <button onclick="toggleDarkMode()" class="absolute right-0 p-2 rounded-lg bg-gray-200 dark:bg-gray-700"> |
83 | | - <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> |
84 | | - <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" /> |
85 | | - </svg> |
| 82 | + <button onclick="toggleDarkMode()" class="absolute right-0 p-2 rounded-lg text-gray-800 dark:text-gray-200"> |
| 83 | + <span id="themeIcon"></span> |
86 | 84 | </button> |
87 | 85 | </div> |
88 | 86 |
|
@@ -110,16 +108,34 @@ <h1 class="text-4xl font-bold text-gray-800">DumbWhois</h1> |
110 | 108 | </div> |
111 | 109 |
|
112 | 110 | <script> |
| 111 | + const sunIcon = `<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> |
| 112 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /> |
| 113 | + </svg>`; |
| 114 | + |
| 115 | + const moonIcon = `<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> |
| 116 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" /> |
| 117 | + </svg>`; |
| 118 | + |
| 119 | + function updateThemeIcon() { |
| 120 | + const isDark = document.documentElement.classList.contains('dark'); |
| 121 | + document.getElementById('themeIcon').innerHTML = isDark ? sunIcon : moonIcon; |
| 122 | + } |
| 123 | + |
113 | 124 | function toggleDarkMode() { |
114 | 125 | const html = document.documentElement; |
115 | 126 | const isDark = html.classList.contains('dark'); |
116 | 127 | html.classList.toggle('dark'); |
117 | 128 | localStorage.setItem('darkMode', !isDark); |
| 129 | + updateThemeIcon(); |
118 | 130 | } |
119 | 131 |
|
120 | | - if (localStorage.getItem('darkMode') === 'true') { |
121 | | - document.documentElement.classList.add('dark'); |
| 132 | + // Check local storage, default to dark mode if not set |
| 133 | + if (localStorage.getItem('darkMode') === 'false') { |
| 134 | + document.documentElement.classList.remove('dark'); |
122 | 135 | } |
| 136 | + |
| 137 | + // Set initial icon |
| 138 | + updateThemeIcon(); |
123 | 139 |
|
124 | 140 | function formatDate(dateString) { |
125 | 141 | return dateString ? new Date(dateString).toLocaleString() : 'N/A'; |
|
0 commit comments