一分钟搭建影视站,支持Docker等部署方式
确保从主页中点击不同视频时的剧集数据正确保存
developer9dd6f353c4f5
diff --git a/js/app.js b/js/app.jsindex 40139fa..1611172 100644--- a/js/app.js+++ b/js/app.js@@ -876,6 +876,7 @@ function playVideo(url, vod_name, episodeIndex = 0) {}// 保存当前状态到localStorage,让播放页面可以获取+ const currentVideoTitle = vod_name;localStorage.setItem('currentVideoTitle', currentVideoTitle);localStorage.setItem('currentEpisodeIndex', episodeIndex);localStorage.setItem('currentEpisodes', JSON.stringify(currentEpisodes));@@ -888,7 +889,9 @@ function playVideo(url, vod_name, episodeIndex = 0) {url: url,episodeIndex: episodeIndex,sourceName: sourceName,- timestamp: Date.now()+ timestamp: Date.now(),+ // 重要:将完整的剧集信息也添加到历史记录中+ episodes: currentEpisodes && currentEpisodes.length > 0 ? [...currentEpisodes] : []};// 保存到观看历史,添加sourceNamediff --git a/js/ui.js b/js/ui.jsindex 0001640..6ec8d9a 100644--- a/js/ui.js+++ b/js/ui.js@@ -511,15 +511,38 @@ function addToViewingHistory(videoInfo) {// 更新URL,确保能够跳转到正确的集数existingItem.url = videoInfo.url;+ // 重要:确保episodes数据与当前视频匹配+ // 只有当videoInfo中包含有效的episodes数据时才更新+ if (videoInfo.episodes && Array.isArray(videoInfo.episodes) && videoInfo.episodes.length > 0) {+ // 如果传入的集数数据与当前保存的不同,则更新+ if (!existingItem.episodes ||+ !Array.isArray(existingItem.episodes) ||+ existingItem.episodes.length !== videoInfo.episodes.length) {+ console.log(`更新 "${videoInfo.title}" 的剧集数据: ${videoInfo.episodes.length}集`);+ existingItem.episodes = [...videoInfo.episodes]; // 使用深拷贝+ }+ }+// 移到最前面history.splice(existingIndex, 1);history.unshift(existingItem);} else {- // 添加新记录到最前面- history.unshift({+ // 添加新记录到最前面,确保包含剧集数据+ const newItem = {...videoInfo,timestamp: Date.now()- });+ };++ // 确保episodes字段是一个数组+ if (videoInfo.episodes && Array.isArray(videoInfo.episodes)) {+ newItem.episodes = [...videoInfo.episodes]; // 使用深拷贝+ console.log(`保存新视频 "${videoInfo.title}" 的剧集数据: ${videoInfo.episodes.length}集`);+ } else {+ // 如果没有提供episodes,初始化为空数组+ newItem.episodes = [];+ }++ history.unshift(newItem);}// 限制历史记录数量为50条diff --git a/player.html b/player.htmlindex bb47165..4463944 100644--- a/player.html+++ b/player.html@@ -1078,6 +1078,11 @@// 在播放器初始化后添加视频到历史记录function saveToHistory() {+ // 确保 currentEpisodes 非空+ if (!currentEpisodes || currentEpisodes.length === 0) {+ console.warn('没有可用的剧集列表,无法保存完整的历史记录');+ }+// 尝试从URL中获取参数const urlParams = new URLSearchParams(window.location.search);const sourceName = urlParams.get('source') || '';@@ -1102,13 +1107,14 @@// 添加播放进度信息playbackPosition: currentPosition > 10 ? currentPosition : 0,duration: videoDuration,- // 新增:保存完整的集数列表- episodes: currentEpisodes+ // 重要:保存完整的集数列表,确保进行深拷贝+ episodes: currentEpisodes && currentEpisodes.length > 0 ? [...currentEpisodes] : []};// 如果外部定义了addToViewingHistory函数,则调用它if (typeof addToViewingHistory === 'function') {addToViewingHistory(videoInfo);+ console.log(`已保存 "${currentVideoTitle}" 的历史记录, 集数数据: ${currentEpisodes.length}集`);} else {// 否则直接使用本地实现try {@@ -1125,9 +1131,15 @@history[existingIndex].duration = videoDuration || history[existingIndex].duration;// 同时更新URL以保存当前的集数状态history[existingIndex].url = window.location.href;- // 更新集数列表(如果有)+ // 更新集数列表(如果有且与当前不同)if (currentEpisodes && currentEpisodes.length > 0) {- history[existingIndex].episodes = currentEpisodes;+ // 检查是否需要更新集数数据(针对不同长度的集数列表)+ if (!history[existingIndex].episodes ||+ !Array.isArray(history[existingIndex].episodes) ||+ history[existingIndex].episodes.length !== currentEpisodes.length) {+ history[existingIndex].episodes = [...currentEpisodes]; // 深拷贝+ console.log(`更新 "${currentVideoTitle}" 的剧集数据: ${currentEpisodes.length}集`);+ }}// 移到最前面@@ -1136,6 +1148,7 @@} else {// 添加新记录到最前面,但保存完整URL以便能直接打开到正确的集数videoInfo.url = window.location.href;+ console.log(`创建新的历史记录: "${currentVideoTitle}", ${currentEpisodes.length}集`);history.unshift(videoInfo);}