File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ body {
1313 font-family : Arial, sans-serif;
1414}
1515
16+ body .dark {
17+ background-color : # 121212 ;
18+ color : # f5f5f5 ;
19+ }
20+
1621# wrap {
1722 max-width : 1200px ;
1823 margin : auto;
@@ -30,6 +35,12 @@ footer {
3035 background-color : # f9f9f9 ;
3136}
3237
38+ body .dark header ,
39+ body .dark .main ,
40+ body .dark footer {
41+ background-color : # 1e1e1e ;
42+ }
43+
3344header {
3445 display : flex;
3546 justify-content : space-between;
@@ -58,6 +69,10 @@ nav a {
5869 color : black;
5970}
6071
72+ body .dark nav a {
73+ color : # f5f5f5 ;
74+ }
75+
6176aside {
6277 flex-grow : 1 ;
6378}
@@ -79,6 +94,20 @@ aside {
7994 margin-top : 2.2rem ;
8095}
8196
97+ # theme-toggle {
98+ padding : 0.4rem 0.8rem ;
99+ border-radius : 4px ;
100+ border : 1px solid # ccc ;
101+ background : # ffffff ;
102+ cursor : pointer;
103+ }
104+
105+ body .dark # theme-toggle {
106+ background : # 333 ;
107+ color : # f5f5f5 ;
108+ border-color : # 555 ;
109+ }
110+
82111/* Responsive adjustments */
83112@media (max-width : 768px ) {
84113 header ,
Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ $(function () {
1818 console . log ( data )
1919 $ ( '#words' ) . text ( data . content )
2020 } )
21+
22+ initTheme ( )
23+ $ ( '#theme-toggle' ) . on ( 'click' , function ( ) {
24+ toggleTheme ( )
25+ } )
2126} )
2227
2328function sendMessage ( ) {
@@ -98,3 +103,45 @@ if (!String.linkify) {
98103 . replace ( emailAddressPattern , '<a href="mailto:$&">$&</a>' )
99104 }
100105}
106+
107+ function initTheme ( ) {
108+ try {
109+ const saved = localStorage . getItem ( 'okdevtv-theme' )
110+ let theme = saved
111+ if ( ! theme ) {
112+ if ( window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ) {
113+ theme = 'dark'
114+ } else {
115+ theme = 'light'
116+ }
117+ }
118+ applyTheme ( theme )
119+ } catch ( e ) {
120+ applyTheme ( 'light' )
121+ }
122+ }
123+
124+ function toggleTheme ( ) {
125+ const isDark = document . body . classList . contains ( 'dark' )
126+ const next = isDark ? 'light' : 'dark'
127+ applyTheme ( next )
128+ try {
129+ localStorage . setItem ( 'okdevtv-theme' , next )
130+ } catch ( e ) { }
131+ }
132+
133+ function applyTheme ( theme ) {
134+ if ( theme === 'dark' ) {
135+ document . body . classList . add ( 'dark' )
136+ const btn = document . getElementById ( 'theme-toggle' )
137+ if ( btn ) {
138+ btn . textContent = 'Light'
139+ }
140+ } else {
141+ document . body . classList . remove ( 'dark' )
142+ const btn = document . getElementById ( 'theme-toggle' )
143+ if ( btn ) {
144+ btn . textContent = 'Dark'
145+ }
146+ }
147+ }
Original file line number Diff line number Diff line change 5353 <%= (user) ? ' My Page' : ' Login' %>
5454 </a >
5555 </li >
56+ <li >
57+ <button id =" theme-toggle" type =" button" >Dark</button >
58+ </li >
5659 </ul >
5760 </nav >
5861 <aside >
You can’t perform that action at this time.
0 commit comments