мНемає опису редагування
мНемає опису редагування
Рядок 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;
        return;
    }
   
    // Перевіряємо чи це мобільна версія
     if (!document.body.classList.contains('skin-minerva')) {
        return;
    }
      
      
     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;
       
        // Використовуємо звичайний перехід замість replace
         setTimeout(() => {
         setTimeout(() => {
             window.location.href = '/w/index.php/Спеціальна:Випадкова_сторінка';
             window.location.href = '/w/index.php/Спеціальна:Випадкова_сторінка';
Рядок 909: Рядок 897:
      
      
     document.body.appendChild(btn);
     document.body.appendChild(btn);
    console.log('Кнопка Випадкова створена зліва');
}
}


// =========================
// =========================
// КНОПКА "ЯК ЦЕ ПРАЦЮЄ?" (для всіх тем)
// КНОПКА "ЯК ЦЕ ПРАЦЮЄ?"
// =========================
// =========================
function createHowItWorksButton() {
function createHowItWorksButton() {
    // Перевіряємо чи кнопка вже існує
     if (document.getElementById('how-it-works-btn')) return;
     if (document.getElementById('how-it-works-btn')) {
        return;
    }
      
      
     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();
       
        // Перехід на сторінку /w/index.php/FAQ
         window.location.href = '/w/index.php/FAQ';
         window.location.href = '/w/index.php/FAQ';
     });
     });
Рядок 967: Рядок 948:
      
      
     document.body.appendChild(btn);
     document.body.appendChild(btn);
}
// =========================
// АДАПТАЦІЯ ДО ЕКРАННОЇ КЛАВІАТУРИ
// =========================
function adjustForKeyboard() {
    const keyboardOffset = 80;
   
    function updateButtonPositions() {
        const randomBtn = document.getElementById('float-random-btn');
        const howBtn = document.getElementById('how-it-works-btn');
       
        if (randomBtn) {
            const currentKeyboardOffset = window.innerHeight < 500 ? 120 : keyboardOffset;
            randomBtn.style.bottom = `${70 + currentKeyboardOffset}px`;
        }
       
        if (howBtn) {
            const currentKeyboardOffset = window.innerHeight < 500 ? 120 : keyboardOffset;
            howBtn.style.bottom = `${140 + currentKeyboardOffset}px`;
        }
    }
   
    window.addEventListener('resize', updateButtonPositions);
    setTimeout(updateButtonPositions, 100);
}
// =========================
// ПОКРАЩЕНЕ ВІДНОВЛЕННЯ КНОПОК ПІСЛЯ ПЕРЕХОДУ
// =========================
function restoreButtons() {
    // Для всіх тем - кнопка "Як це працює?"
    if (!document.getElementById('how-it-works-btn')) {
        createHowItWorksButton();
    }
   
    // Для мобільної версії - кнопка "Випадкова сторінка"
    if (document.body.classList.contains('skin-minerva') && !document.getElementById('float-random-btn')) {
        createRandomButton();
    }
   
    adjustForKeyboard();
}
}


Рядок 1037: Рядок 976:


// =========================
// =========================
// ЗАГАЛЬНИЙ ІНІЦІАЛІЗАТОР
// ПРОСТИЙ ІНІЦІАЛІЗАТОР
// =========================
// =========================
let initialized = false;


// Основний ініціалізатор
function initializeButtons() {
function initializeAll() {
     if (initialized) return;
     restoreButtons();
    initialized = true;
   
    console.log('Ініціалізація кнопок...');
   
    // Кнопка "Як це працює?" для всіх тем
    createHowItWorksButton();
   
    // Кнопка "Випадкова сторінка" тільки для Minerva
     if (document.body.classList.contains('skin-minerva')) {
     if (document.body.classList.contains('skin-minerva')) {
        createRandomButton();
         hideMobileElements();
         hideMobileElements();
     }
     }
}
}


// Ініціалізація при завантаженні DOM
// Тільки один спосіб ініціалізації
document.addEventListener('DOMContentLoaded', function() {
    console.log('DOM завантажено - ініціалізація кнопок');
    initializeAll();
});
 
// Ініціалізація при повному завантаженні сторінки
window.addEventListener('load', function() {
    console.log('Сторінка завантажена - ініціалізація кнопок');
    setTimeout(initializeAll, 100);
});
 
// Ініціалізація при кожному переході між сторінками
window.addEventListener('pageshow', function(event) {
    console.log('Перехід на нову сторінку - відновлення кнопок');
    if (event.persisted) {
        // Сторінка завантажена з кешу браузера
        setTimeout(initializeAll, 50);
    } else {
        // Звичайне завантаження сторінки
        setTimeout(initializeAll, 100);
    }
});
 
// Резервна ініціалізація
setTimeout(function() {
    if (!document.getElementById('how-it-works-btn') ||
        (document.body.classList.contains('skin-minerva') && !document.getElementById('float-random-btn'))) {
        console.log('Резервна ініціалізація кнопок');
        initializeAll();
    }
}, 2000);
 
// Додаткова перевірка після завантаження контенту
if (document.readyState === 'loading') {
if (document.readyState === 'loading') {
     document.addEventListener('DOMContentLoaded', initializeAll);
     document.addEventListener('DOMContentLoaded', initializeButtons);
} else {
} else {
     setTimeout(initializeAll, 100);
     initializeButtons();
}
}
// Тільки один резервний таймер
setTimeout(initializeButtons, 500);