|
17 | 17 | <title>{{ page.title }}</title> |
18 | 18 | <link rel="stylesheet" href="{{ '/assets/style.css' | relative_url }}"> |
19 | 19 |
|
20 | | - <script> |
| 20 | + |
| 21 | +<!-- <script> |
21 | 22 | // Track current zone: 'IST' or 'GMT' |
22 | 23 | let currentZone = 'IST'; |
23 | 24 |
|
|
93 | 94 | .catch(err => console.error('SW registration failed', err)); |
94 | 95 | } |
95 | 96 | }; |
| 97 | + </script>--> |
| 98 | + |
| 99 | + <script> |
| 100 | + // Track current zone: 'IST' or 'GMT' |
| 101 | + let currentZone = 'IST'; |
| 102 | + |
| 103 | + // Sidebar Toggle |
| 104 | + function toggleSidebar() { |
| 105 | + document.getElementById('sidebar').classList.toggle('hidden'); |
| 106 | + } |
| 107 | + |
| 108 | + // Hide Sidebar When Clicking Outside |
| 109 | + function hideSidebarIfClickedOutside(event) { |
| 110 | + const sidebar = document.getElementById('sidebar'); |
| 111 | + const toggleBtn = document.querySelector('.toggle-btn'); |
| 112 | + if (!sidebar.classList.contains('hidden') |
| 113 | + && !sidebar.contains(event.target) |
| 114 | + && !toggleBtn.contains(event.target)) { |
| 115 | + sidebar.classList.add('hidden'); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + // Dark Mode Toggle |
| 120 | + function toggleDarkMode() { |
| 121 | + document.body.classList.toggle('dark-mode'); |
| 122 | + localStorage.setItem('dark-mode', document.body.classList.contains('dark-mode')); |
| 123 | + } |
| 124 | + |
| 125 | + // Toggle between IST and GMT |
| 126 | + function toggleTimezone() { |
| 127 | + currentZone = (currentZone === 'IST') ? 'GMT' : 'IST'; |
| 128 | + document.getElementById('tz-toggle-btn').textContent = currentZone; |
| 129 | + updateLiveTime(); // immediately refresh display |
| 130 | + } |
| 131 | + |
| 132 | + // Live Time Update with timezone support |
| 133 | + function updateLiveTime() { |
| 134 | + const now = new Date(); |
| 135 | + let date; |
| 136 | + if (currentZone === 'GMT') { |
| 137 | + // UTC time |
| 138 | + date = new Date(now.getTime() + now.getTimezoneOffset() * 60000); |
| 139 | + } else { |
| 140 | + // IST = UTC + 5.5h |
| 141 | + const utc = now.getTime() + now.getTimezoneOffset() * 60000; |
| 142 | + date = new Date(utc + 5.5 * 3600000); |
| 143 | + } |
| 144 | + let hours = date.getHours(); |
| 145 | + const mins = date.getMinutes().toString().padStart(2,'0'); |
| 146 | + const secs = date.getSeconds().toString().padStart(2,'0'); |
| 147 | + const ampm = hours >= 12 ? 'PM' : 'AM'; |
| 148 | + hours = hours % 12 || 12; |
| 149 | + document.getElementById('live-time').textContent = |
| 150 | + `Time (${currentZone}): ${hours}:${mins}:${secs} ${ampm}`; |
| 151 | + } |
| 152 | + |
| 153 | + // On window load: initialize Dark Mode, Sidebar listener, Live Time & Service Worker |
| 154 | + window.onload = () => { |
| 155 | + // Dark mode init |
| 156 | + if (localStorage.getItem('dark-mode') === 'true') { |
| 157 | + document.body.classList.add('dark-mode'); |
| 158 | + } |
| 159 | + |
| 160 | + // Sidebar outside-click hide |
| 161 | + document.addEventListener('click', hideSidebarIfClickedOutside); |
| 162 | + |
| 163 | + // Start live time updates |
| 164 | + updateLiveTime(); |
| 165 | + setInterval(updateLiveTime, 1000); |
| 166 | + |
| 167 | + // Service Worker registration |
| 168 | + if ('serviceWorker' in navigator) { |
| 169 | + navigator.serviceWorker |
| 170 | + .register('/JavaEvolution-Learning-Growing-Mastering/assets/sw.js') |
| 171 | + .then(() => console.log('✅ Service Worker Registered')) |
| 172 | + .catch(err => console.error('SW registration failed', err)); |
| 173 | + } |
| 174 | + }; |
| 175 | + |
96 | 176 | </script> |
97 | 177 | </head> |
98 | 178 | <body> |
|
0 commit comments