57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const form = document.getElementById('config-form');
|
|
const queryInput = document.getElementById('search-query');
|
|
const engineSelect = document.getElementById('search-engine');
|
|
const resultSection = document.getElementById('result-section');
|
|
const generatedLinkInput = document.getElementById('generated-link');
|
|
const copyBtn = document.getElementById('copy-btn');
|
|
const testBtn = document.getElementById('test-btn');
|
|
|
|
form.addEventListener('submit', (e) => {
|
|
e.preventDefault();
|
|
|
|
const query = queryInput.value.trim();
|
|
if (!query) return;
|
|
|
|
const engine = engineSelect.value;
|
|
|
|
// Získání aktuální domény/cesty
|
|
const baseUrl = window.location.href.split('index.html')[0];
|
|
const searchUrl = `${baseUrl}search.html?q=${encodeURIComponent(query)}&engine=${encodeURIComponent(engine)}`;
|
|
|
|
generatedLinkInput.value = searchUrl;
|
|
resultSection.classList.add('active');
|
|
});
|
|
|
|
copyBtn.addEventListener('click', () => {
|
|
generatedLinkInput.select();
|
|
generatedLinkInput.setSelectionRange(0, 99999); /* Pro mobilní zařízení */
|
|
|
|
try {
|
|
navigator.clipboard.writeText(generatedLinkInput.value);
|
|
|
|
// Vizuální zpětná vazba
|
|
const originalHTML = copyBtn.innerHTML;
|
|
copyBtn.innerHTML = `
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#10b981" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<polyline points="20 6 9 17 4 12"></polyline>
|
|
</svg>
|
|
`;
|
|
setTimeout(() => {
|
|
copyBtn.innerHTML = originalHTML;
|
|
}, 2000);
|
|
} catch (err) {
|
|
console.error('Nepodařilo se zkopírovat odkaz: ', err);
|
|
// Fallback pro starší prohlížeče
|
|
document.execCommand('copy');
|
|
}
|
|
});
|
|
|
|
testBtn.addEventListener('click', () => {
|
|
const link = generatedLinkInput.value;
|
|
if (link) {
|
|
window.open(link, '_blank');
|
|
}
|
|
});
|
|
});
|