MediaWiki:Vector.js: различия между версиями
Aylong (обсуждение | вклад) Нет описания правки Метка: отменено |
Aylong (обсуждение | вклад) Отмена правки 72140, сделанной Aylong (обсуждение) Метки: отмена отменено |
||
| Строка 1: | Строка 1: | ||
function | $(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 | 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'); | |||
} | } | ||
Версия от 17:21, 4 мая 2024
$(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');
}