From 944b779fcdcb14564dc2ebb76599a368cb3f3c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enes=20Yak=C4=B1=C5=9Ft=C4=B1r?= Date: Mon, 2 Nov 2026 14:39:11 +0300 Subject: [PATCH] feat(a11y): add NLnet WCAG 2.2 AAA suite (Audio-only blank mode, live transcript reader, clean fediverse share, focus trap and F6 landmarks) (v1.7.4) --- client.js | 474 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- style.css | 149 ++++++++++++++++ 3 files changed, 624 insertions(+), 1 deletion(-) diff --git a/client.js b/client.js index b2a9f10..27aaa06 100644 --- a/client.js +++ b/client.js @@ -1077,6 +1077,435 @@ try { } // 3. Screen-Reader & Turkish Q Optimized Shortcuts & Player Bar (v1.4.1) + // YakTube NLnet WCAG 2.2 AAA & Privacy Suite Modules + +// ============================================================================ +// 1. WCAG 2.2 AAA Focus Trap & Modal Management +// ============================================================================ +var lastActiveElementBeforeModal = null; + +function trapFocusInModal(modalEl) { + if (!modalEl) return; + var focusableElements = modalEl.querySelectorAll( + 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])' + ); + if (!focusableElements.length) return; + var firstFocusable = focusableElements[0]; + var lastFocusable = focusableElements[focusableElements.length - 1]; + + function handleKeydown(e) { + if (e.key !== 'Tab') return; + if (e.shiftKey) { + if (document.activeElement === firstFocusable) { + e.preventDefault(); + lastFocusable.focus(); + } + } else { + if (document.activeElement === lastFocusable) { + e.preventDefault(); + firstFocusable.focus(); + } + } + } + + modalEl.removeEventListener('keydown', modalEl._trapHandler); + modalEl._trapHandler = handleKeydown; + modalEl.addEventListener('keydown', handleKeydown); + setTimeout(function () { + firstFocusable.focus(); + }, 50); +} + +function recordFocusBeforeModal() { + lastActiveElementBeforeModal = document.activeElement; +} + +function restoreFocusAfterModal() { + if (lastActiveElementBeforeModal && typeof lastActiveElementBeforeModal.focus === 'function') { + try { + lastActiveElementBeforeModal.focus(); + } catch (e) {} + } +} + +// ============================================================================ +// 2. Audio-Only & Screen Blank Mode (NLnet Privacy & Bandwidth Shield) +// ============================================================================ +var isAudioOnlyMode = false; +var wakeLockSentinel = null; + +async function requestScreenWakeLock() { + try { + if ('wakeLock' in navigator) { + wakeLockSentinel = await navigator.wakeLock.request('screen'); + wakeLockSentinel.addEventListener('release', function () { + wakeLockSentinel = null; + }); + } + } catch (err) { + console.warn('[YakTube] WakeLock error:', err); + } +} + +function releaseScreenWakeLock() { + if (wakeLockSentinel) { + wakeLockSentinel.release().catch(function () {}); + wakeLockSentinel = null; + } +} + +function toggleAudioOnlyMode() { + var video = getVideoElement(); + if (!video) { + announce('Aktif video bulunamadı.'); + return; + } + + isAudioOnlyMode = !isAudioOnlyMode; + document.body.classList.toggle('yaktube-audio-only-active', isAudioOnlyMode); + + var overlay = document.getElementById('yaktube-audio-blank-overlay'); + var audioBtn = document.getElementById('yaktube-bar-audio-btn'); + + if (isAudioOnlyMode) { + if (!overlay) { + overlay = document.createElement('div'); + overlay.id = 'yaktube-audio-blank-overlay'; + overlay.className = 'yaktube-audio-blank-overlay'; + overlay.setAttribute('role', 'region'); + overlay.setAttribute('aria-label', 'Yalnızca Ses ve Ekran Karartma Modu'); + overlay.innerHTML = + '
' + + '
📻
' + + '

Yalnızca Ses Modu Aktif

' + + '

Ekran pil ve veri tasarrufu için karartıldı. Arka planda çalma desteklenir.

