@@ -90,6 +90,15 @@ const colorOptions = {
90
90
pink : 'color-scheme-pink'
91
91
} ;
92
92
93
+ // Define the favicon options
94
+ const faviconOptions = {
95
+ yellow : 'favicon-yellow.ico' ,
96
+ green : 'favicon-green.ico' ,
97
+ blue : 'favicon-blue.ico' ,
98
+ purple : 'favicon-purple.ico' ,
99
+ pink : 'favicon-pink.ico'
100
+ } ;
101
+
93
102
// check if there is a color preference stored in localStorage
94
103
const colorPref = localStorage . getItem ( 'colorPref' ) ;
95
104
@@ -105,6 +114,8 @@ Object.keys(colorOptions).forEach(color => {
105
114
button . addEventListener ( 'click' , ( ) => {
106
115
setTheme ( colorOptions [ color ] ) ;
107
116
localStorage . setItem ( 'colorPref' , color ) ;
117
+ updateFavicon ( color ) ;
118
+
108
119
Object . keys ( colorOptions ) . forEach ( otherColor => {
109
120
const otherButton = document . getElementById ( `${ otherColor } -button` ) ;
110
121
if ( color === otherColor ) {
@@ -135,23 +146,46 @@ function setTheme(theme) {
135
146
} ) ;
136
147
}
137
148
149
+ // Update the favicon according to the current color
150
+ function updateFavicon ( color ) {
151
+ const favicon = document . querySelector ( "link[rel*='icon']" ) ;
152
+ favicon . href = faviconOptions [ color ] ;
153
+ }
154
+
155
+ // Update the initial favicon
156
+ updateFavicon ( colorPref ? colorPref : 'yellow' ) ;
157
+
138
158
// Copy characters to clipboard
139
159
var charButtons = document . querySelectorAll ( '.char-button' ) ;
140
- charButtons . forEach ( function ( button ) {
141
- button . addEventListener ( 'click' , function ( ) {
142
- var charText = this . getAttribute ( 'data-clipboard-text' ) ;
143
- navigator . clipboard . writeText ( charText ) . then ( function ( ) {
144
- var confirmationText = '<span class="character">' + charText + '</span>' +
160
+ charButtons . forEach ( function ( button ) {
161
+ button . addEventListener ( 'click' , function ( ) {
162
+ var charText = this . getAttribute ( 'data-clipboard-text' ) ;
163
+ navigator . clipboard . writeText ( charText ) . then ( function ( ) {
164
+ var confirmationText = '<span class="character">' + charText + '</span>' +
145
165
'<span class="message"> copied to clipboard</span>' ;
146
- var confirmationElement = document . getElementById ( 'confirmation-message' ) ;
147
- var confirmationInnerElement = confirmationElement . querySelector ( '.copy-confirmation-inner' ) ;
148
- confirmationInnerElement . innerHTML = confirmationText ;
149
- confirmationElement . classList . add ( 'visible' ) ;
150
- setTimeout ( function ( ) {
151
- confirmationElement . classList . remove ( 'visible' ) ;
152
- } , 750 ) ; // Remove "visible" class after 750 mms
153
- } , function ( ) {
154
- console . error ( 'Failed to copy to clipboard' ) ;
166
+ var confirmationElement = document . getElementById ( 'confirmation-message' ) ;
167
+ var confirmationInnerElement = confirmationElement . querySelector ( '.copy-confirmation-inner' ) ;
168
+ confirmationInnerElement . innerHTML = confirmationText ;
169
+ confirmationElement . classList . add ( 'visible' ) ;
170
+ setTimeout ( function ( ) {
171
+ confirmationElement . classList . remove ( 'visible' ) ;
172
+ } , 750 ) ; // Remove "visible" class after 750 ms
173
+ } ) . catch ( function ( ) {
174
+ console . error ( 'Failed to copy to clipboard' ) ;
155
175
} ) ;
156
176
} ) ;
157
177
} ) ;
178
+
179
+ // Offline Mode
180
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
181
+ function updateOnlineStatus ( ) {
182
+ if ( navigator . onLine ) {
183
+ document . body . classList . remove ( 'offline-mode' ) ;
184
+ } else {
185
+ document . body . classList . add ( 'offline-mode' ) ;
186
+ }
187
+ }
188
+ window . addEventListener ( 'online' , updateOnlineStatus ) ;
189
+ window . addEventListener ( 'offline' , updateOnlineStatus ) ;
190
+ updateOnlineStatus ( ) ;
191
+ } ) ;
0 commit comments