// URL'den link kodunu al function getLinkCodeFromUrl() { const urlParams = new URLSearchParams(window.location.search); return urlParams.get('code'); } // URL'den link verisini decode et function getLinkFromUrl() { const urlParams = new URLSearchParams(window.location.search); const encodedData = urlParams.get('data'); if (!encodedData) return null; try { return JSON.parse(atob(encodedData)); } catch (e) { return null; } } // Link kodunu doğrula (localStorage yerine URL'den) function validateLink(code) { const linkData = getLinkFromUrl(); return linkData && linkData.code === code ? linkData : null; } // Linkin süresi doldu mu kontrol et function isLinkExpired(link) { if (link.limitType === 'time') { const now = new Date(); const expiresAt = new Date(link.expiresAt); return now > expiresAt; } else { return link.remainingViews <= 0; } } // İzleme sayısını azalt (localStorage gerekmez, URL'den decode ederiz) function decrementViewCount(link) { // Hugging Face'te localStorage çalışmadığı için // İzleme sayısını URL'den decode edip güncellememiz gerekir // Bu basit versiyonda sadece gösteriyoruz, gerçek kontrol için server gerekir return link.remainingViews - 1; } // Bildirim göster function showNotification(message, type = 'success') { const notification = document.getElementById('notification'); notification.textContent = message; notification.className = 'notification'; if (type === 'error') { notification.style.background = '#333'; notification.style.color = '#fff'; } else { notification.style.background = '#fff'; notification.style.color = '#000'; } notification.style.display = 'block'; setTimeout(() => { notification.style.display = 'none'; }, 3000); } // Videoyu göster function showVideo(link) { document.getElementById('loading').style.display = 'none'; document.getElementById('error').style.display = 'none'; document.getElementById('videoSection').style.display = 'block'; document.getElementById('linkCode').textContent = link.code; // YouTube video ID'si const youtubeVideoId = 'xROC6HUeakk'; // YouTube embed'i ayarla const youtubePlayer = document.getElementById('youtubePlayer'); youtubePlayer.src = `https://www.youtube.com/embed/${youtubeVideoId}?enablejsapi=1`; if (link.limitType === 'count') { // Kez bazlı limit const currentRemaining = link.remainingViews; document.getElementById('remainingViews').textContent = currentRemaining; document.getElementById('viewCountDisplay').textContent = currentRemaining; // Bu link bu session'da daha önce izlendi mi kontrol et const sessionKey = 'viewed_' + link.code; const alreadyViewed = sessionStorage.getItem(sessionKey); if (!alreadyViewed && currentRemaining > 0) { // İlk izleme - sayıyı azalt ve session'a kaydet sessionStorage.setItem(sessionKey, 'true'); const newRemaining = currentRemaining - 1; link.remainingViews = newRemaining; // URL'yi güncelle (sayfayı yenile) const encodedData = btoa(JSON.stringify(link)); setTimeout(() => { window.location.href = `viewer.html?code=${link.code}&data=${encodedData}`; }, 1000); } else if (currentRemaining <= 0) { // Hak doldu showNotification('İzleme hakkınız doldu!', 'error'); youtubePlayer.src = ''; setTimeout(() => { window.location.href = 'viewer.html?code=' + link.code; }, 2000); } } else { // Süre bazlı limit const now = new Date(); const expiresAt = new Date(link.expiresAt); const remainingMinutes = Math.max(0, Math.ceil((expiresAt - now) / 60000)); document.getElementById('remainingViews').textContent = remainingMinutes + ' dakika'; document.getElementById('viewCountDisplay').textContent = remainingMinutes + ' dakika'; // Süre kontrolü const checkExpiration = () => { const currentTime = new Date(); const currentRemaining = Math.max(0, Math.ceil((expiresAt - currentTime) / 60000)); document.getElementById('remainingViews').textContent = currentRemaining + ' dakika'; document.getElementById('viewCountDisplay').textContent = currentRemaining + ' dakika'; if (currentRemaining <= 0) { showNotification('Süreniz doldu!', 'error'); youtubePlayer.src = ''; clearInterval(expirationInterval); setTimeout(() => { window.location.href = 'viewer.html?code=' + link.code; }, 2000); } }; // Her saniye kontrol et const expirationInterval = setInterval(checkExpiration, 1000); } } // Hata göster function showError() { document.getElementById('loading').style.display = 'none'; document.getElementById('videoSection').style.display = 'none'; document.getElementById('error').style.display = 'block'; } // Sayfa yüklendiğinde document.addEventListener('DOMContentLoaded', function() { const code = getLinkCodeFromUrl(); if (!code) { showError(); return; } const link = validateLink(code); if (!link) { showError(); return; } if (isLinkExpired(link)) { if (link.limitType === 'count') { document.querySelector('.error-message').textContent = 'İzleme Hakkı Doldu'; document.querySelector('.error-description').textContent = 'Bu link için izleme hakkınız tükenmiş.'; } else { document.querySelector('.error-message').textContent = 'Süre Doldu'; document.querySelector('.error-description').textContent = 'Bu linkin süresi dolmuş.'; } showError(); return; } showVideo(link); });