一分钟搭建影视站,支持Docker等部署方式
更新了多个文件以改进用户界面和播放器功能:
developerb645c1b85c59
diff --git a/css/styles.css b/css/styles.cssindex e746311..afbb7b6 100644--- a/css/styles.css+++ b/css/styles.css@@ -536,8 +536,8 @@ body {}.filter-disabled .toggle-dot {- transform: translateX(0) !important;- background-color: #777 !important;+ transform: translateX(0) ;+ background-color: #777 ;opacity: 0.9;}@@ -603,19 +603,32 @@ body {.history-panel {box-shadow: 2px 0 10px rgba(0,0,0,0.5);transition: transform 0.3s ease-in-out;+ overflow-y: scroll; /* 始终显示滚动条,防止宽度变化 */+ overflow-x: hidden; /* 防止水平滚动 */+ width: 320px; /* 固定宽度 */+ box-sizing: border-box; /* 确保padding不影响总宽度 */+ scrollbar-gutter: stable; /* 现代浏览器:为滚动条预留空间 */}.history-panel.show {transform: translateX(0);}+#historyList {+ padding-right: 6px; /* 为滚动条预留空间,确保内容不被挤压 */+}++/* 历史记录项样式优化 */.history-item {background: #1a1a1a;- border-radius: 8px;+ border-radius: 6px; /* 减小圆角 */border: 1px solid #333;overflow: hidden;transition: all 0.2s ease;- padding: 12px;+ padding: 8px 12px; /* 减小内边距 */+ position: relative;+ margin-bottom: 8px; /* 减小底部间距 */+ width: 100%; /* 确保宽度一致 */}.history-item:hover {@@ -624,14 +637,24 @@ body {box-shadow: 0 4px 8px rgba(0,0,0,0.2);}+/* 添加组悬停效果,使删除按钮在悬停时显示 */+.history-item .delete-btn {+ opacity: 0;+ transition: opacity 0.2s ease;+}++.history-item:hover .delete-btn {+ opacity: 1;+}+.history-info {- padding: 0;+ padding: 0; /* 移除额外的内边距 */}.history-title {font-weight: 500;- font-size: 1rem;- margin-bottom: 4px;+ font-size: 0.95rem; /* 减小字体大小 */+ margin-bottom: 2px; /* 减小底部边距 */overflow: hidden;text-overflow: ellipsis;white-space: nowrap;@@ -639,9 +662,10 @@ body {.history-meta {color: #bbb;- font-size: 0.8rem;+ font-size: 0.75rem; /* 减小字体大小 */display: flex;flex-wrap: wrap;+ margin-bottom: 1px; /* 减小边距 */}.history-episode {@@ -654,8 +678,8 @@ body {.history-time {color: #888;- font-size: 0.75rem;- margin-top: 4px;+ font-size: 0.7rem; /* 减小字体大小 */+ margin-top: 1px; /* 减小顶部边距 */}.history-separator {diff --git a/index.html b/index.htmlindex b0578c9..8526702 100644--- a/index.html+++ b/index.html@@ -50,17 +50,17 @@</div><!-- 历史记录面板 -->- <div id="historyPanel" class="history-panel fixed left-0 top-0 h-full w-80 bg-[#111] border-r border-[#333] p-6 z-40 overflow-y-auto transform -translate-x-full transition-transform duration-300" aria-label="观看历史" aria-hidden="true">+ <div id="historyPanel" class="history-panel fixed left-0 top-0 h-full bg-[#111] border-r border-[#333] p-6 z-40 transform -translate-x-full transition-transform duration-300" aria-label="观看历史" aria-hidden="true"><div class="flex justify-between items-center mb-6"><h3 class="text-xl font-bold gradient-text">观看历史</h3><button onclick="toggleHistory()" class="text-gray-400 hover:text-white" aria-label="关闭历史">×</button></div>- <div id="historyList" class="space-y-4">+ <div id="historyList" class="pb-4"><!-- 历史记录将在这里动态显示 --><div class="text-center text-gray-500 py-8">暂无观看记录</div></div>- <div class="mt-6 text-center">- <button onclick="clearViewingHistory()" class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg text-sm transition-colors">+ <div class="mt-4 text-center sticky bottom-0 pb-2 pt-2 bg-[#111]">+ <button onclick="clearViewingHistory()" class="px-4 py-2 w-full bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500 hover:from-indigo-600 hover:via-purple-600 hover:to-pink-600 text-white rounded-lg text-sm transition-all duration-300 shadow-md hover:shadow-lg">清空历史记录</button></div>diff --git a/js/app.js b/js/app.jsindex 8441e75..9d7ebdd 100644--- a/js/app.js+++ b/js/app.js@@ -878,19 +878,23 @@ function playVideo(url, vod_name, episodeIndex = 0) {localStorage.setItem('currentEpisodes', JSON.stringify(currentEpisodes));localStorage.setItem('episodesReversed', episodesReversed);+ // 构建视频信息对象,使用标题作为唯一标识+ const videoTitle = vod_name || currentVideoTitle;+ const videoInfo = {+ title: videoTitle,+ url: url,+ episodeIndex: episodeIndex,+ sourceName: sourceName,+ timestamp: Date.now()+ };+// 保存到观看历史,添加sourceNameif (typeof addToViewingHistory === 'function') {- addToViewingHistory({- title: vod_name || currentVideoTitle,- url: url,- episodeIndex: episodeIndex,- sourceName: sourceName,- timestamp: Date.now()- });+ addToViewingHistory(videoInfo);}// 构建播放页面URL,传递必要参数- const playerUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(vod_name)}&index=${episodeIndex}`;+ const playerUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(videoTitle)}&index=${episodeIndex}&source=${encodeURIComponent(sourceName)}`;// 在新标签页中打开播放页面window.open(playerUrl, '_blank');diff --git a/js/ui.js b/js/ui.jsindex 1026099..df2269f 100644--- a/js/ui.js+++ b/js/ui.js@@ -229,7 +229,7 @@ function clearSearchHistory() {showToast('搜索历史已清除', 'success');} catch (e) {console.error('清除搜索历史失败:', e);- showToast('清除搜索历史失败', 'error');+ showToast('清除搜索历史失败:', 'error');}}@@ -326,9 +326,19 @@ function loadViewingHistory() {const episodeText = item.episodeIndex !== undefined ?`第${item.episodeIndex + 1}集` : '';- // 构建历史记录项HTML,移除缩略图,添加来源信息+ // 为防止XSS,使用encodeURIComponent编码URL+ const safeURL = encodeURIComponent(item.url);++ // 构建历史记录项HTML,添加删除按钮,需要放在position:relative的容器中return `- <div class="history-item cursor-pointer" onclick="playFromHistory('${item.url}', '${safeTitle}', ${item.episodeIndex || 0})">+ <div class="history-item cursor-pointer relative group" onclick="playFromHistory('${item.url}', '${safeTitle}', ${item.episodeIndex || 0})">+ <button onclick="event.stopPropagation(); deleteHistoryItem('${safeURL}')"+ class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity duration-200 text-gray-400 hover:text-red-400 p-1 rounded-full hover:bg-gray-800 z-10"+ title="删除记录">+ <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>+ </button><div class="history-info"><div class="history-title">${safeTitle}</div><div class="history-meta">@@ -341,33 +351,86 @@ function loadViewingHistory() {</div>`;}).join('');++ // 检查是否存在较多历史记录,添加底部边距确保底部按钮不会挡住内容+ if (history.length > 5) {+ historyList.classList.add('pb-4');+ }+}++// 删除单个历史记录项+function deleteHistoryItem(encodedUrl) {+ try {+ // 解码URL+ const url = decodeURIComponent(encodedUrl);++ // 获取当前历史记录+ const history = getViewingHistory();++ // 过滤掉要删除的项+ const newHistory = history.filter(item => item.url !== url);++ // 保存回localStorage+ localStorage.setItem('viewingHistory', JSON.stringify(newHistory));++ // 重新加载历史记录显示+ loadViewingHistory();++ // 显示成功提示+ showToast('已删除该记录', 'success');+ } catch (e) {+ console.error('删除历史记录项失败:', e);+ showToast('删除记录失败', 'error');+ }}// 从历史记录播放function playFromHistory(url, title, episodeIndex) {// 构造播放页面URL并跳转- const playerUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&index=${episodeIndex}`;- window.open(playerUrl, '_blank');+ // 检查URL是否已经包含必要参数+ if (url.includes('?')) {+ // URL已有参数,添加&index=+ const playUrl = `${url}${url.includes('index=') ? '' : `&index=${episodeIndex}`}`;+ window.open(playUrl, '_blank');+ } else {+ // 原始URL,添加完整参数+ const playerUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&index=${episodeIndex}`;+ window.open(playerUrl, '_blank');+ }}-// 添加观看历史+// 添加观看历史 - 确保每个视频标题只有一条记录function addToViewingHistory(videoInfo) {try {const history = getViewingHistory();- // 检查是否已经存在相同的项目(基于URL)- const existingIndex = history.findIndex(item => item.url === videoInfo.url);+ // 检查是否已经存在相同标题的记录(同一视频的不同集数)+ const existingIndex = history.findIndex(item => item.title === videoInfo.title);if (existingIndex !== -1) {- // 存在则移除旧的记录+ // 存在则更新现有记录的集数和时间戳+ const existingItem = history[existingIndex];+ existingItem.episodeIndex = videoInfo.episodeIndex;+ existingItem.timestamp = Date.now();++ // 确保来源信息保留+ if (videoInfo.sourceName && !existingItem.sourceName) {+ existingItem.sourceName = videoInfo.sourceName;+ }++ // 更新URL,确保能够跳转到正确的集数+ existingItem.url = videoInfo.url;++ // 移到最前面history.splice(existingIndex, 1);+ history.unshift(existingItem);+ } else {+ // 添加新记录到最前面+ history.unshift({+ ...videoInfo,+ timestamp: Date.now()+ });}- // 添加新记录到最前面- history.unshift({- ...videoInfo,- timestamp: Date.now()- });-// 限制历史记录数量为50条const maxHistoryItems = 50;if (history.length > maxHistoryItems) {diff --git a/player.html b/player.htmlindex 0217f7b..f379635 100644--- a/player.html+++ b/player.html@@ -790,10 +790,17 @@currentEpisodeIndex = index;videoHasEnded = false; // 重置视频结束标志- // 更新URL,不刷新页面+ // 获取当前URL参数,保留source参数+ const urlParams = new URLSearchParams(window.location.search);+ const sourceName = urlParams.get('source') || '';++ // 更新URL,不刷新页面,保留source参数const newUrl = new URL(window.location.href);newUrl.searchParams.set('index', index);newUrl.searchParams.set('url', url);+ if (sourceName) {+ newUrl.searchParams.set('source', sourceName);+ }window.history.pushState({}, '', newUrl);// 更新播放器@@ -829,6 +836,9 @@// 重置用户点击位置记录userClickedPosition = null;++ // 三秒后保存到历史记录+ setTimeout(() => saveToHistory(), 3000);}// 播放上一集@@ -955,7 +965,8 @@// 构建要保存的视频信息对象const videoInfo = {title: currentVideoTitle,- url: window.location.href, // 保存完整URL以便能直接打开+ // 创建基础URL,使用标题作为唯一标识符+ url: `player.html?title=${encodeURIComponent(currentVideoTitle)}&source=${encodeURIComponent(sourceName)}`,episodeIndex: currentEpisodeIndex,sourceName: sourceName,timestamp: Date.now()@@ -969,15 +980,24 @@try {const history = JSON.parse(localStorage.getItem('viewingHistory') || '[]');- // 检查是否已经存在相同的项目- const existingIndex = history.findIndex(item => item.url === videoInfo.url);+ // 检查是否已经存在相同标题的记录(同一视频的不同集数)+ const existingIndex = history.findIndex(item => item.title === videoInfo.title);if (existingIndex !== -1) {- history.splice(existingIndex, 1);+ // 存在则更新现有记录的集数、时间戳和URL+ history[existingIndex].episodeIndex = currentEpisodeIndex;+ history[existingIndex].timestamp = Date.now();+ // 同时更新URL以保存当前的集数状态+ history[existingIndex].url = window.location.href;++ // 移到最前面+ const updatedItem = history.splice(existingIndex, 1)[0];+ history.unshift(updatedItem);+ } else {+ // 添加新记录到最前面,但保存完整URL以便能直接打开到正确的集数+ videoInfo.url = window.location.href;+ history.unshift(videoInfo);}- // 添加新记录到最前面- history.unshift(videoInfo);-// 限制历史记录数量为50条if (history.length > 50) history.splice(50);