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', | ||
| Рядок 5: | Рядок 6: | ||
}; | }; | ||
// ======================= | |||
// Кнопка Темна/Світла тема | |||
// ======================= | |||
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 $ | var $themeBtn = $('<button>') | ||
.text(theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙') | .text(theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙') | ||
.attr('title', 'Змінити тему') | .attr('title', 'Змінити тему') | ||
| Рядок 22: | Рядок 24: | ||
bottom: '10px', | bottom: '10px', | ||
right: '10px', | right: '10px', | ||
padding: '10px 16px', | padding: '10px 16px', | ||
border: 'none', | border: 'none', | ||
borderRadius: '25px', | borderRadius: '25px', | ||
background: '#1a73e8', | background: '#1a73e8', | ||
color: '#ffffff', | color: '#ffffff', | ||
fontWeight: 'bold', | fontWeight: 'bold', | ||
| Рядок 33: | Рядок 35: | ||
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' | whiteSpace: 'nowrap' | ||
}) | }) | ||
.click(function () { | .click(function () { | ||
| Рядок 41: | Рядок 43: | ||
}); | }); | ||
$('body').append($ | $('body').append($themeBtn); | ||
// ======================= | |||
// Кнопка Доступність | |||
// ======================= | |||
var $accessBtn = $('<button>') | |||
.text('Доступність ♿') | |||
.attr('title', 'Увімкнути режим доступності') | |||
.css({ | |||
position: 'fixed', | |||
bottom: '70px', // над кнопкою теми | |||
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 () { | |||
if (!$('body').hasClass('accessibility-mode')) { | |||
$('body').addClass('accessibility-mode'); | |||
localStorage.setItem('accessibilityMode', 'on'); | |||
} else { | |||
$('body').removeClass('accessibility-mode'); | |||
localStorage.setItem('accessibilityMode', 'off'); | |||
} | |||
}); | |||
$('body').append($accessBtn); | |||
// Вмикаємо збережений режим доступності | |||
if (localStorage.getItem('accessibilityMode') === 'on') { | |||
$('body').addClass('accessibility-mode'); | |||
} | |||
}); | }); | ||
Версія за 15:42, 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 $themeBtn = $('<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($themeBtn);
// =======================
// Кнопка Доступність
// =======================
var $accessBtn = $('<button>')
.text('Доступність ♿')
.attr('title', 'Увімкнути режим доступності')
.css({
position: 'fixed',
bottom: '70px', // над кнопкою теми
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 () {
if (!$('body').hasClass('accessibility-mode')) {
$('body').addClass('accessibility-mode');
localStorage.setItem('accessibilityMode', 'on');
} else {
$('body').removeClass('accessibility-mode');
localStorage.setItem('accessibilityMode', 'off');
}
});
$('body').append($accessBtn);
// Вмикаємо збережений режим доступності
if (localStorage.getItem('accessibilityMode') === 'on') {
$('body').addClass('accessibility-mode');
}
});