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', | ||
| Рядок 12: | Рядок 10: | ||
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'); | ||
function createButton(text, bottom, onClick, title) { | function createButton(text, bottom, onClick, title) { | ||
var $btn = $('<button>').text(text).attr('title', title).css({ | var $btn = $('<button>').text(text).attr('title', title).css({ | ||
| Рядок 41: | Рядок 34: | ||
} | } | ||
// Кнопка Темна/Світла тема | // Кнопка Темна/Світла тема | ||
var $themeBtn = createButton( | var $themeBtn = createButton( | ||
theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙', | theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙', | ||
| Рядок 55: | Рядок 46: | ||
); | ); | ||
// Кнопка доступності | |||
// Кнопка | var accessClass = theme === 'dark' ? 'accessibility-mode-dark' : 'accessibility-mode-light'; | ||
var storageKey = theme === 'dark' ? 'accessibilityModeDark' : 'accessibilityModeLight'; | |||
var $accessBtn = createButton( | |||
'Доступність ♿', | |||
70, | |||
function () { | |||
if (!$('body').hasClass(accessClass)) { | |||
$('body').addClass(accessClass); | |||
localStorage.setItem(storageKey, 'on'); | |||
} else { | |||
$('body').removeClass(accessClass); | |||
localStorage.setItem(storageKey, 'off'); | |||
} | |||
}, | |||
'Увімкнути режим доступності' | |||
); | |||
if (localStorage.getItem(storageKey) === 'on') $('body').addClass(accessClass); | |||
// Лупа | |||
// Лупа | |||
var fontSize = parseInt($('body').css('font-size'), 10); | var fontSize = parseInt($('body').css('font-size'), 10); | ||
| Рядок 97: | Рядок 83: | ||
}, 'Зменшити шрифт'); | }, 'Зменшити шрифт'); | ||
if (localStorage.getItem('fontSize')) { | if (localStorage.getItem('fontSize')) { | ||
fontSize = parseInt(localStorage.getItem('fontSize'), 10); | fontSize = parseInt(localStorage.getItem('fontSize'), 10); | ||
Версія за 16:10, 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');
function createButton(text, bottom, onClick, title) {
var $btn = $('<button>').text(text).attr('title', title).css({
position: 'fixed',
bottom: bottom + 'px',
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(onClick);
$('body').append($btn);
return $btn;
}
// Кнопка Темна/Світла тема
var $themeBtn = createButton(
theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙',
10,
function () {
var newTheme = theme === 'dark' ? 'light' : 'dark';
localStorage.setItem('selectedTheme', newTheme);
location.reload();
},
'Змінити тему'
);
// Кнопка доступності
var accessClass = theme === 'dark' ? 'accessibility-mode-dark' : 'accessibility-mode-light';
var storageKey = theme === 'dark' ? 'accessibilityModeDark' : 'accessibilityModeLight';
var $accessBtn = createButton(
'Доступність ♿',
70,
function () {
if (!$('body').hasClass(accessClass)) {
$('body').addClass(accessClass);
localStorage.setItem(storageKey, 'on');
} else {
$('body').removeClass(accessClass);
localStorage.setItem(storageKey, 'off');
}
},
'Увімкнути режим доступності'
);
if (localStorage.getItem(storageKey) === 'on') $('body').addClass(accessClass);
// Лупа
var fontSize = parseInt($('body').css('font-size'), 10);
createButton('🔍 +', 130, function () {
fontSize += 2;
$('body').css('font-size', fontSize + 'px');
localStorage.setItem('fontSize', fontSize);
}, 'Збільшити шрифт');
createButton('🔍 -', 170, function () {
fontSize -= 2;
if (fontSize < 12) fontSize = 12;
$('body').css('font-size', fontSize + 'px');
localStorage.setItem('fontSize', fontSize);
}, 'Зменшити шрифт');
if (localStorage.getItem('fontSize')) {
fontSize = parseInt(localStorage.getItem('fontSize'), 10);
$('body').css('font-size', fontSize + 'px');
}
});