1111 < link rel ="apple-touch-icon " sizes ="180x180 " href ="{{ '/assets/apple-touch-icon.png' | relative_url }} " />
1212 < meta name ="apple-mobile-web-app-title " content ="Java " />
1313
14- <!-- Manifest (for GitHub Pages project path) -->
14+ <!-- Manifest -->
1515 < link rel ="manifest " href ="/JavaEvolution-Learning-Growing-Mastering/assets/site.webmanifest ">
1616 < meta name ="theme-color " content ="#ffffff ">
1717
2121 < script >
2222 // Sidebar Toggle Function
2323 function toggleSidebar ( ) {
24- const sidebar = document . getElementById ( "sidebar" ) ;
25- sidebar . classList . toggle ( "hidden " ) ;
24+ const sidebar = document . getElementById ( "sidebar" ) ;
25+ sidebar . classList . toggle ( "visible " ) ;
2626 }
2727
28- // Hide sidebar when clicking outside
28+ // Hide Sidebar When Clicking Outside
2929 function hideSidebarIfClickedOutside ( event ) {
30- const sidebar = document . getElementById ( "sidebar" ) ;
31- const toggleBtn = document . querySelector ( ".toggle-btn" ) ;
32- if ( ! sidebar . classList . contains ( "hidden " ) &&
33- ! sidebar . contains ( event . target ) &&
34- ! toggleBtn . contains ( event . target ) ) {
35- sidebar . classList . add ( "hidden ") ;
36- }
30+ const sidebar = document . getElementById ( "sidebar" ) ;
31+ const toggleBtn = document . querySelector ( ".toggle-btn" ) ;
32+ if ( sidebar . classList . contains ( "visible " ) &&
33+ ! sidebar . contains ( event . target ) &&
34+ ! toggleBtn . contains ( event . target ) ) {
35+ sidebar . classList . remove ( "visible ") ;
36+ }
3737 }
3838
3939 // Dark Mode Toggle Function
4040 const toggleDarkMode = ( ) => {
41- document . body . classList . toggle ( ' dark-mode' ) ;
42- localStorage . setItem ( ' dark-mode' , document . body . classList . contains ( ' dark-mode' ) ) ;
41+ document . body . classList . toggle ( " dark-mode" ) ;
42+ localStorage . setItem ( " dark-mode" , document . body . classList . contains ( " dark-mode" ) ) ;
4343 } ;
4444
45- // Live Time Update Function ( with GMT offset)
45+ // Live Time Update Function with GMT Offset
4646 function updateLiveTime ( ) {
47- const now = new Date ( ) ;
48- let hours = now . getHours ( ) ;
49- const minutes = now . getMinutes ( ) . toString ( ) . padStart ( 2 , '0' ) ;
50- const seconds = now . getSeconds ( ) . toString ( ) . padStart ( 2 , '0' ) ;
51- const ampm = hours >= 12 ? 'PM' : 'AM' ;
52- hours = hours % 12 || 12 ;
53- const timeString = `${ hours } :${ minutes } :${ seconds } ${ ampm } ` ;
54-
55- // Calculate GMT offset (negate offset from getTimezoneOffset)
56- const offset = - now . getTimezoneOffset ( ) ;
57- const offsetHours = Math . floor ( Math . abs ( offset ) / 60 ) ;
58- const offsetMinutes = Math . abs ( offset ) % 60 ;
59- const offsetSign = offset >= 0 ? '+' : '-' ;
60- const offsetString = `GMT${ offsetSign } ${ offsetHours . toString ( ) . padStart ( 2 , '0' ) } :${ offsetMinutes . toString ( ) . padStart ( 2 , '0' ) } ` ;
61-
62- document . getElementById ( 'current-time' ) . textContent = timeString + ' ' + offsetString ;
47+ const now = new Date ( ) ;
48+ let hours = now . getHours ( ) ;
49+ const minutes = now . getMinutes ( ) . toString ( ) . padStart ( 2 , "0" ) ;
50+ const seconds = now . getSeconds ( ) . toString ( ) . padStart ( 2 , "0" ) ;
51+ const ampm = hours >= 12 ? "PM" : "AM" ;
52+ hours = hours % 12 || 12 ;
53+ const timeString = `${ hours } :${ minutes } :${ seconds } ${ ampm } ` ;
54+ const offset = - now . getTimezoneOffset ( ) ;
55+ const offsetHours = Math . floor ( Math . abs ( offset ) / 60 ) ;
56+ const offsetMinutes = Math . abs ( offset ) % 60 ;
57+ const offsetSign = offset >= 0 ? "+" : "-" ;
58+ const offsetString = `GMT${ offsetSign } ${ offsetHours . toString ( ) . padStart ( 2 , "0" ) } :${ offsetMinutes . toString ( ) . padStart ( 2 , "0" ) } ` ;
59+ document . getElementById ( "live-time" ) . textContent = `${ timeString } ${ offsetString } ` ;
6360 }
6461
6562 // Service Worker Registration
6663 if ( "serviceWorker" in navigator ) {
67- navigator . serviceWorker . register ( "/JavaEvolution-Learning-Growing-Mastering/assets/sw.js" )
68- . then ( ( ) => console . log ( "✅ Service Worker Registered" ) )
69- . catch ( err => console . error ( "SW registration failed" , err ) ) ;
64+ navigator . serviceWorker . register ( "/JavaEvolution-Learning-Growing-Mastering/assets/sw.js" )
65+ . then ( ( ) => console . log ( "✅ Service Worker Registered" ) )
66+ . catch ( err => console . error ( "SW registration failed" , err ) ) ;
7067 }
7168
72- // Initialization on DOMContentLoaded
73- window . addEventListener ( 'DOMContentLoaded' , ( ) => {
74- // Restore dark mode preference
75- if ( localStorage . getItem ( 'dark-mode' ) === 'true' ) {
76- document . body . classList . add ( 'dark-mode' ) ;
77- }
78- // Attach listener for sidebar auto-hide
79- document . addEventListener ( 'click' , hideSidebarIfClickedOutside ) ;
80- // Start live time updates
81- updateLiveTime ( ) ;
82- setInterval ( updateLiveTime , 1000 ) ;
69+ // Initialization
70+ window . addEventListener ( "DOMContentLoaded" , ( ) => {
71+ if ( localStorage . getItem ( "dark-mode" ) === "true" ) {
72+ document . body . classList . add ( "dark-mode" ) ;
73+ }
74+ document . addEventListener ( "click" , hideSidebarIfClickedOutside ) ;
75+ updateLiveTime ( ) ;
76+ setInterval ( updateLiveTime , 1000 ) ;
8377 } ) ;
8478 </ 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 >
11979</ head >
12080< body >
121-
122- <!-- Time Container with Dark Mode Toggle Embedded -->
81+ <!-- Time Container with Dark Mode Toggle -->
12382< div id ="time-container ">
124- < span id ="current -time "> --:-- </ span >
125- < button class =" dark-toggle " onclick ="toggleDarkMode() "> 🌙 </ button >
83+ < div id ="live -time "> Time: Loading... </ div >
84+ < button onclick ="toggleDarkMode() " class =" dark-toggle " > 🌓 </ button >
12685</ div >
12786
12887< div class ="wrapper ">
13392
13493 <!-- Content Area -->
13594 < div class ="content ">
136- <!-- Optional: Manual Sidebar Toggle Button -->
13795 < button class ="toggle-btn " onclick ="toggleSidebar() "> ☰</ button >
13896 < div class ="fade-in ">
13997 {{ content }}
14098 </ div >
14199 </ div >
142100</ div >
143101</ body >
144- </ html >
102+ </ html >
0 commit comments