一分钟搭建影视站,支持Docker等部署方式
添加单个搜索历史标签删除功能
WLong547b30d01be5
diff --git a/js/ui.js b/js/ui.jsindex 2ffc52d..bab6b5d 100644--- a/js/ui.js+++ b/js/ui.js@@ -228,8 +228,24 @@ function renderSearchHistory() {history.forEach(item => {const tag = document.createElement('button');- tag.className = 'search-tag';- tag.textContent = item.text;+ tag.className = 'search-tag flex items-center gap-1';+ const textSpan = document.createElement('span');+ textSpan.textContent = item.text;+ tag.appendChild(textSpan);++ // 添加删除按钮+ const deleteButton = document.createElement('span');+ deleteButton.className = 'pl-1 text-gray-500 hover:text-red-500 transition-colors';+ deleteButton.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>';+ deleteButton.onclick = function(e) {+ // 阻止事件冒泡,避免触发搜索+ e.stopPropagation();+ // 删除对应历史记录+ deleteSingleSearchHistory(item.text);+ // 重新渲染搜索历史+ renderSearchHistory();+ };+ tag.appendChild(deleteButton);// 添加时间提示(如果有时间戳)if (item.timestamp) {@@ -245,6 +261,21 @@ function renderSearchHistory() {});}+// 删除单条搜索历史记录+function deleteSingleSearchHistory(query) {+ // 当url中包含删除的关键词时,页面刷新后会自动加入历史记录,导致误认为删除功能有bug。此问题无需修复,功能无实际影响。+ try {+ let history = getSearchHistory();+ // 过滤掉要删除的记录+ history = history.filter(item => item.text !== query);+ console.log('更新后的搜索历史:', history);+ localStorage.setItem(SEARCH_HISTORY_KEY, JSON.stringify(history));+ } catch (e) {+ console.error('删除单条搜索历史失败:', e);+ showToast('删除单条搜索历史失败', 'error');+ }+}+// 增加清除搜索历史功能function clearSearchHistory() {// 密码保护校验