MediaWiki:Common.js: відмінності між версіями
Перейти до навігації
Перейти до пошуку
Wiki (обговорення | внесок) Немає опису редагування |
Wiki (обговорення | внесок) Немає опису редагування |
||
| Рядок 1: | Рядок 1: | ||
$(function () { | $(function () { | ||
var themes = { | var themes = { | ||
light: '/w/index.php?title=MediaWiki:Light.css&action=raw&ctype=text/css', | light: '/w/index.php?title=MediaWiki:Light.css&action=raw&ctype=text/css', | ||
| Рядок 8: | Рядок 5: | ||
}; | }; | ||
var theme = localStorage.getItem('selectedTheme'); | var theme = localStorage.getItem('selectedTheme'); | ||
if (!theme) { | if (!theme) { | ||
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; | theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; | ||
} | } | ||
if (themes[theme]) { | if (themes[theme]) { | ||
mw.loader.load(themes[theme], 'text/css'); | mw.loader.load(themes[theme], 'text/css'); | ||
} | } | ||
var $btn = $('<button>') | var $btn = $('<button>') | ||
.text(theme === 'dark' ? ' Світла тема ☀️' : ' Темна тема 🌙') | .text(theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙') | ||
.attr('title', 'Змінити тему') | .attr('title', 'Змінити тему') | ||
.css({ | .css({ | ||
| Рядок 29: | Рядок 22: | ||
bottom: '10px', | bottom: '10px', | ||
right: '10px', | right: '10px', | ||
padding: '10px 16px', // більше простору для тексту | |||
padding: ' | |||
border: 'none', | border: 'none', | ||
borderRadius: ' | borderRadius: '25px', // овальна форма | ||
background: '#1a73e8', | background: '#1a73e8', | ||
color: '#ffffff', | color: '#ffffff', | ||
fontWeight: 'bold', | fontWeight: 'bold', | ||
fontSize: '14px', | fontSize: '14px', | ||
| Рядок 41: | Рядок 32: | ||
zIndex: 9999, | zIndex: 9999, | ||
textAlign: 'center', | textAlign: 'center', | ||
boxShadow: '0 2px 6px rgba(0,0,0,0.3)', | |||
boxShadow: '0 2px 6px rgba(0,0,0,0.3)' | whiteSpace: 'nowrap' // текст не переноситься | ||
}) | }) | ||
.click(function () { | .click(function () { | ||
var newTheme = theme === 'dark' ? 'light' : 'dark'; | var newTheme = theme === 'dark' ? 'light' : 'dark'; | ||
localStorage.setItem('selectedTheme', newTheme); | localStorage.setItem('selectedTheme', newTheme); | ||
Версія за 15:21, 23 вересня 2025
$(function () {
var themes = {
light: '/w/index.php?title=MediaWiki:Light.css&action=raw&ctype=text/css',
dark: '/w/index.php?title=MediaWiki:Dark.css&action=raw&ctype=text/css'
};
var theme = localStorage.getItem('selectedTheme');
if (!theme) {
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
if (themes[theme]) {
mw.loader.load(themes[theme], 'text/css');
}
var $btn = $('<button>')
.text(theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙')
.attr('title', 'Змінити тему')
.css({
position: 'fixed',
bottom: '10px',
right: '10px',
padding: '10px 16px', // більше простору для тексту
border: 'none',
borderRadius: '25px', // овальна форма
background: '#1a73e8',
color: '#ffffff',
fontWeight: 'bold',
fontSize: '14px',
cursor: 'pointer',
zIndex: 9999,
textAlign: 'center',
boxShadow: '0 2px 6px rgba(0,0,0,0.3)',
whiteSpace: 'nowrap' // текст не переноситься
})
.click(function () {
var newTheme = theme === 'dark' ? 'light' : 'dark';
localStorage.setItem('selectedTheme', newTheme);
location.reload();
});
$('body').append($btn);
});