Skip to content

一分钟搭建影视站,支持Docker等部署方式

feat(播放器): 改进关闭播放器逻辑并简化返回功能

shinya50e717b69eb4
diff --git a/js/app.js b/js/app.js
index ea3a71a..33e05cd 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1107,7 +1107,7 @@ function showVideoPlayer(url) {
}
// 关闭播放器页面
-function closeVideoPlayer() {
+function closeVideoPlayer(home = false) {
videoPlayerFrame = document.getElementById('VideoPlayerFrame');
if (videoPlayerFrame) {
videoPlayerFrame.remove();
@@ -1123,6 +1123,9 @@ function closeVideoPlayer() {
document.getElementById('doubanArea').classList.remove('hidden');
}
}
+ if (home) {
+ resetToHome();
+ }
}
// 播放上一集
diff --git a/js/player.js b/js/player.js
index fcfbabe..80f9c8a 100644
--- a/js/player.js
+++ b/js/player.js
@@ -1,67 +1,54 @@
// 改进返回功能
-function goBack(e) {
- if (e) e.preventDefault();
-
- // 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参数获取返回地址
+function goBack(event) {
+ // 防止默认链接行为
+ if (event) event.preventDefault();
+
+ // 1. 优先检查URL参数中的returnUrl
const urlParams = new URLSearchParams(window.location.search);
const returnUrl = urlParams.get('returnUrl');
-
+
if (returnUrl) {
- // 存在明确的返回地址
- console.log('使用returnUrl参数返回:', decodeURIComponent(returnUrl)); // decodeURIComponent added
- window.location.href = decodeURIComponent(returnUrl); // decodeURIComponent added
- return;
- }
-
- // 3. 如果是在iframe中打开的,尝试关闭iframe
- if (closeEmbeddedPlayer()) {
- console.log('关闭了嵌入式播放器');
+ // 如果URL中有returnUrl参数,优先使用
+ window.location.href = decodeURIComponent(returnUrl);
return;
}
-
- // 4. 其次尝试从localStorage中获取上一页URL
+
+ // 2. 检查localStorage中保存的lastPageUrl
const lastPageUrl = localStorage.getItem('lastPageUrl');
if (lastPageUrl && lastPageUrl !== window.location.href) {
- console.log('从localStorage返回:', lastPageUrl);
window.location.href = lastPageUrl;
return;
}
-
- // 5. 检查referrer是否是有效的站内页面
- if (referrer &&
- referrer !== window.location.href &&
- (referrer.includes(window.location.hostname) || referrer.startsWith('/'))) {
- console.log('返回referrer页面:', referrer);
+
+ // 3. 检查是否是从搜索页面进入的播放器
+ const referrer = document.referrer;
+
+ // 检查 referrer 是否包含搜索参数
+ if (referrer && (referrer.includes('/s=') || referrer.includes('?s='))) {
+ // 如果是从搜索页面来的,返回到搜索页面
window.location.href = referrer;
return;
}
-
- // 6. 都不满足时,返回首页
- console.log('返回首页');
- window.location.href = '/';
+
+ // 4. 如果是在iframe中打开的,尝试关闭iframe
+ if (window.self !== window.top) {
+ try {
+ // 尝试调用父窗口的关闭播放器函数
+ window.parent.closeVideoPlayer && window.parent.closeVideoPlayer();
+ return;
+ } catch (e) {
+ console.error('调用父窗口closeVideoPlayer失败:', e);
+ }
+ }
+
+ // 5. 无法确定上一页,则返回首页
+ if (!referrer || referrer === '') {
+ window.location.href = '/';
+ return;
+ }
+
+ // 6. 以上都不满足,使用默认行为:返回上一页
+ window.history.back();
}
// 页面加载时保存当前URL到localStorage,作为返回目标
diff --git a/player.html b/player.html
index 5f0ab3c..891cbd9 100644
--- a/player.html
+++ b/player.html
@@ -339,37 +339,7 @@
// PASSWORD 变量将在这里被服务器端注入
window.__ENV__.PASSWORD = "{{PASSWORD}}";
- // 直接导航到首页的备份方法,强制清理和导航
- function directNavigateHome() {
- console.log('Direct home navigation triggered');
- try {
- // 停止所有音频和视频
- document.querySelectorAll('video, audio').forEach(media => {
- try {
- media.pause();
- media.muted = true;
- media.src = '';
- } catch (e) {}
- });
-
- // 关闭播放器
- if (window.dp && typeof window.dp.destroy === 'function') {
- try { window.dp.destroy(true); } catch(e) {}
- }
-
- // 清除事件处理程序
- window.onbeforeunload = null;
-
- // 立即导航
- setTimeout(() => { window.location.replace('/'); }, 0);
- } catch(e) {
- // 如果出错,直接导航
- window.location.href = '/';
- }
- return false; // 阻止默认点击事件
- }
-
- // 页面加载完成后初始化事件监听
+ // 修复 home 跳转
document.addEventListener('DOMContentLoaded', function() {
// 使用事件委托处理首页按钮点击
document.body.addEventListener('click', function(event) {
@@ -377,6 +347,18 @@
if (homeButton) {
event.preventDefault();
event.stopPropagation();
+
+ // 如果是在iframe中打开的,尝试关闭iframe
+ if (window.self !== window.top) {
+ try {
+ // 尝试调用父窗口的关闭播放器函数
+ window.parent.closeVideoPlayer && window.parent.closeVideoPlayer(true);
+ return;
+ } catch (e) {
+ console.error('调用父窗口closeVideoPlayer失败:', e);
+ }
+ }
+
// 多重兜底跳转
try {
window.location.href = '/';