Исправлены ошибки связанные с переключение тем
This commit is contained in:
@@ -10,16 +10,33 @@ const checkbox = document.getElementById('isLightTheme');
|
|||||||
const html = document.getElementsByTagName('html')[0];
|
const html = document.getElementsByTagName('html')[0];
|
||||||
let scale = 1; // Начальный масштаб
|
let scale = 1; // Начальный масштаб
|
||||||
|
|
||||||
|
function createTheme(nameTheme) {
|
||||||
|
if (nameTheme == 'dark') {
|
||||||
|
html.style.backgroundColor = '#1e1e1e';
|
||||||
|
changeButtonsColor('#fff')
|
||||||
|
} else if (nameTheme == 'light') {
|
||||||
|
html.style.backgroundColor = '#fff';
|
||||||
|
changeButtonsColor('#1e1e1e')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Установление значения поля ввода из local storage и темы сайта
|
// Установление значения поля ввода из local storage и темы сайта
|
||||||
window.onload = () => {
|
window.onload = () => {
|
||||||
// Установка темы сайта
|
// Установка темы сайта
|
||||||
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
let oldTheme = localStorage.getItem('theme')
|
||||||
if (darkModeMediaQuery.matches) {
|
if (oldTheme){
|
||||||
html.style.backgroundColor = '#1e1e1e';
|
createTheme(oldTheme)
|
||||||
changeButtonsColor('#fff')
|
|
||||||
|
if (oldTheme == 'light') {
|
||||||
|
checkbox.checked = 1
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
html.style.backgroundColor = '#fff';
|
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
changeButtonsColor('#1e1e1e')
|
if (darkModeMediaQuery.matches) {
|
||||||
|
createTheme('dark')
|
||||||
|
} else {
|
||||||
|
createTheme('light')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Восстановление масштаба
|
// Восстановление масштаба
|
||||||
@@ -33,8 +50,6 @@ window.onload = () => {
|
|||||||
if (inputText) {
|
if (inputText) {
|
||||||
textInput.value = inputText;
|
textInput.value = inputText;
|
||||||
generateQR()
|
generateQR()
|
||||||
} else {
|
|
||||||
localStorage.setItem('userText', '')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,12 +64,13 @@ function changeButtonsColor(color) {
|
|||||||
|
|
||||||
// Изменение темы сайта при клике
|
// Изменение темы сайта при клике
|
||||||
checkbox.addEventListener('change', () => {
|
checkbox.addEventListener('change', () => {
|
||||||
if (checkbox.checked) {
|
const theme = localStorage.getItem('theme')
|
||||||
html.style.backgroundColor = '#fff';
|
if (theme == 'dark') {
|
||||||
changeButtonsColor('#1e1e1e')
|
createTheme('light')
|
||||||
|
localStorage.setItem('theme', 'light')
|
||||||
} else {
|
} else {
|
||||||
html.style.backgroundColor = '#1e1e1e';
|
createTheme('dark')
|
||||||
changeButtonsColor('#fff')
|
localStorage.setItem('theme', 'dark')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user