Files
2026-05-21 18:23:28 +02:00

95 lines
3.3 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('q');
const engine = urlParams.get('engine') || 'google';
const inputField = document.getElementById('fake-input');
const cursor = document.getElementById('fake-cursor');
const searchBtn = document.getElementById('btn-submit');
const statusMsg = document.getElementById('status-msg');
if (!query) {
window.location.href = 'index.html';
return;
}
const searchEngines = {
'google': 'https://www.google.com/search?q=',
'bing': 'https://www.bing.com/search?q=',
'duckduckgo': 'https://duckduckgo.com/?q=',
'seznam': 'https://search.seznam.cz/?q='
};
const targetUrl = (searchEngines[engine] || searchEngines['google']) + encodeURIComponent(query);
// Pomocná funkce pro čekání
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
// Funkce pro přesun kurzoru
const moveCursorTo = (element, offsetX = 0, offsetY = 0) => {
const rect = element.getBoundingClientRect();
// Přesun do středu elementu + offset
const top = rect.top + (rect.height / 2) + offsetY;
const left = rect.left + (rect.width / 2) + offsetX;
cursor.style.top = `${top}px`;
cursor.style.left = `${left}px`;
};
// Hlavní sekvence animace
const runAnimation = async () => {
await wait(1000);
statusMsg.textContent = 'Step 1: Move to search field...';
// 1. Přesun kurzoru na input (offset trochu doleva)
cursor.style.transition = 'all 1s cubic-bezier(0.4, 0, 0.2, 1)';
moveCursorTo(inputField, -100, 0);
await wait(1200);
// Simulace kliknutí do inputu
inputField.style.borderColor = '#4285f4';
inputField.style.boxShadow = '0 0 0 1px #4285f4';
statusMsg.textContent = 'Step 2: Typing...';
await wait(500);
// 2. Psaní textu
cursor.style.transition = 'all 0.1s linear'; // pro psaní není potřeba dlouhá animace kurzoru, ale může se jemně třást
for (let i = 0; i < query.length; i++) {
inputField.value += query.charAt(i);
// Malý náhodný pohyb kurzoru při psaní
moveCursorTo(inputField, -100 + (i * 2), (Math.random() * 4) - 2);
await wait(100 + Math.random() * 100); // Náhodná rychlost psaní (100-200ms)
}
await wait(500);
inputField.style.borderColor = '#dfe1e5';
inputField.style.boxShadow = 'none';
// 3. Přesun kurzoru na tlačítko "Vyhledat"
statusMsg.textContent = 'Step 3: Click the button...';
cursor.style.transition = 'all 1s cubic-bezier(0.4, 0, 0.2, 1)';
moveCursorTo(searchBtn);
await wait(1200);
// 4. Simulace hover a kliknutí na tlačítko
searchBtn.classList.add('active');
cursor.style.transform = 'scale(0.9)'; // efekt stisknutí
await wait(300);
searchBtn.classList.remove('active');
cursor.style.transform = 'scale(1)';
statusMsg.textContent = 'Redirecting...';
await wait(500);
// 5. Přesměrování
window.location.href = targetUrl;
};
// Spuštění animace
runAnimation();
});