diff --git a/js/app.js b/js/app.js
index 78bfddf..adf8779 100644
--- a/js/app.js
+++ b/js/app.js
@@ -2123,6 +2123,10 @@ document.addEventListener('DOMContentLoaded', async () => {
ui.renderSearchHistory();
});
+ searchInput.addEventListener('click', () => {
+ ui.renderSearchHistory();
+ });
+
document.addEventListener('click', (e) => {
if (!e.target.closest('.search-bar')) {
const historyEl = document.getElementById('search-history');
diff --git a/js/ui.js b/js/ui.js
index de9c46f..9516dd4 100644
--- a/js/ui.js
+++ b/js/ui.js
@@ -2078,6 +2078,82 @@ export class UIRenderer {
}
}
+ renderSearchHistory() {
+ const historyEl = document.getElementById('search-history');
+ if (!historyEl) return;
+ const history = JSON.parse(localStorage.getItem('search-history') || '[]');
+ if (history.length === 0) {
+ historyEl.style.display = 'none';
+ return;
+ }
+ historyEl.innerHTML =
+ history
+ .map(
+ (query) => `
+
+
+
${escapeHtml(query)}
+
+
+
+
+ `
+ )
+ .join('') +
+ `
+
+ Clear all history
+
+ `;
+ historyEl.style.display = 'block';
+
+ historyEl.querySelectorAll('.search-history-item').forEach((item) => {
+ item.addEventListener('click', (e) => {
+ if (e.target.closest('.delete-history-btn')) {
+ e.stopPropagation();
+ this.removeFromSearchHistory(item.dataset.query);
+ return;
+ }
+ const query = item.dataset.query;
+ const searchInput = document.getElementById('search-input');
+ if (searchInput) {
+ searchInput.value = query;
+ searchInput.dispatchEvent(new Event('input'));
+ historyEl.style.display = 'none';
+ }
+ });
+ });
+
+ const clearBtn = document.getElementById('clear-search-history');
+ if (clearBtn) {
+ clearBtn.addEventListener('click', (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ localStorage.removeItem('search-history');
+ this.renderSearchHistory();
+ });
+ }
+ }
+
+ removeFromSearchHistory(query) {
+ let history = JSON.parse(localStorage.getItem('search-history') || '[]');
+ history = history.filter((q) => q !== query);
+ localStorage.setItem('search-history', JSON.stringify(history));
+ this.renderSearchHistory();
+ }
+
+ addToSearchHistory(query) {
+ if (!query || query.trim().length === 0) return;
+ let history = JSON.parse(localStorage.getItem('search-history') || '[]');
+ history = history.filter((q) => q !== query);
+ history.unshift(query);
+ history = history.slice(0, 10);
+ localStorage.setItem('search-history', JSON.stringify(history));
+ }
+
async renderAlbumPage(albumId, provider = null) {
this.showPage('album');