diff --git a/client.js b/client.js
index d7f2c55..672244f 100644
--- a/client.js
+++ b/client.js
@@ -4465,26 +4465,400 @@ try {
var container = document.getElementById('yaktube-ondemand-container');
var nativeResults = searchMount.querySelector('.search-result');
+ function ensureSearchContainerMounted() {
+ var curSearchMount = document.querySelector('my-search, my-search-results') || searchMount;
+ var curNative = curSearchMount ? curSearchMount.querySelector('.search-result') : null;
+ var el = document.getElementById('yaktube-ondemand-container');
+ if (!el) {
+ el = document.createElement('div');
+ el.id = 'yaktube-ondemand-container';
+ el.className = 'yaktube-ondemand-section';
+ el.setAttribute('role', 'region');
+ el.setAttribute('aria-label', 'Canlı YouTube ve ' + getInstanceName() + ' Arama Sonuçları');
+ }
+ if (curSearchMount && el.parentElement !== curSearchMount) {
+ curSearchMount.insertBefore(el, curNative || curSearchMount.firstChild);
+ }
+ return el;
+ }
+
+ function renderSearchOutcome(ytData, localData, activeContainer) {
+ var targetContainer = activeContainer || ensureSearchContainerMounted();
+ ytData = ytData || {};
+ localData = localData || {};
+
+ if (typeof ytData.guestImportLimit === 'number') {
+ cachedGuestImportLimit = ytData.guestImportLimit;
+ }
+
+ if (ytData && ytData.blocked) {
+ var safetyMsg =
+ ytData.message ||
+ 'Bu arama terimi veya içerik, Çocuk ve Aile Güvenliği (Child & Family Safety) politikaları gereğince filtrelenmiştir.';
+ targetContainer.innerHTML =
+ '
';
+ announce(safetyMsg, true);
+ return;
+ }
+
+ var rawYtResults = ytData.results || [];
+ var uniqueYtResults = [];
+ var seenIds = {};
+
+ rawYtResults.forEach(function (item) {
+ if (item && item.id && !seenIds[item.id] && item.title) {
+ seenIds[item.id] = true;
+ uniqueYtResults.push(item);
+ }
+ });
+
+ var ytCount = uniqueYtResults.length;
+ var localResults = localData.data || [];
+ var localTotal = typeof localData.total === 'number' ? localData.total : localResults.length;
+
+ if (ytCount === 0 && localResults.length === 0) {
+ var emptyTitle = ytData.searchError
+ ? 'YouTube bağlantısı geçici olarak zaman aşımına uğradı'
+ : '"' + escapeHtml(query) + '" için Sonuç Bulunamadı';
+ var retryHtml = ytData.searchError
+ ? ''
+ : '';
+ targetContainer.innerHTML =
+ '' +
+ retryHtml;
+ var rBtn = document.getElementById('yaktube-retry-search-btn');
+ if (rBtn) {
+ rBtn.addEventListener('click', function () {
+ window.__yaktube_last_search_snapshot__ = null;
+ lastQuery = null;
+ checkAndInjectSearchResults();
+ });
+ }
+ var scBtn = document.getElementById('yaktube-open-shortcuts');
+ if (scBtn) scBtn.addEventListener('click', toggleShortcutsModal);
+ announce(
+ ytData.searchError
+ ? 'YouTube bağlantısı geçici olarak yanıt vermedi.'
+ : query + ' için eşleşen video bulunamadı.'
+ );
+ return;
+ }
+
+ var visibleYtCount = Math.min(12, ytCount);
+
+ function renderAll() {
+ var ytHeaderHtml = '';
+ var ytCardsHtml = '';
+ var ytLoadMoreHtml = '';
+
+ if (ytCount > 0) {
+ var countText = ytCount === 1 ? '1 Video Bulundu' : ytCount + ' Video Bulundu';
+ ytHeaderHtml =
+ '';
+
+ var visibleResults = uniqueYtResults.slice(0, visibleYtCount);
+ visibleResults.forEach(function (item) {
+ if (item && item.title && item.channel) {
+ saveVideoChannelMeta(
+ item.title,
+ item.channel,
+ item.id || '',
+ (item.localVideo && item.localVideo.uuid) || ''
+ );
+ }
+ var isLocal = !!item.isDownloaded;
+ var isLive = !!item.isLive;
+
+ var statusBadge = '';
+ if (isLive) {
+ statusBadge =
+ '🔴 CANLI YAYIN';
+ } else if (isLocal) {
+ statusBadge =
+ '✅ ' +
+ escapeHtml(getInstanceName()) +
+ "'da Mevcut";
+ }
+
+ var actionButton = '';
+ if (isLive) {
+ actionButton =
+ '';
+ } else if (isLocal && item.localVideo && item.localVideo.url) {
+ actionButton =
+ '▶️ ' +
+ escapeHtml(getInstanceName()) +
+ "'dan İzle";
+ } else {
+ actionButton =
+ '";
+ }
+
+ var durationText = isLive ? 'CANLI' : item.durationFormatted || formatClockTime(item.duration);
+ var cardLabel =
+ item.title +
+ (isLive ? ' (Canlı Yayın)' : isLocal ? ' (' + getInstanceName() + ' kütüphanenizde mevcut)' : '') +
+ ', ' +
+ item.channel +
+ ' kanalı, Süre: ' +
+ durationText;
+
+ ytCardsHtml +=
+ '' +
+ '
' +
+ '
 +
+ ')
' +
+ '
' +
+ escapeHtml(durationText) +
+ '' +
+ '
' +
+ '
' +
+ '
' +
+ statusBadge +
+ '
' +
+ escapeHtml(item.title) +
+ '
' +
+ '
' +
+ escapeHtml(item.channel) +
+ '
' +
+ '
' +
+ actionButton +
+ '
' +
+ '
';
+ });
+
+ if (visibleYtCount < ytCount) {
+ ytLoadMoreHtml =
+ '' +
+ '' +
+ '
';
+ }
+ }
+
+ var localShelfHtml = '';
+ if (localResults.length > 0) {
+ var localCardsHtml = '';
+ localResults.forEach(function (lItem) {
+ var lThumb =
+ lItem.thumbnailPath ||
+ (lItem.thumbnails && lItem.thumbnails[0]
+ ? lItem.thumbnails[0].fileUrl
+ : '/client/assets/images/default-thumbnail.jpg');
+ var lDuration = formatClockTime(lItem.duration);
+ var lChannel =
+ (lItem.channel && (lItem.channel.displayName || lItem.channel.name)) ||
+ (lItem.account && (lItem.account.displayName || lItem.account.name)) ||
+ getInstanceName();
+ var lWatchUrl = lItem.url || '/videos/watch/' + (lItem.shortUUID || lItem.uuid);
+ var lViews = (lItem.views || 0) + ' görüntüleme';
+ var lLabel =
+ lItem.name +
+ ', ' +
+ lChannel +
+ ', ' +
+ getInstanceName() +
+ ' yerel sunucusunda mevcut, Süre: ' +
+ lDuration;
+
+ localCardsHtml +=
+ '';
+ });
+
+ localShelfHtml =
+ '' +
+ '' +
+ '
' +
+ localCardsHtml +
+ '
' +
+ '
';
+ }
+
+ targetContainer.innerHTML =
+ ytHeaderHtml +
+ (ytCount > 0 ? '' + ytCardsHtml + '
' : '') +
+ ytLoadMoreHtml +
+ localShelfHtml;
+
+ var sBtn = document.getElementById('yaktube-open-shortcuts');
+ if (sBtn) {
+ sBtn.addEventListener('click', toggleShortcutsModal);
+ }
+
+ var loadMoreBtn = document.getElementById('yaktube-load-more-btn');
+ if (loadMoreBtn) {
+ loadMoreBtn.addEventListener('click', function () {
+ visibleYtCount = Math.min(visibleYtCount + 6, ytCount);
+ renderAll();
+ announce(visibleYtCount + ' adet video gösteriliyor.');
+ });
+ }
+
+ targetContainer.querySelectorAll('.yaktube-live-btn').forEach(function (btn) {
+ btn.addEventListener('click', function (e) {
+ var liveUrl = e.currentTarget.getAttribute('data-url');
+ var liveTitle = e.currentTarget.getAttribute('data-title');
+ handleLiveStream(liveUrl, liveTitle);
+ });
+ });
+
+ targetContainer.querySelectorAll('.yaktube-import-btn').forEach(function (btn) {
+ btn.addEventListener('click', function (e) {
+ var videoUrl = e.currentTarget.getAttribute('data-url');
+ var videoTitle = e.currentTarget.getAttribute('data-title');
+ handleImport(videoUrl, e.currentTarget, videoTitle);
+ });
+ });
+ }
+
+ renderAll();
+ }
+
if (queryKey === lastQueryKey) {
- if (container && container.parentElement !== searchMount) {
- searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
+ if (container) {
+ if (container.parentElement !== searchMount) {
+ searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
+ }
+ ensureFediverseBridge(query, currentSearchTarget);
+ return;
+ }
+ // If Angular re-rendered and wiped #yaktube-ondemand-container, restore instantly!
+ if (!isSearching) {
+ var snap = window.__yaktube_last_search_snapshot__;
+ if (snap && snap.key === queryKey) {
+ var restoredContainer = ensureSearchContainerMounted();
+ renderSearchOutcome(snap.ytData, snap.localData, restoredContainer);
+ ensureFediverseBridge(query, currentSearchTarget);
+ return;
+ }
+ lastQuery = null;
+ lastSearchTarget = null;
+ } else {
+ container = ensureSearchContainerMounted();
+ ensureFediverseBridge(query, currentSearchTarget);
+ return;
}
- ensureFediverseBridge(query, currentSearchTarget);
- return;
}
lastQuery = query;
lastSearchTarget = currentSearchTarget;
-
- if (!container) {
- container = document.createElement('div');
- container.id = 'yaktube-ondemand-container';
- container.className = 'yaktube-ondemand-section';
- container.setAttribute('role', 'region');
- container.setAttribute('aria-label', 'Canlı YouTube ve ' + getInstanceName() + ' Arama Sonuçları');
- searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
- } else if (container.parentElement !== searchMount) {
- searchMount.insertBefore(container, nativeResults || searchMount.firstChild);
- }
+ container = ensureSearchContainerMounted();
container.innerHTML =
'