MediaWiki:Common.js: відмінності між версіями
Wiki (обговорення | внесок) мНемає опису редагування |
Wiki (обговорення | внесок) мНемає опису редагування |
||
| Рядок 841: | Рядок 841: | ||
// ========================= | // ========================= | ||
// ========================= | /// ========================= | ||
// КНОПКА ВИПАДКОВА СТОРІНКА | // КНОПКА ВИПАДКОВА СТОРІНКА | ||
// ========================= | // ========================= | ||
function createRandomButton() { | function createRandomButton() { | ||
if (document.getElementById('float-random-btn')) return; | |||
if (document.getElementById('float-random-btn')) | if (!document.body.classList.contains('skin-minerva')) return; | ||
if (!document.body.classList.contains('skin-minerva')) | |||
const btn = document.createElement('button'); | const btn = document.createElement('button'); | ||
| Рядок 880: | Рядок 873: | ||
`; | `; | ||
btn.addEventListener('click', function(e) { | btn.addEventListener('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
btn.innerHTML = '⏳ Завантаження...'; | btn.innerHTML = '⏳ Завантаження...'; | ||
btn.style.opacity = '0.7'; | btn.style.opacity = '0.7'; | ||
btn.disabled = true; | btn.disabled = true; | ||
setTimeout(() => { | setTimeout(() => { | ||
window.location.href = '/w/index.php/Спеціальна:Випадкова_сторінка'; | window.location.href = '/w/index.php/Спеціальна:Випадкова_сторінка'; | ||
| Рядок 909: | Рядок 897: | ||
document.body.appendChild(btn); | document.body.appendChild(btn); | ||
} | } | ||
// ========================= | // ========================= | ||
// КНОПКА "ЯК ЦЕ ПРАЦЮЄ?" | // КНОПКА "ЯК ЦЕ ПРАЦЮЄ?" | ||
// ========================= | // ========================= | ||
function createHowItWorksButton() { | function createHowItWorksButton() { | ||
if (document.getElementById('how-it-works-btn')) return; | |||
if (document.getElementById('how-it-works-btn')) | |||
const btn = document.createElement('button'); | const btn = document.createElement('button'); | ||
| Рядок 947: | Рядок 931: | ||
`; | `; | ||
btn.addEventListener('click', function(e) { | btn.addEventListener('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
window.location.href = '/w/index.php/FAQ'; | window.location.href = '/w/index.php/FAQ'; | ||
}); | }); | ||
| Рядок 967: | Рядок 948: | ||
document.body.appendChild(btn); | document.body.appendChild(btn); | ||
} | } | ||
| Рядок 1037: | Рядок 976: | ||
// ========================= | // ========================= | ||
// | // ПРОСТИЙ ІНІЦІАЛІЗАТОР | ||
// ========================= | // ========================= | ||
let initialized = false; | |||
function initializeButtons() { | |||
function | if (initialized) return; | ||
initialized = true; | |||
console.log('Ініціалізація кнопок...'); | |||
// Кнопка "Як це працює?" для всіх тем | |||
createHowItWorksButton(); | |||
// Кнопка "Випадкова сторінка" тільки для Minerva | |||
if (document.body.classList.contains('skin-minerva')) { | if (document.body.classList.contains('skin-minerva')) { | ||
createRandomButton(); | |||
hideMobileElements(); | hideMobileElements(); | ||
} | } | ||
} | } | ||
// | // Тільки один спосіб ініціалізації | ||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', | document.addEventListener('DOMContentLoaded', initializeButtons); | ||
} else { | } else { | ||
initializeButtons(); | |||
} | } | ||
// Тільки один резервний таймер | |||
setTimeout(initializeButtons, 500); | |||