一分钟搭建影视站,支持Docker等部署方式
Enhance back navigation logic to prioritize returning from search page and improve URL handling
developer87efd4fbe542
diff --git a/player.html b/player.htmlindex 19ec6d8..75bf3e9 100644--- a/player.html+++ b/player.html@@ -224,34 +224,75 @@function goBack(e) {e.preventDefault();- // 1. 首先尝试从URL参数获取返回地址+ // 1. 首先检查是否从搜索页面进入的播放器 (优先使用localStorage中的记录)+ const cameFromSearch = localStorage.getItem('cameFromSearch') === 'true';+ const searchPageUrl = localStorage.getItem('searchPageUrl');++ if (cameFromSearch && searchPageUrl) {+ console.log('返回搜索页面:', searchPageUrl);+ window.location.href = searchPageUrl;+ // 清除标记,避免下次返回仍然去搜索页+ localStorage.removeItem('cameFromSearch');+ return;+ }++ // 继续原有的返回逻辑...+ const referrer = document.referrer;++ // 检查referrer是否包含搜索参数+ if (referrer && (referrer.includes('?s=') || referrer.includes('/s='))) {+ // 如果是从搜索页面来的,返回到搜索页面+ console.log('根据referrer返回搜索页面:', referrer);+ window.location.href = referrer;+ return;+ }++ // 2. 尝试从URL参数获取返回地址const urlParams = new URLSearchParams(window.location.search);const returnUrl = urlParams.get('returnUrl');if (returnUrl) {// 存在明确的返回地址+ console.log('使用returnUrl参数返回:', returnUrl);window.location.href = returnUrl;return;}- // 2. 其次尝试从localStorage中获取上一页URL+ // 3. 如果是在iframe中打开的,尝试关闭iframe+ if (closeEmbeddedPlayer()) {+ console.log('关闭了嵌入式播放器');+ return;+ }++ // 4. 其次尝试从localStorage中获取上一页URLconst lastPageUrl = localStorage.getItem('lastPageUrl');if (lastPageUrl && lastPageUrl !== window.location.href) {+ console.log('从localStorage返回:', lastPageUrl);window.location.href = lastPageUrl;return;}- // 3. 最后使用浏览器历史记录- if (document.referrer && document.referrer !== window.location.href) {- window.location.href = document.referrer;- } else {- // 没有任何有效的返回地址,返回首页- window.location.href = '/';+ // 5. 检查referrer是否是有效的站内页面+ if (referrer &&+ referrer !== window.location.href &&+ (referrer.includes(window.location.hostname) || referrer.startsWith('/'))) {+ console.log('返回referrer页面:', referrer);+ window.location.href = referrer;+ return;}++ // 6. 都不满足时,返回首页+ console.log('返回首页');+ window.location.href = '/';}// 页面加载时保存当前URL到localStorage,作为返回目标window.addEventListener('load', function() {+ // 保存前一页面URL+ if (document.referrer && document.referrer !== window.location.href) {+ localStorage.setItem('lastPageUrl', document.referrer);+ }+// 提取当前URL中的重要参数,以便在需要时能够恢复当前页面const urlParams = new URLSearchParams(window.location.search);const videoId = urlParams.get('id');@@ -345,7 +386,7 @@<!-- 复制链接按钮 --><button title="复制播放链接" onclick="copyLinks()" class="px-2 py-1 bg-[#222] hover:bg-[#333] border border-[#333] text-white rounded-lg transition"><svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" />+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 012-2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" /></svg></button>@@ -1771,10 +1812,18 @@: '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d=\"M15 11V7a3 3 0 00-6 0v4m-3 4h12v6H6v-6z\"/>';}- // 返回上一页- function goBack() {- const parentWindow = window.parent;- parentWindow.closeVideoPlayer();+ // 支持在iframe中关闭播放器+ function closeEmbeddedPlayer() {+ try {+ if (window.self !== window.top) {+ // 如果在iframe中,尝试调用父窗口的关闭方法+ window.parent.closeVideoPlayer && window.parent.closeVideoPlayer();+ return true;+ }+ } catch (e) {+ console.error('尝试关闭嵌入式播放器失败:', e);+ }+ return false;}</script></body>