MediaWiki:Vector.js: различия между версиями
Aylong (обсуждение | вклад) Нет описания правки Метка: отменено |
Aylong (обсуждение | вклад) Нет описания правки Метка: отменено |
||
| Строка 1: | Строка 1: | ||
$( | $(document).ready(function() { | ||
var button = document.createElement("button"); | var button = document.createElement("button"); | ||
button.innerHTML = "Сменить тему"; | button.innerHTML = "Сменить тему"; | ||
| Строка 15: | Строка 8: | ||
if (container) { | if (container) { | ||
container.parentNode.insertBefore(button, container); | container.parentNode.insertBefore(button, container); | ||
} | |||
var isLightTheme = localStorage.getItem("isLightTheme"); | |||
if (isLightTheme === "true") { | |||
setLightTheme(); | |||
} else { | |||
setDarkTheme(); | |||
} | } | ||
}); | }); | ||
function toggleTheme() { | function toggleTheme() { | ||
var isLightTheme = localStorage.getItem("isLightTheme"); | |||
if (isLightTheme === "true") { | |||
setDarkTheme(); | |||
root. | localStorage.setItem("isLightTheme", "false"); | ||
} else { | |||
setLightTheme(); | |||
localStorage.setItem("isLightTheme", "true"); | |||
} | |||
} | |||
function setLightTheme() { | |||
var root = document.documentElement; | |||
root.style.setProperty('--color-fg', '#252525'); | |||
root.style.setProperty('--color-bg', '#ffffff'); | |||
} | |||
function setDarkTheme() { | |||
var root = document.documentElement; | |||
root.style.setProperty('--color-fg', '#ffffff'); | |||
root.style.setProperty('--color-bg', '#252525'); | |||
} | } | ||
Версия от 17:15, 4 мая 2024
$(document).ready(function() {
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);
}
var isLightTheme = localStorage.getItem("isLightTheme");
if (isLightTheme === "true") {
setLightTheme();
} else {
setDarkTheme();
}
});
function toggleTheme() {
var isLightTheme = localStorage.getItem("isLightTheme");
if (isLightTheme === "true") {
setDarkTheme();
localStorage.setItem("isLightTheme", "false");
} else {
setLightTheme();
localStorage.setItem("isLightTheme", "true");
}
}
function setLightTheme() {
var root = document.documentElement;
root.style.setProperty('--color-fg', '#252525');
root.style.setProperty('--color-bg', '#ffffff');
}
function setDarkTheme() {
var root = document.documentElement;
root.style.setProperty('--color-fg', '#ffffff');
root.style.setProperty('--color-bg', '#252525');
}