мНемає опису редагування
мНемає опису редагування
 
(Не показані 4 проміжні версії цього користувача)
Рядок 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');
Рядок 861: Рядок 853:
     btn.style.cssText = `
     btn.style.cssText = `
         position: fixed;
         position: fixed;
         bottom: 70px;
         bottom: 240px;
         left: 15px;
         left: 15px;
         z-index: 9998;
         z-index: 9998;
Рядок 880: Рядок 872:
     `;
     `;
      
      
    // ВИПРАВЛЕНИЙ ОБРОБНИК КЛІКУ
     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: Рядок 896:
      
      
     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: Рядок 930:
     `;
     `;
      
      
    // Обробник для кнопки "Як це працює?"
     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';
     });
     });
Рядок 970: Рядок 950:


// =========================
// =========================
// АДАПТАЦІЯ ДО ЕКРАННОЇ КЛАВІАТУРИ
// ВИПРАВЛЕНА ІНІЦІАЛІЗАЦІЯ (замінити тільки цю частину)
// =========================
// =========================
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);
}


// =========================
// Видаляємо всі старі ініціалізатори і замінюємо на цей простий код:
// ПОКРАЩЕНЕ ВІДНОВЛЕННЯ КНОПОК ПІСЛЯ ПЕРЕХОДУ
 
// =========================
let buttonsInitialized = false;
function restoreButtons() {
 
    // Для всіх тем - кнопка "Як це працює?"
function initializeLeftButtons() {
     if (!document.getElementById('how-it-works-btn')) {
     if (buttonsInitialized) return;
        createHowItWorksButton();
     buttonsInitialized = true;
     }
   
    // Для мобільної версії - кнопка "Випадкова сторінка"
    if (document.body.classList.contains('skin-minerva') && !document.getElementById('float-random-btn')) {
        createRandomButton();
    }
      
      
     adjustForKeyboard();
     // Кнопка "Як це працює?" для всіх тем
}
     createHowItWorksButton();
 
// =========================
// ПРИХОВАННЯ ЕЛЕМЕНТІВ У МОБІЛЬНІЙ ВЕРСІЇ
// =========================
function hideMobileElements() {
     if (!document.body.classList.contains('skin-minerva')) return;
      
      
     setTimeout(() => {
     // Кнопка "Випадкова сторінка" тільки для Minerva
        const elements = document.querySelectorAll('*');
        elements.forEach(element => {
            if (element.textContent && element.textContent.includes('Відмова')) {
                element.style.display = 'none';
                const parentLi = element.closest('li');
                if (parentLi) parentLi.style.display = 'none';
            }
        });
       
        const links = document.querySelectorAll('a[href*="%D0%92%D1%96%D0%B4%D0%BC%D0%BE%D0%B2%D0%B0"]');
        links.forEach(link => {
            link.style.display = 'none';
            const parentLi = link.closest('li');
            if (parentLi) parentLi.style.display = 'none';
        });
    }, 1000);
}
 
// =========================
// ЗАГАЛЬНИЙ ІНІЦІАЛІЗАТОР
// =========================
 
// Основний ініціалізатор
function initializeAll() {
    restoreButtons();
     if (document.body.classList.contains('skin-minerva')) {
     if (document.body.classList.contains('skin-minerva')) {
         hideMobileElements();
         createRandomButton();
     }
     }
}
}


// Ініціалізація при завантаженні 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', initializeLeftButtons);
} else {
} else {
     setTimeout(initializeAll, 100);
     setTimeout(initializeLeftButtons, 100);
}
}
// Тільки один резервний таймер
setTimeout(initializeLeftButtons, 1000);