|
11 | 11 | <link rel="apple-touch-icon" sizes="180x180" href="{{ '/assets/apple-touch-icon.png' | relative_url }}" /> |
12 | 12 | <meta name="apple-mobile-web-app-title" content="Java" /> |
13 | 13 |
|
14 | | - <!-- Manifest (use only one, with correct GitHub Pages path) --> |
| 14 | + <!-- Manifest (for GitHub Pages project path) --> |
15 | 15 | <link rel="manifest" href="/JavaEvolution-Learning-Growing-Mastering/assets/site.webmanifest"> |
16 | 16 | <meta name="theme-color" content="#ffffff"> |
17 | 17 |
|
18 | 18 | <title>{{ page.title }}</title> |
19 | | - <link rel="stylesheet" href="{{ "/assets/style.css" | relative_url }}"> |
| 19 | + <link rel="stylesheet" href="{{ '/assets/style.css' | relative_url }}"> |
20 | 20 |
|
21 | 21 | <script> |
22 | 22 | // Sidebar Toggle Function |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 |
|
39 | | - // Dark Mode Toggle Function (now used inside time container) |
| 39 | + // Dark Mode Toggle Function |
40 | 40 | const toggleDarkMode = () => { |
41 | 41 | document.body.classList.toggle('dark-mode'); |
42 | 42 | localStorage.setItem('dark-mode', document.body.classList.contains('dark-mode')); |
43 | 43 | }; |
44 | 44 |
|
45 | | - // Live Time Update Function with GMT Offset |
| 45 | + // Live Time Update Function (with GMT offset) |
46 | 46 | function updateLiveTime() { |
47 | 47 | const now = new Date(); |
48 | 48 | let hours = now.getHours(); |
|
52 | 52 | hours = hours % 12 || 12; |
53 | 53 | const timeString = `${hours}:${minutes}:${seconds} ${ampm}`; |
54 | 54 |
|
55 | | - // Calculate GMT offset (JS returns minutes behind UTC; we negate to show positive for IST) |
| 55 | + // Calculate GMT offset (negate offset from getTimezoneOffset) |
56 | 56 | const offset = -now.getTimezoneOffset(); |
57 | 57 | const offsetHours = Math.floor(Math.abs(offset) / 60); |
58 | 58 | const offsetMinutes = Math.abs(offset) % 60; |
59 | 59 | const offsetSign = offset >= 0 ? '+' : '-'; |
60 | 60 | const offsetString = `GMT${offsetSign}${offsetHours.toString().padStart(2, '0')}:${offsetMinutes.toString().padStart(2, '0')}`; |
61 | 61 |
|
62 | | - document.getElementById('live-time').textContent = `Time: ${timeString} ${offsetString}`; |
| 62 | + document.getElementById('current-time').textContent = timeString + ' ' + offsetString; |
63 | 63 | } |
64 | 64 |
|
65 | 65 | // Service Worker Registration |
|
71 | 71 |
|
72 | 72 | // Initialization on DOMContentLoaded |
73 | 73 | window.addEventListener('DOMContentLoaded', () => { |
| 74 | + // Restore dark mode preference |
74 | 75 | if (localStorage.getItem('dark-mode') === 'true') { |
75 | 76 | document.body.classList.add('dark-mode'); |
76 | 77 | } |
| 78 | + // Attach listener for sidebar auto-hide |
77 | 79 | document.addEventListener('click', hideSidebarIfClickedOutside); |
| 80 | + // Start live time updates |
78 | 81 | updateLiveTime(); |
79 | 82 | setInterval(updateLiveTime, 1000); |
80 | 83 | }); |
81 | 84 | </script> |
| 85 | + |
| 86 | + <!-- (Optional inline styles for the time container can also reside in your style.css) --> |
| 87 | + <style> |
| 88 | + /* Time Container (holds the live time and dark mode toggle) */ |
| 89 | + #time-container { |
| 90 | + position: fixed; |
| 91 | + top: 1rem; |
| 92 | + right: 1rem; |
| 93 | + z-index: 1100; |
| 94 | + background: rgba(0, 0, 0, 0.6); |
| 95 | + color: #00ffff; |
| 96 | + border: 1px solid #00ffff; |
| 97 | + box-shadow: 0 0 15px rgba(0, 255, 255, 0.3); |
| 98 | + border-radius: 16px; |
| 99 | + padding: 0.6rem 1rem; |
| 100 | + display: flex; |
| 101 | + align-items: center; |
| 102 | + gap: 0.5rem; |
| 103 | + font-weight: 600; |
| 104 | + font-size: 1.05rem; |
| 105 | + } |
| 106 | + /* Dark mode overrides for the time container */ |
| 107 | + body.dark-mode #time-container { |
| 108 | + background-color: #333; |
| 109 | + color: #eee; |
| 110 | + } |
| 111 | + @media (max-width: 600px) { |
| 112 | + #time-container { |
| 113 | + flex-direction: column; |
| 114 | + font-size: 0.95rem; |
| 115 | + padding: 0.8rem; |
| 116 | + } |
| 117 | + } |
| 118 | + </style> |
82 | 119 | </head> |
83 | 120 | <body> |
84 | | -<!-- The combined Time Container with Dark Mode Toggle --> |
| 121 | + |
| 122 | +<!-- Time Container with Dark Mode Toggle Embedded --> |
85 | 123 | <div id="time-container"> |
86 | | - <div id="live-time">Time: Loading...</div> |
87 | | - <!-- Dark mode toggle button placed inside the time container --> |
88 | | - <button onclick="toggleDarkMode()" class="dark-toggle" style="padding: 0.5rem; font-size: 1.2rem;">🌓</button> |
| 124 | + <span id="current-time">--:--</span> |
| 125 | + <button class="dark-toggle" onclick="toggleDarkMode()">🌙</button> |
89 | 126 | </div> |
90 | 127 |
|
91 | 128 | <div class="wrapper"> |
|
96 | 133 |
|
97 | 134 | <!-- Content Area --> |
98 | 135 | <div class="content"> |
99 | | - <!-- Sidebar Toggle Button (if you want manual control; you may remove it later) --> |
| 136 | + <!-- Optional: Manual Sidebar Toggle Button --> |
100 | 137 | <button class="toggle-btn" onclick="toggleSidebar()">☰</button> |
101 | 138 | <div class="fade-in"> |
102 | 139 | {{ content }} |
|
0 commit comments