MediaWiki:Common.js
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5.
$(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');
}
});