|
97 | 97 | const LANGS = ['en','ru','hi','es']; |
98 | 98 | const LANG_NAMES = { en:'English', ru:'Русский', hi:'हिन्दी', es:'Español' }; |
99 | 99 | let currentLang = 'en'; |
| 100 | + function showToast(message, duration) { |
| 101 | + duration = duration || 3000; |
| 102 | + let container = document.querySelector('.toast-container'); |
| 103 | + if (!container) { |
| 104 | + container = document.createElement('div'); |
| 105 | + container.className = 'toast-container'; |
| 106 | + container.setAttribute('role', 'region'); |
| 107 | + container.setAttribute('aria-label', 'Notifications'); |
| 108 | + document.body.appendChild(container); |
| 109 | + } |
| 110 | + const toast = document.createElement('div'); |
| 111 | + toast.className = 'toast'; |
| 112 | + toast.setAttribute('role', 'alert'); |
| 113 | + toast.setAttribute('aria-live', 'polite'); |
| 114 | + toast.textContent = message; |
| 115 | + container.appendChild(toast); |
| 116 | + requestAnimationFrame(() => requestAnimationFrame(() => toast.classList.add('visible'))); |
| 117 | + setTimeout(() => { |
| 118 | + toast.classList.remove('visible'); |
| 119 | + setTimeout(() => toast.remove(), 300); |
| 120 | + }, duration); |
| 121 | + } |
100 | 122 | const translations = { |
101 | 123 | en: { |
102 | 124 | ctaFooter: '⚡ GET FULL REPORT IN TELEGRAM', |
|
332 | 354 | document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active')); |
333 | 355 | document.getElementById(`lang-${lang}`)?.classList.add('active'); |
334 | 356 | const t = translations[lang]; |
335 | | - document.getElementById('cta-footer').innerHTML = t.ctaFooter; |
| 357 | + document.getElementById('cta-footer').textContent = t.ctaFooter; |
336 | 358 | if (!window.currentQuizState) renderApp(); |
337 | 359 | else if (window.currentQuizState === 'quiz') renderApp(); |
338 | 360 | else if (window.currentQuizState === 'result') renderResult(); |
|
442 | 464 | const t = translations[currentLang]; |
443 | 465 | const questionText = q[`text${currentLang.charAt(0).toUpperCase()+currentLang.slice(1)}`] || q.textEn; |
444 | 466 | const options = q[`options${currentLang.charAt(0).toUpperCase()+currentLang.slice(1)}`] || q.optionsEn; |
445 | | - const optsHtml = options.map((opt, idx) => `<button class="option-btn" data-opt="${idx}" type="button">${opt}</button>`).join(''); |
| 467 | + const optsHtml = options.map((opt, idx) => `<button class="option-btn" data-opt="${idx}" type="button" role="radio" aria-checked="false">${opt}</button>`).join(''); |
446 | 468 | app.innerHTML = ` |
447 | 469 | <div class="card"> |
448 | 470 | <div class="progress-bar"><div class="progress-fill" style="width:${(currentQuestion/QUESTIONS.length)*100}%"></div></div> |
449 | | - <div class="question-text">${questionText}</div> |
450 | | - <div class="options">${optsHtml}</div> |
| 471 | + <div class="question-text" id="questionLabel">${questionText}</div> |
| 472 | + <div class="options" role="radiogroup" aria-labelledby="questionLabel">${optsHtml}</div> |
451 | 473 | <button class="btn-primary" id="nextBtn">${currentQuestion === QUESTIONS.length-1 ? t.result : t.next}</button> |
452 | 474 | </div>`; |
453 | 475 | document.querySelectorAll('.option-btn').forEach(btn => { |
454 | 476 | btn.addEventListener('click', () => { |
455 | | - document.querySelectorAll('.option-btn').forEach(b => b.classList.remove('selected')); |
| 477 | + document.querySelectorAll('.option-btn').forEach(b => { b.classList.remove('selected'); b.setAttribute('aria-checked', 'false'); }); |
456 | 478 | btn.classList.add('selected'); |
| 479 | + btn.setAttribute('aria-checked', 'true'); |
457 | 480 | answers[currentQuestion] = parseInt(btn.dataset.opt); |
458 | 481 | }); |
459 | 482 | }); |
|
568 | 591 | setTimeout(() => URL.revokeObjectURL(url), 1000); |
569 | 592 | } catch (e) { |
570 | 593 | if (navigator.share) { navigator.share({ title: 'AstroScan Result', url: window.location.href }); } |
571 | | - else { alert(t.copyLink); } |
| 594 | + else { showToast(t.copyLink); } |
572 | 595 | } |
573 | 596 | }); |
574 | 597 | function getTrackerData() { |
|
0 commit comments