Compare commits

...
4 Commits
4 changed files with 192 additions and 44 deletions
+107 -24
View File
@@ -4354,18 +4354,52 @@ try {
var q = query.trim(); var q = query.trim();
try { try {
var list = getRecentSearches(); var list = getRecentSearches();
// Remove previous occurrence of the exact term (case-insensitive) and bubble it to the very top (#1)
list = list.filter(function (item) { list = list.filter(function (item) {
return item.toLowerCase() !== q.toLowerCase(); return item.toLowerCase() !== q.toLowerCase();
}); });
list.unshift(q); list.unshift(q);
if (list.length > 12) list = list.slice(0, 12); if (list.length > 20) list = list.slice(0, 20);
localStorage.setItem('yaktube_recent_searches', JSON.stringify(list)); localStorage.setItem('yaktube_recent_searches', JSON.stringify(list));
} catch (e) {} } catch (e) {}
// If user is logged in and sync is active, sync with YakNet account // If user is logged in and sync is active, sync with YakNet account
if (isAccountSyncEnabled()) { if (isAccountSyncEnabled()) {
callCloudSearchHistory('POST', '', { query: q, device_name: 'YakTube Web' }); callCloudSearchHistory('POST', '', { query: q, device_name: 'YakTube Web' }, function (data) {
if (data && data.status === 'success' && Array.isArray(data.history) && data.history.length > 0) {
localStorage.setItem('yaktube_recent_searches', JSON.stringify(data.history));
} }
});
}
}
function deleteRecentSearch(targetQuery) {
if (!targetQuery) return;
var q = targetQuery.trim();
try {
var list = getRecentSearches();
list = list.filter(function (item) {
return item.toLowerCase() !== q.toLowerCase();
});
localStorage.setItem('yaktube_recent_searches', JSON.stringify(list));
} catch (e) {}
if (isAccountSyncEnabled()) {
callCloudSearchHistory('DELETE', '?query=' + encodeURIComponent(q), { query: q }, function (data) {
if (data && data.status === 'success' && Array.isArray(data.history)) {
localStorage.setItem('yaktube_recent_searches', JSON.stringify(data.history));
}
});
}
var modal = document.getElementById('yaktube-full-search-modal');
var filterVal = '';
if (modal) {
var inp = modal.querySelector('#yaktube-modal-input');
if (inp) filterVal = inp.value;
}
renderDynamicSearchChips(filterVal);
announce('"' + q + '" araması geçmişten silindi.');
} }
function clearRecentSearches() { function clearRecentSearches() {
@@ -4406,7 +4440,7 @@ try {
captureUrlSearchQuery(); captureUrlSearchQuery();
window.addEventListener('popstate', captureUrlSearchQuery); window.addEventListener('popstate', captureUrlSearchQuery);
function renderDynamicSearchChips() { function renderDynamicSearchChips(filterText) {
var modal = document.getElementById('yaktube-full-search-modal'); var modal = document.getElementById('yaktube-full-search-modal');
if (!modal) return; if (!modal) return;
@@ -4416,12 +4450,28 @@ try {
var recent = getRecentSearches(); var recent = getRecentSearches();
var loggedIn = isUserLoggedIn(); var loggedIn = isUserLoggedIn();
var syncEnabled = isAccountSyncEnabled(); var syncEnabled = isAccountSyncEnabled();
var filter = (filterText || '').trim().toLowerCase();
var displayedRecent = recent;
var displayedPopular = popularTrendingQueries;
if (filter.length > 0) {
displayedRecent = recent.filter(function (term) {
return term.toLowerCase().includes(filter);
});
displayedPopular = popularTrendingQueries.filter(function (item) {
return item.q.toLowerCase().includes(filter) || item.title.toLowerCase().includes(filter);
});
}
var html = ''; var html = '';
// 1. Recent searches section // 1. Recent searches section
html += html +=
'<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px;">' + '<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px;">' +
'<div class="yaktube-modal-section-title" style="margin-bottom: 0;">🕒 Son Aramalarınız</div>' + '<div class="yaktube-modal-section-title" style="margin-bottom: 0;">🕒 ' +
(filter.length > 0 ? 'Eşleşen Son Aramalarınız' : 'Son Aramalarınız') +
'</div>' +
'<div style="display: flex; align-items: center; gap: 8px;">'; '<div style="display: flex; align-items: center; gap: 8px;">';
if (loggedIn) { if (loggedIn) {
@@ -4448,35 +4498,52 @@ try {
'<span style="font-size: 11px; color: #94a3b8; background: #1e293b; border-radius: 6px; padding: 2px 8px;" title="Misafir modundasınız, aramalar sadece bu cihazda saklanır">🔒 Bu Cihazda</span>'; '<span style="font-size: 11px; color: #94a3b8; background: #1e293b; border-radius: 6px; padding: 2px 8px;" title="Misafir modundasınız, aramalar sadece bu cihazda saklanır">🔒 Bu Cihazda</span>';
} }
if (recent.length > 0) { if (recent.length > 0 && filter.length === 0) {
html += html +=
'<button id="yaktube-clear-recent-btn" style="background: transparent; border: none; color: #ff8f37; font-size: 12px; font-weight: 600; cursor: pointer; text-decoration: underline;" aria-label="Arama geçmişini temizle">Geçmişi Temizle</button>'; '<button id="yaktube-clear-recent-btn" style="background: transparent; border: none; color: #ff8f37; font-size: 12px; font-weight: 600; cursor: pointer; text-decoration: underline;" aria-label="Tüm arama geçmişini temizle">Geçmişi Temizle</button>';
} }
html += '</div></div>'; html += '</div></div>';
if (recent.length > 0) { if (displayedRecent.length > 0) {
html += '<div class="yaktube-modal-chips-grid" style="margin-bottom: 18px;">'; html += '<div class="yaktube-modal-chips-grid" style="margin-bottom: 18px;">';
recent.forEach(function (term) { displayedRecent.forEach(function (term) {
var safeTerm = term.replace(/"/g, '&quot;'); var safeTerm = term.replace(/"/g, '&quot;');
html += html +=
'<button class="yaktube-modal-chip yaktube-recent-chip" data-query="' + '<div class="yaktube-modal-chip yaktube-recent-chip" data-query="' +
safeTerm + safeTerm +
'" aria-label="Son arama: ' + '" title="' +
safeTerm +
' için ara">' +
'<span class="yaktube-recent-chip-text" data-query="' +
safeTerm + safeTerm +
'">🕒 ' + '">🕒 ' +
safeTerm + safeTerm +
'</button>'; '</span>' +
'<button type="button" class="yaktube-recent-chip-delete" data-delete-query="' +
safeTerm +
'" title="Bu aramayı geçmişten kaldır" aria-label="' +
safeTerm +
' aramasını geçmişten kaldır">✕</button>' +
'</div>';
}); });
html += '</div>'; html += '</div>';
} else if (filter.length > 0) {
html +=
'<div style="font-size: 12px; color: #94a3b8; margin-bottom: 14px; font-style: italic;">Geçmişte "' +
filter.replace(/"/g, '&quot;') +
'" ile eşleşen kayıt bulunamadı.</div>';
} }
// 2. Popular & Trending searches section // 2. Popular & Trending searches section
if (displayedPopular.length > 0) {
html += html +=
'<div class="yaktube-modal-section-title">🔥 Hızlı ve Popüler Aramalar</div>' + '<div class="yaktube-modal-section-title">🔥 ' +
(filter.length > 0 ? 'Önerilen Aramalar' : 'Hızlı ve Popüler Aramalar') +
'</div>' +
'<div class="yaktube-modal-chips-grid">'; '<div class="yaktube-modal-chips-grid">';
popularTrendingQueries.forEach(function (item) { displayedPopular.forEach(function (item) {
var safeQ = item.q.replace(/"/g, '&quot;'); var safeQ = item.q.replace(/"/g, '&quot;');
html += html +=
'<button class="yaktube-modal-chip" data-query="' + '<button class="yaktube-modal-chip" data-query="' +
@@ -4488,12 +4555,25 @@ try {
'</button>'; '</button>';
}); });
html += '</div>'; html += '</div>';
}
container.innerHTML = html; container.innerHTML = html;
// Attach click events // Attach click events
container.querySelectorAll('.yaktube-recent-chip-delete').forEach(function (delBtn) {
delBtn.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
var delTerm = delBtn.getAttribute('data-delete-query');
deleteRecentSearch(delTerm);
});
});
container.querySelectorAll('.yaktube-modal-chip').forEach(function (chip) { container.querySelectorAll('.yaktube-modal-chip').forEach(function (chip) {
chip.addEventListener('click', function () { chip.addEventListener('click', function (e) {
if (e.target && e.target.classList.contains('yaktube-recent-chip-delete')) {
return;
}
var query = chip.getAttribute('data-query'); var query = chip.getAttribute('data-query');
var inp = modal.querySelector('#yaktube-modal-input'); var inp = modal.querySelector('#yaktube-modal-input');
if (inp) inp.value = query; if (inp) inp.value = query;
@@ -4576,19 +4656,22 @@ try {
var voiceBtn = modal.querySelector('#yaktube-modal-voice-btn'); var voiceBtn = modal.querySelector('#yaktube-modal-voice-btn');
var micPulseBtn = modal.querySelector('#yaktube-modal-mic-pulse'); var micPulseBtn = modal.querySelector('#yaktube-modal-mic-pulse');
// Input typing & clear // Input typing & live search history filtering
inp.addEventListener('input', function () { inp.addEventListener('input', function () {
if (inp.value && inp.value.trim().length > 0) { var val = (inp.value || '').trim();
if (val.length > 0) {
clearBtn.style.display = 'inline-flex'; clearBtn.style.display = 'inline-flex';
} else { } else {
clearBtn.style.display = 'none'; clearBtn.style.display = 'none';
} }
renderDynamicSearchChips(val);
}); });
clearBtn.addEventListener('click', function () { clearBtn.addEventListener('click', function () {
inp.value = ''; inp.value = '';
clearBtn.style.display = 'none'; clearBtn.style.display = 'none';
inp.focus(); inp.focus();
renderDynamicSearchChips('');
announce('Arama metni temizlendi.'); announce('Arama metni temizlendi.');
}); });
@@ -4632,14 +4715,6 @@ try {
} }
}); });
// Chips click
modal.querySelectorAll('.yaktube-modal-chip').forEach(function (chip) {
chip.addEventListener('click', function () {
var query = chip.getAttribute('data-query');
executeSearch(query);
});
});
// Voice button click // Voice button click
voiceBtn.addEventListener('click', function () { voiceBtn.addEventListener('click', function () {
toggleVoiceInsideModal(); toggleVoiceInsideModal();
@@ -5860,3 +5935,11 @@ try {
} catch (err) { } catch (err) {
console.error('[YakTube] Safe catch error:', err); console.error('[YakTube] Safe catch error:', err);
} }
// PeerTube Plugin Client Hook Registration
export async function register({ registerHook, peertubeHelpers } = {}) {
return true;
}
export { register as registerClient };
export default register;
+33 -4
View File
@@ -607,6 +607,20 @@ async function register({ getRouter, registerSetting, settingsManager, peertubeH
return false; return false;
} }
function normalizeTitleForMatch(str) {
if (!str) return '';
return String(str)
.replace(/&amp;/g, '&')
.replace(/&#39;/g, "'")
.replace(/&quot;/g, '"')
.replace(/[\u2010-\u2015]/g, '-')
.replace(/\s*[\(\[](official|video|music|audio|clip|4k|hd|lyrics|sözleri|visualizer)[^\)\]]*[\)\]]/gi, '')
.replace(/[^a-zA-Z0-9\u00C0-\u024F\u1E00-\u1EFF]/g, ' ')
.replace(/\s+/g, ' ')
.trim()
.toLocaleLowerCase('tr');
}
// Helper to enrich YouTube results with existing local PeerTube videos via DB // Helper to enrich YouTube results with existing local PeerTube videos via DB
async function enrichResultsWithLocalStatus(results) { async function enrichResultsWithLocalStatus(results) {
try { try {
@@ -643,10 +657,18 @@ async function register({ getRouter, registerSetting, settingsManager, peertubeH
}; };
} }
const normalizedTitle = (item.title || '').toLowerCase().trim(); const rawItemTitle = (item.title || '').toLowerCase().trim();
const normItemTitle = normalizeTitleForMatch(item.title);
const matchedLocal = localVideos.find(lv => { const matchedLocal = localVideos.find(lv => {
const lvName = (lv.name || '').toLowerCase().trim(); const rawLv = (lv.name || '').toLowerCase().trim();
return lvName === normalizedTitle || (lvName.length > 5 && normalizedTitle.includes(lvName)); if (rawLv === rawItemTitle) return true;
const normLv = normalizeTitleForMatch(lv.name);
return (
normLv &&
(normLv === normItemTitle ||
(normLv.length > 5 && (normItemTitle.includes(normLv) || normLv.includes(normItemTitle))))
);
}); });
if (matchedLocal) { if (matchedLocal) {
@@ -1318,13 +1340,20 @@ async function register({ getRouter, registerSetting, settingsManager, peertubeH
if (q && q.length >= 2) { if (q && q.length >= 2) {
const filtered = currentList.filter(item => String(item).toLowerCase() !== q.toLowerCase()); const filtered = currentList.filter(item => String(item).toLowerCase() !== q.toLowerCase());
filtered.unshift(q); filtered.unshift(q);
store[userKey] = filtered.slice(0, 12); store[userKey] = filtered.slice(0, 20);
writeHistoryStore(store); writeHistoryStore(store);
} }
return res.json({ status: 'success', history: store[userKey] || currentList }); return res.json({ status: 'success', history: store[userKey] || currentList });
} }
if (req.method === 'DELETE') { if (req.method === 'DELETE') {
const target = ((req.body && req.body.query) || (req.query && req.query.query) || '').trim();
if (target) {
const filtered = currentList.filter(item => String(item).toLowerCase() !== target.toLowerCase());
store[userKey] = filtered;
writeHistoryStore(store);
return res.json({ status: 'success', history: filtered });
}
delete store[userKey]; delete store[userKey];
writeHistoryStore(store); writeHistoryStore(store);
return res.json({ status: 'success', history: [] }); return res.json({ status: 'success', history: [] });
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "peertube-plugin-yaktube-ondemand", "name": "peertube-plugin-yaktube-ondemand",
"version": "1.6.6", "version": "1.7.0",
"description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube", "description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube",
"main": "main.js", "main": "main.js",
"library": "./main.js", "library": "./main.js",
+36
View File
@@ -810,6 +810,42 @@ my-search-typeahead,
transform: translateY(-1px) !important; transform: translateY(-1px) !important;
} }
.yaktube-modal-chip.yaktube-recent-chip {
padding: 6px 10px 6px 14px !important;
gap: 8px !important;
}
.yaktube-recent-chip-text {
cursor: pointer !important;
display: inline-flex !important;
align-items: center !important;
}
.yaktube-recent-chip-delete {
background: rgba(255, 255, 255, 0.08) !important;
border: none !important;
color: #94a3b8 !important;
font-size: 11px !important;
font-weight: 700 !important;
line-height: 1 !important;
cursor: pointer !important;
width: 18px !important;
height: 18px !important;
border-radius: 50% !important;
display: inline-flex !important;
align-items: center !important;
justify-content: center !important;
transition: all 0.2s ease !important;
margin-left: 2px !important;
padding: 0 !important;
}
.yaktube-recent-chip-delete:hover {
background: rgba(239, 68, 68, 0.35) !important;
color: #ff6b6b !important;
transform: scale(1.15) !important;
}
.yaktube-modal-hint-footer { .yaktube-modal-hint-footer {
display: flex !important; display: flex !important;
justify-content: space-between !important; justify-content: space-between !important;