' + + '
' + + '' + + '' + + '
' + + '
'; + + var exitBtn = overlay.querySelector('#yaktube-exit-audio-btn'); + if (exitBtn) { + exitBtn.addEventListener('click', toggleAudioOnlyMode); + } + var togglePlayBtn = overlay.querySelector('#yaktube-toggle-play-audio-btn'); + if (togglePlayBtn) { + togglePlayBtn.addEventListener('click', function () { + var v = getVideoElement(); + if (v) { + if (v.paused) v.play(); else v.pause(); + } + }); + } + document.body.appendChild(overlay); + } + overlay.style.display = 'flex'; + requestScreenWakeLock(); + if (audioBtn) { + audioBtn.classList.add('active'); + audioBtn.setAttribute('aria-pressed', 'true'); + } + announce('Yalnızca ses modu açıldı. Ekran karartıldı, pil ve veri tasarrufu aktif. Çıkmak için Alt+O tuşuna basın.'); + showQuickToast('📻 Yalnızca Ses Modu Açık'); + } else { + if (overlay) overlay.style.display = 'none'; + releaseScreenWakeLock(); + if (audioBtn) { + audioBtn.classList.remove('active'); + audioBtn.setAttribute('aria-pressed', 'false'); + } + announce('Yalnızca ses modu kapatıldı. Görüntü normale döndü.'); + showQuickToast('🎬 Normal Görüntü Modu'); + } +} + +// ============================================================================ +// 3. Accessible Live Transcript Reader (NLnet WCAG 2.2 AAA Milestone) +// ============================================================================ +var liveTranscriptCues = []; +var isTranscriptPanelOpen = false; + +function extractVideoCaptions() { + var video = getVideoElement(); + if (!video || !video.textTracks || !video.textTracks.length) return []; + + var cuesList = []; + for (var i = 0; i < video.textTracks.length; i++) { + var track = video.textTracks[i]; + if (track.cues && track.cues.length) { + for (var j = 0; j < track.cues.length; j++) { + var cue = track.cues[j]; + cuesList.push({ + startTime: cue.startTime, + endTime: cue.endTime, + text: (cue.text || '').replace(/<[^>]*>/g, '').trim() + }); + } + break; + } + } + return cuesList; +} + +function openTranscriptPanel() { + var existing = document.getElementById('yaktube-transcript-panel'); + if (existing) { + existing.remove(); + isTranscriptPanelOpen = false; + restoreFocusAfterModal(); + announce('Transkript paneli kapatıldı.'); + return; + } + + recordFocusBeforeModal(); + isTranscriptPanelOpen = true; + + var cues = extractVideoCaptions(); + var video = getVideoElement(); + var curTime = video ? video.currentTime : 0; + + var panel = document.createElement('div'); + panel.id = 'yaktube-transcript-panel'; + panel.className = 'yaktube-transcript-panel'; + panel.setAttribute('role', 'region'); + panel.setAttribute('aria-label', 'Video Transkript ve Canlı Metin İnceleyici'); + + var listHtml = ''; + if (cues && cues.length) { + liveTranscriptCues = cues; + cues.forEach(function (c, idx) { + var isActive = curTime >= c.startTime && curTime <= c.endTime; + listHtml += + '
  • ' + + '' + formatTime(c.startTime) + '' + + '' + c.text + '' + + '
  • '; + }); + } else { + listHtml = + '
    ' + + '

    📄 Bu video için otomatik altyazı veya transkript henüz hazır değil.

    ' + + '

    Video oynatıcısındaki Altyazı (CC) butonunu açarak dili seçebilirsiniz.

    ' + + '
    '; + } + + panel.innerHTML = + '
    ' + + '
    ' + + '📜' + + '

    Video Transkripti

    ' + + '
    ' + + '
    ' + + '' + + '' + + '
    ' + + '
    ' + + ''; + + var closeBtn = panel.querySelector('#yaktube-transcript-close'); + if (closeBtn) { + closeBtn.addEventListener('click', function () { + panel.remove(); + isTranscriptPanelOpen = false; + restoreFocusAfterModal(); + }); + } + + // Click on cue to jump video + panel.querySelectorAll('.yaktube-transcript-item').forEach(function (item) { + function jumpToCue() { + var start = parseFloat(item.getAttribute('data-start')); + var v = getVideoElement(); + if (v && !isNaN(start)) { + v.currentTime = start; + if (v.paused) v.play(); + announce(formatTime(start) + ' konumuna gidildi: ' + item.querySelector('.yaktube-transcript-text').textContent); + } + } + item.addEventListener('click', jumpToCue); + item.addEventListener('keydown', function (e) { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + jumpToCue(); + } + }); + }); + + // Live search in transcript + var searchInp = panel.querySelector('#yaktube-transcript-search'); + if (searchInp) { + searchInp.addEventListener('input', function (e) { + var query = (e.target.value || '').toLowerCase().trim(); + panel.querySelectorAll('.yaktube-transcript-item').forEach(function (item) { + var txt = (item.querySelector('.yaktube-transcript-text').textContent || '').toLowerCase(); + item.style.display = txt.includes(query) ? 'flex' : 'none'; + }); + }); + } + + var targetWrap = document.querySelector( + '#video-wrapper, #videojs-wrapper, .player-container, my-video-watch .player' + ); + if (targetWrap && targetWrap.parentNode) { + targetWrap.parentNode.insertBefore(panel, targetWrap.nextSibling); + } else { + document.body.appendChild(panel); + } + + trapFocusInModal(panel); + announce('Transkript paneli açıldı. ' + (cues.length ? cues.length + ' satır metin bulundu.' : 'Altyazı bulunamadı.')); +} + +// Sync transcript highlight with current video time +setInterval(function () { + if (!isTranscriptPanelOpen) return; + var video = getVideoElement(); + if (!video) return; + var curTime = video.currentTime; + var panel = document.getElementById('yaktube-transcript-panel'); + if (!panel) return; + + var items = panel.querySelectorAll('.yaktube-transcript-item'); + items.forEach(function (item) { + var start = parseFloat(item.getAttribute('data-start')); + var isActive = Math.abs(curTime - start) < 3; + if (isActive && !item.classList.contains('active')) { + items.forEach(function (i) { i.classList.remove('active'); }); + item.classList.add('active'); + } + }); +}, 1500); + +// ============================================================================ +// 4. Fediverse Clean Share & Timestamp Generator (Privacy First) +// ============================================================================ +function openCleanShareModal() { + var existing = document.getElementById('yaktube-clean-share-modal'); + if (existing) existing.remove(); + + recordFocusBeforeModal(); + + var video = getVideoElement(); + var curSec = video ? Math.floor(video.currentTime) : 0; + var cleanUrl = window.location.origin + window.location.pathname; + var timestampUrl = cleanUrl + '?start=' + curSec + 's'; + + var titleEl = document.querySelector('h1.video-title, my-video-watch h1, .video-name, .title'); + var videoTitle = titleEl ? titleEl.textContent.trim() : document.title; + + var modal = document.createElement('div'); + modal.id = 'yaktube-clean-share-modal'; + modal.className = 'yaktube-feature-modal-backdrop'; + modal.setAttribute('role', 'dialog'); + modal.setAttribute('aria-modal', 'true'); + modal.setAttribute('aria-labelledby', 'yaktube-share-title'); + + modal.innerHTML = + '
    ' + + '
    ' + + '

    🔗 Temiz ve Federe Paylaşım

    ' + + '' + + '
    ' + + '

    Tüm reklam ve izleyici parametrelerinden arındırılmış temiz YakTube bağlantısı:

    ' + + '
    ' + + '
    ' + + '' + + '' + + '
    ' + + '
    ' + + '' + + '' + + '
    ' + + '
    ' + + '🐘 Mastodon / Fediverse' + + '💬 WhatsApp' + + '
    ' + + '
    ' + + '
    '; + + var closeBtn = modal.querySelector('#yaktube-share-close'); + if (closeBtn) { + closeBtn.addEventListener('click', function () { + modal.remove(); + restoreFocusAfterModal(); + }); + } + + var chk = modal.querySelector('#yaktube-share-timestamp-chk'); + var inp = modal.querySelector('#yaktube-share-url-inp'); + var mastodonLink = modal.querySelector('#yaktube-mastodon-share'); + var waLink = modal.querySelector('#yaktube-whatsapp-share'); + + function updateShareLinks() { + var finalUrl = chk.checked ? timestampUrl : cleanUrl; + inp.value = finalUrl; + var shareText = encodeURIComponent(videoTitle + ' - YakTube: ' + finalUrl); + if (mastodonLink) mastodonLink.href = 'https://mastodonshare.com/?text=' + shareText; + if (waLink) waLink.href = 'https://api.whatsapp.com/send?text=' + shareText; + } + chk.addEventListener('change', updateShareLinks); + updateShareLinks(); + + modal.querySelector('#yaktube-copy-share-btn').addEventListener('click', function () { + inp.select(); + navigator.clipboard.writeText(inp.value).then(function () { + announce('Temiz paylaşım bağlantısı panoya kopyalandı.'); + showQuickToast('📋 Bağlantı Kopyalandı!'); + }).catch(function () { + document.execCommand('copy'); + announce('Temiz paylaşım bağlantısı kopyalandı.'); + }); + }); + + document.body.appendChild(modal); + trapFocusInModal(modal); + announce('Paylaşım penceresi açıldı. Kapatmak için Escape tuşuna basın.'); +} + +// ============================================================================ +// 5. F6 Landmark Cycle Navigation (WCAG 2.2 AAA Quick Switch) +// ============================================================================ +var landmarkIndex = 0; +function cycleLandmarks(reverse) { + var landmarks = [ + { name: 'Başlık ve Ana Arama', selector: 'header, my-header, #yaktube-search-input' }, + { name: 'Kategori Çipleri', selector: '#yaktube-home-categories, .yaktube-categories-bar' }, + { name: 'Video Oynatıcı Alanı', selector: '#videojs-wrapper, .video-js, #video-wrapper' }, + { name: 'Video Araç Çubuğu', selector: '#yaktube-player-action-bar' }, + { name: 'Video Açıklaması ve Bilgiler', selector: 'my-video-watch-description, .video-info, .video-bottom' }, + { name: 'Yorumlar ve Tartışmalar', selector: 'my-video-comments, .comments' }, + { name: 'Önerilen Videolar', selector: 'my-video-watch-related, .related-videos, #yaktube-ondemand-container' } + ]; + + var validLandmarks = landmarks.map(function (item) { + return { name: item.name, el: document.querySelector(item.selector) }; + }).filter(function (item) { + return !!item.el && item.el.offsetParent !== null; + }); + + if (!validLandmarks.length) { + announce('Sayfada gezinilebilir alan bulunamadı.'); + return; + } + + if (reverse) { + landmarkIndex = (landmarkIndex - 1 + validLandmarks.length) % validLandmarks.length; + } else { + landmarkIndex = (landmarkIndex + 1) % validLandmarks.length; + } + + var target = validLandmarks[landmarkIndex]; + if (target && target.el) { + target.el.setAttribute('tabindex', '-1'); + target.el.scrollIntoView({ behavior: 'smooth', block: 'center' }); + target.el.focus(); + announce('Bölgeye atlandı: ' + target.name); + showQuickToast('🎯 ' + target.name); + } +} + + function toggleShortcutsModal() { var modal = document.getElementById('yaktube-shortcuts-dialog'); if (modal) { @@ -2367,6 +2796,9 @@ try { '' + '' + '' + + '' + + '' + + '' + ''; var playerWrap = document.querySelector( @@ -2427,6 +2859,27 @@ try { showQuickVideoInfo(); }); + var audioBtn = bar.querySelector('#yaktube-bar-audio-btn'); + if (audioBtn) { + audioBtn.addEventListener('click', function () { + toggleAudioOnlyMode(); + }); + } + + var transcriptBtn = bar.querySelector('#yaktube-bar-transcript-btn'); + if (transcriptBtn) { + transcriptBtn.addEventListener('click', function () { + openTranscriptPanel(); + }); + } + + var shareBtn = bar.querySelector('#yaktube-bar-share-btn'); + if (shareBtn) { + shareBtn.addEventListener('click', function () { + openCleanShareModal(); + }); + }; + bar.querySelector('#yaktube-bar-help-btn').addEventListener('click', function () { toggleShortcutsModal(); }); @@ -2523,6 +2976,27 @@ try { return; } + // F6 or Shift+F6: Landmark Navigation (WCAG 2.2 AAA) + if (e.key === 'F6') { + e.preventDefault(); + cycleLandmarks(e.shiftKey); + return; + } + + // Audio-Only Mode: Alt+O + if (e.altKey && (e.key === 'o' || e.key === 'O') && !isInputFocused()) { + e.preventDefault(); + toggleAudioOnlyMode(); + return; + } + + // Live Transcript: Alt+C + if (e.altKey && (e.key === 'c' || e.key === 'C') && !isInputFocused()) { + e.preventDefault(); + openTranscriptPanel(); + return; + } + // Voice Search Open: Alt+V or Shift+V if ( ((e.altKey && (e.key === 'v' || e.key === 'V')) || (e.shiftKey && (e.key === 'v' || e.key === 'V'))) && diff --git a/package.json b/package.json index a59984c..7c90b24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "peertube-plugin-yaktube-ondemand", - "version": "1.7.3", + "version": "1.7.4", "description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube", "main": "main.js", "library": "./main.js", diff --git a/style.css b/style.css index 7797e05..36282e0 100644 --- a/style.css +++ b/style.css @@ -1789,3 +1789,152 @@ my-date-toggle .date-toggle:focus-visible { outline-offset: 2px !important; box-shadow: 0 0 10px rgba(255, 143, 55, 0.8) !important; } + + +/* === YakTube NLnet WCAG 2.2 AAA & Privacy Suite Styles === */ + +/* 1. Yalnızca Ses ve Ekran Karartma Modu */ +.yaktube-audio-blank-overlay { + position: fixed !important; + top: 0 !important; + left: 0 !important; + width: 100vw !important; + height: 100vh !important; + background: #000 !important; + z-index: 9999999 !important; + display: flex !important; + align-items: center !important; + justify-content: center !important; + text-align: center !important; + color: #fff !important; + padding: 24px !important; + box-sizing: border-box !important; +} + +.yaktube-audio-blank-content { + background: rgba(20, 20, 28, 0.95) !important; + border: 1px solid rgba(255, 143, 55, 0.5) !important; + border-radius: 20px !important; + padding: 32px 24px !important; + box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9) !important; + display: flex !important; + flex-direction: column !important; + align-items: center !important; + animation: yaktube-fade-in 0.25s ease-out !important; +} + +.yaktube-audio-action-btn { + background: linear-gradient(135deg, #ff8f37 0%, #ff5e3a 100%) !important; + color: #fff !important; + border: none !important; + border-radius: 10px !important; + padding: 12px 20px !important; + font-size: 14px !important; + font-weight: 700 !important; + cursor: pointer !important; + transition: transform 0.15s, opacity 0.15s !important; +} + +.yaktube-audio-action-btn:hover, +.yaktube-audio-action-btn:focus-visible { + transform: scale(1.05) !important; + outline: 3px solid #ff8f37 !important; + outline-offset: 3px !important; +} + +/* 2. Erişilebilir Canlı Transkript Paneli */ +.yaktube-transcript-panel { + margin: 16px 0 !important; + background: #181824 !important; + border: 1px solid rgba(255, 143, 55, 0.35) !important; + border-radius: 16px !important; + box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important; + color: #fff !important; + overflow: hidden !important; + animation: yaktube-fade-in 0.2s ease-out !important; +} + +.yaktube-transcript-header { + display: flex !important; + justify-content: space-between !important; + align-items: center !important; + padding: 14px 18px !important; + background: rgba(255, 255, 255, 0.04) !important; + border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important; + flex-wrap: wrap !important; + gap: 10px !important; +} + +.yaktube-transcript-search { + background: #22222e !important; + border: 1px solid #444 !important; + border-radius: 8px !important; + padding: 6px 12px !important; + color: #fff !important; + font-size: 13px !important; + width: 180px !important; + outline: none !important; +} + +.yaktube-transcript-search:focus { + border-color: #ff8f37 !important; + box-shadow: 0 0 8px rgba(255, 143, 55, 0.4) !important; +} + +.yaktube-transcript-list { + list-style: none !important; + margin: 0 !important; + padding: 8px 12px !important; + max-height: 280px !important; + overflow-y: auto !important; + display: flex !important; + flex-direction: column !important; + gap: 4px !important; +} + +.yaktube-transcript-item { + display: flex !important; + align-items: baseline !important; + gap: 12px !important; + padding: 8px 12px !important; + border-radius: 8px !important; + cursor: pointer !important; + transition: background 0.15s ease !important; +} + +.yaktube-transcript-item:hover, +.yaktube-transcript-item:focus-visible { + background: rgba(255, 143, 55, 0.15) !important; + outline: 2px solid #ff8f37 !important; + outline-offset: -2px !important; +} + +.yaktube-transcript-item.active { + background: rgba(255, 143, 55, 0.25) !important; + font-weight: 700 !important; + border-left: 4px solid #ff8f37 !important; +} + +.yaktube-transcript-time { + font-family: monospace !important; + font-size: 12px !important; + color: #ff8f37 !important; + background: rgba(255, 143, 55, 0.1) !important; + padding: 2px 6px !important; + border-radius: 4px !important; + flex-shrink: 0 !important; +} + +.yaktube-transcript-text { + font-size: 14px !important; + line-height: 1.45 !important; + color: #e5e5e5 !important; +} + +/* 3. Araç Çubuğu Butonlarının Aktif Hali */ +.yaktube-player-action-btn.active { + background: linear-gradient(135deg, #ff8f37 0%, #ff5e3a 100%) !important; + color: #fff !important; + border-color: #ff8f37 !important; + box-shadow: 0 0 12px rgba(255, 143, 55, 0.6) !important; +}