@@ -35,6 +35,13 @@ const notyf = new Notyf({
3535} )
3636
3737document . addEventListener ( 'DOMContentLoaded' , ( ) => {
38+ const imageBlocks = document . querySelectorAll ( '.block' )
39+ let i = 1
40+ const them = localStorage . getItem ( 'theme' ) === 'dark' ? '_dark' : ''
41+ imageBlocks . forEach ( block => {
42+ block . style . backgroundImage = `url(images/zad${ i } ${ them } .png)`
43+ i ++
44+ } )
3845 const themeSwitch = document . getElementById ( 'theme-checkbox' )
3946 const prefersDarkScheme = window . matchMedia ( '(prefers-color-scheme: dark)' )
4047
@@ -51,17 +58,17 @@ document.addEventListener('DOMContentLoaded', () => {
5158
5259 // Обработчик переключения темы
5360 themeSwitch . addEventListener ( 'change' , function ( ) {
61+ const newTheme = this . checked ? 'dark' : 'light'
62+ document . body . classList . toggle ( 'dark' , this . checked )
63+ localStorage . setItem ( 'theme' , newTheme )
64+
5465 const imageBlocks = document . querySelectorAll ( '.block' )
5566 let i = 1
67+ const them = localStorage . getItem ( 'theme' ) === 'dark' ? '_dark' : ''
5668 imageBlocks . forEach ( block => {
57- const them = localStorage . getItem ( 'theme' ) === 'light' ? '_dark' : ''
5869 block . style . backgroundImage = `url(images/zad${ i } ${ them } .png)`
5970 i ++
6071 } )
61- const newTheme = this . checked ? 'dark' : 'light'
62- document . body . classList . toggle ( 'dark' , this . checked )
63- localStorage . setItem ( 'theme' , newTheme )
64-
6572 // Обновляем цвет иконок
6673 updateIconColors ( newTheme )
6774 } )
0 commit comments