мНемає опису редагування
мНемає опису редагування
 
(Не показано 5 проміжних версій цього користувача)
Рядок 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');
Рядок 860: Рядок 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;
Рядок 879: Рядок 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;
       
        // Використовуємо window.location.replace для чистого переходу
         setTimeout(() => {
         setTimeout(() => {
             window.location.replace('/w/index.php/Спеціальна:Випадкова_сторінка');
             window.location.href = '/w/index.php/Спеціальна:Випадкова_сторінка';
         }, 100);
         }, 100);
     });
     });
Рядок 908: Рядок 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');
Рядок 946: Рядок 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';
     });
     });
Рядок 969: Рядок 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 restoreRandomButton() {
    // Перевіряємо чи ми на випадковій сторінці
    const isRandomPage = window.location.href.includes('Випадкова_сторінка') ||
                        window.location.href.includes('Special:Random');
   
    if (isRandomPage && document.body.classList.contains('skin-minerva')) {
        // Чекаємо повного завантаження сторінки
        setTimeout(() => {
            if (!document.getElementById('float-random-btn')) {
                createRandomButton();
            }
        }, 500);
    }
}


// =========================
function initializeLeftButtons() {
// ПРИХОВАННЯ ЕЛЕМЕНТІВ У МОБІЛЬНІЙ ВЕРСІЇ
     if (buttonsInitialized) return;
// =========================
    buttonsInitialized = true;
function hideMobileElements() {
     if (!document.body.classList.contains('skin-minerva')) return;
      
      
     setTimeout(() => {
     // Кнопка "Як це працює?" для всіх тем
        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);
}
 
// =========================
// ЗАГАЛЬНИЙ ІНІЦІАЛІЗАТОР
// =========================
document.addEventListener('DOMContentLoaded', function() {
    // Для всіх тем - кнопка "Як це працює?"
     createHowItWorksButton();
     createHowItWorksButton();
      
      
     // Для мобільної версії
     // Кнопка "Випадкова сторінка" тільки для Minerva
     if (document.body.classList.contains('skin-minerva')) {
     if (document.body.classList.contains('skin-minerva')) {
        hideMobileElements();
         createRandomButton();
         createRandomButton();
     }
     }
   
}
    adjustForKeyboard();
   
    setTimeout(() => {
        if (!document.getElementById('how-it-works-btn')) {
            createHowItWorksButton();
        }
        if (document.body.classList.contains('skin-minerva') && !document.getElementById('float-random-btn')) {
            createRandomButton();
        }
        adjustForKeyboard();
        hideMobileElements();
    }, 2000);
});


window.addEventListener('load', function() {
// Тільки один спосіб ініціалізації
    if (document.body.classList.contains('skin-minerva')) {
if (document.readyState === 'loading') {
        setTimeout(createRandomButton, 500);
     document.addEventListener('DOMContentLoaded', initializeLeftButtons);
    }
} else {
     setTimeout(createHowItWorksButton, 500);
     setTimeout(initializeLeftButtons, 100);
    adjustForKeyboard();
}
});
 
setTimeout(function() {
    if (document.body.classList.contains('skin-minerva') && !document.getElementById('float-random-btn')) {
        createRandomButton();
    }
    if (!document.getElementById('how-it-works-btn')) {
        createHowItWorksButton();
     }
    adjustForKeyboard();
}, 3000);


// Відновлюємо кнопки після переходу
// Тільки один резервний таймер
window.addEventListener('pageshow', restoreRandomButton);
setTimeout(initializeLeftButtons, 1000);