|
Метки: очистка ручная отмена |
(не показано 75 промежуточных версий этого же участника) |
Строка 1: |
Строка 1: |
| $(window).on("load", function() {
| |
| var isLightTheme = localStorage.getItem("isLightTheme");
| |
| if (isLightTheme === "true") {
| |
| document.documentElement.setAttribute('data-theme', 'light');
| |
| } else {
| |
| document.documentElement.setAttribute('data-theme', 'dark');
| |
| }
| |
|
| |
|
| var button = document.createElement("button");
| |
| button.innerHTML = "Сменить тему";
| |
| button.className = "theme-button";
| |
| button.onclick = toggleTheme;
| |
|
| |
| var container = document.getElementById("p-personal");
| |
| if (container) {
| |
| container.parentNode.insertBefore(button, container);
| |
| }
| |
| });
| |
|
| |
| function toggleTheme() {
| |
| const root = document.documentElement;
| |
| const currentTheme = root.getAttribute('data-theme');
| |
| const newTheme = currentTheme === 'light' ? 'dark' : 'light';
| |
| root.setAttribute('data-theme', newTheme);
| |
|
| |
| localStorage.setItem("isLightTheme", newTheme === 'light');
| |
| }
| |