Skip to content

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

test

developer4c4cd71ac3ad
diff --git a/index.html b/index.html
index 8225cdf..3b20c58 100644
--- a/index.html
+++ b/index.html
@@ -454,7 +454,13 @@
<script>
// 在页面加载完成后检查URL中的搜索参数
document.addEventListener('DOMContentLoaded', function() {
- // 首先检查页面路径中的搜索参数 (格式: /s=keyword)
+ // 首先检查是否是播放URL格式 (/watch 开头的路径)
+ if (window.location.pathname.startsWith('/watch')) {
+ // 播放URL,不做额外处理,watch.html会处理重定向
+ return;
+ }
+
+ // 检查页面路径中的搜索参数 (格式: /s=keyword)
const path = window.location.pathname;
const searchPrefix = '/s=';
@@ -492,6 +498,16 @@
// 执行搜索
setTimeout(() => {
search();
+ // 更新URL为规范格式
+ try {
+ window.history.replaceState(
+ { search: searchQuery },
+ `搜索: ${searchQuery} - LibreTV`,
+ `/s=${encodeURIComponent(searchQuery)}`
+ );
+ } catch (e) {
+ console.error('更新浏览器历史失败:', e);
+ }
}, 300);
}
});
diff --git a/js/app.js b/js/app.js
index 82ffc3c..2ccf5ce 100644
--- a/js/app.js
+++ b/js/app.js
@@ -990,7 +990,7 @@ async function showDetails(id, vod_name, sourceCode) {
}
}
-// 更新播放视频函数,修改为在新标签页中打开播放页面,并保存到历史记录
+// 更新播放视频函数,修改为使用/watch路径而不是直接打开player.html
function playVideo(url, vod_name, sourceCode, episodeIndex = 0) {
// 密码保护校验
if (window.isPasswordProtected && window.isPasswordVerified) {
@@ -1000,52 +1000,33 @@ function playVideo(url, vod_name, sourceCode, episodeIndex = 0) {
}
}
if (!url) {
- showToast('无效的视频链接', 'error');
+ showToast('视频地址无效', 'error');
return;
}
- // 获取当前视频来源名称(从模态框标题中提取)
- let sourceName = '';
- const modalTitle = document.getElementById('modalTitle');
- if (modalTitle) {
- const sourceSpan = modalTitle.querySelector('span.text-gray-400');
- if (sourceSpan) {
- // 提取括号内的来源名称, 例如从 "(黑木耳)" 提取 "黑木耳"
- const sourceText = sourceSpan.textContent;
- const match = sourceText.match(/\(([^)]+)\)/);
- if (match && match[1]) {
- sourceName = match[1].trim();
- }
- }
- }
+ // 获取当前路径作为返回页面
+ let currentPath = window.location.href;
- // 保存当前状态到localStorage,让播放页面可以获取
- const currentVideoTitle = vod_name;
- localStorage.setItem('currentVideoTitle', currentVideoTitle);
- localStorage.setItem('currentEpisodeIndex', episodeIndex);
- localStorage.setItem('currentEpisodes', JSON.stringify(currentEpisodes));
- localStorage.setItem('episodesReversed', episodesReversed);
+ // 构建播放页面URL,使用watch.html作为中间跳转页
+ let watchUrl = `watch.html?id=${currentEpisodes[episodeIndex].id || ''}&source=${sourceCode || ''}&url=${encodeURIComponent(url)}&index=${episodeIndex}&title=${encodeURIComponent(vod_name || '')}`;
- // 构建视频信息对象,使用标题作为唯一标识
- const videoTitle = vod_name || currentVideoTitle;
- const videoInfo = {
- title: videoTitle,
- url: url,
- episodeIndex: episodeIndex,
- sourceName: sourceName,
- timestamp: Date.now(),
- // 重要:将完整的剧集信息也添加到历史记录中
- episodes: currentEpisodes && currentEpisodes.length > 0 ? [...currentEpisodes] : []
- };
+ // 添加返回URL参数
+ watchUrl += `&back=${encodeURIComponent(currentPath)}`;
- // 保存到观看历史,添加sourceName
- if (typeof addToViewingHistory === 'function') {
- addToViewingHistory(videoInfo);
+ // 保存当前状态到localStorage
+ try {
+ localStorage.setItem('currentVideoTitle', vod_name || '未知视频');
+ localStorage.setItem('currentEpisodes', JSON.stringify(currentEpisodes));
+ localStorage.setItem('currentEpisodeIndex', episodeIndex);
+ localStorage.setItem('currentSourceCode', sourceCode || '');
+ localStorage.setItem('lastPlayTime', Date.now());
+ localStorage.setItem('lastSearchPage', currentPath);
+ } catch (e) {
+ console.error('保存播放状态失败:', e);
}
- // 构建播放页面URL,传递必要参数
- const playerUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(videoTitle)}&index=${episodeIndex}&source=${encodeURIComponent(sourceName)}&source_code=${encodeURIComponent(sourceCode)}`;
- showVideoPlayer(playerUrl);
+ // 在新窗口/标签页中打开播放页面
+ window.open(watchUrl, '_blank');
}
// 弹出播放器页面
diff --git a/js/douban.js b/js/douban.js
index 888f46f..9b4c26d 100644
--- a/js/douban.js
+++ b/js/douban.js
@@ -169,6 +169,22 @@ function fillAndSearch(title) {
if (input) {
input.value = safeTitle;
search(); // 使用已有的search函数执行搜索
+
+ // 同时更新浏览器URL,使其反映当前的搜索状态
+ try {
+ // 使用URI编码确保特殊字符能够正确显示
+ const encodedQuery = encodeURIComponent(safeTitle);
+ // 使用HTML5 History API更新URL,不刷新页面
+ window.history.pushState(
+ { search: safeTitle },
+ `搜索: ${safeTitle} - LibreTV`,
+ `/s=${encodedQuery}`
+ );
+ // 更新页面标题
+ document.title = `搜索: ${safeTitle} - LibreTV`;
+ } catch (e) {
+ console.error('更新浏览器历史失败:', e);
+ }
}
}
@@ -213,6 +229,22 @@ async function fillAndSearchWithDouban(title) {
if (input) {
input.value = safeTitle;
await search(); // 使用已有的search函数执行搜索
+
+ // 更新浏览器URL,使其反映当前的搜索状态
+ try {
+ // 使用URI编码确保特殊字符能够正确显示
+ const encodedQuery = encodeURIComponent(safeTitle);
+ // 使用HTML5 History API更新URL,不刷新页面
+ window.history.pushState(
+ { search: safeTitle },
+ `搜索: ${safeTitle} - LibreTV`,
+ `/s=${encodedQuery}`
+ );
+ // 更新页面标题
+ document.title = `搜索: ${safeTitle} - LibreTV`;
+ } catch (e) {
+ console.error('更新浏览器历史失败:', e);
+ }
if (window.innerWidth <= 768) {
window.scrollTo({
diff --git a/player.html b/player.html
index 453013d..a13f74e 100644
--- a/player.html
+++ b/player.html
@@ -211,13 +211,59 @@
</a>
</div>
<h2 id="videoTitle" class="text-xl font-semibold flex-1 text-center overflow-x-auto whitespace-nowrap truncate custom-title-scroll"></h2>
- <a href="#" id="goBack" onclick="goBack()" class="px-4 py-2 bg-[#222] hover:bg-[#333] border border-[#333] rounded-lg transition-colors flex items-center min-w-0 home-btn">
+ <a href="#" id="goBack" onclick="goBack(event)" class="px-4 py-2 bg-[#222] hover:bg-[#333] border border-[#333] rounded-lg transition-colors flex items-center min-w-0 home-btn">
<svg class="w-5 h-5 mr-1" viewBox="0 0 24 24" fill="#ffffff" xmlns="http://www.w3.org/2000/svg">
<path d="M5.25 11h15a1.5 1.5 0 1 1 0 3H5.25a1.5 1.5 0 0 1 0-3z"/>
<path d="M5.55 12 11.3 17.3a1.5 1.5 0 1 1-2.12 2.12L3 12l6.18-6.18a1.5 1.5 0 1 1 2.12 2.12L5.55 12z"/>
</svg>
<span class="home-btn-text">上一页</span>
</a>
+
+ <script>
+ // 改进返回功能
+ function goBack(e) {
+ e.preventDefault();
+
+ // 1. 首先尝试从URL参数获取返回地址
+ const urlParams = new URLSearchParams(window.location.search);
+ const returnUrl = urlParams.get('returnUrl');
+
+ if (returnUrl) {
+ // 存在明确的返回地址
+ window.location.href = returnUrl;
+ return;
+ }
+
+ // 2. 其次尝试从localStorage中获取上一页URL
+ const lastPageUrl = localStorage.getItem('lastPageUrl');
+ if (lastPageUrl && lastPageUrl !== window.location.href) {
+ window.location.href = lastPageUrl;
+ return;
+ }
+
+ // 3. 最后使用浏览器历史记录
+ if (document.referrer && document.referrer !== window.location.href) {
+ window.location.href = document.referrer;
+ } else {
+ // 没有任何有效的返回地址,返回首页
+ window.location.href = '/';
+ }
+ }
+
+ // 页面加载时保存当前URL到localStorage,作为返回目标
+ window.addEventListener('load', function() {
+ // 提取当前URL中的重要参数,以便在需要时能够恢复当前页面
+ const urlParams = new URLSearchParams(window.location.search);
+ const videoId = urlParams.get('id');
+ const sourceCode = urlParams.get('source');
+
+ if (videoId && sourceCode) {
+ // 保存当前播放状态,以便其他页面可以返回
+ localStorage.setItem('currentPlayingId', videoId);
+ localStorage.setItem('currentPlayingSource', sourceCode);
+ }
+ });
+ </script>
</header>
<!-- 密码验证弹窗 -->
diff --git a/watch.html b/watch.html
index 407a18b..822030a 100644
--- a/watch.html
+++ b/watch.html
@@ -22,16 +22,29 @@
// 获取来源URL (如果存在)
const referrer = document.referrer;
- // 如果有referrer并且包含搜索参数,保存它以便返回
- if (referrer && (referrer.includes('/s=') || referrer.includes('?s='))) {
- // 如果已经有参数,添加&,否则添加?
- playerUrl += playerUrl.includes('?') ? '&' : '?';
- playerUrl += 'referrer=' + encodeURIComponent(referrer);
-
- // 同时保存在localStorage中,作为备用
- localStorage.setItem('lastSearchPage', referrer);
+ // 获取当前URL中的返回URL参数(如果有)
+ const backUrl = currentParams.get('back');
+
+ // 确定返回URL的优先级:1. 指定的back参数 2. referrer 3. 搜索页面
+ let returnUrl = '';
+ if (backUrl) {
+ // 有显式指定的返回URL
+ returnUrl = decodeURIComponent(backUrl);
+ } else if (referrer && (referrer.includes('/s=') || referrer.includes('?s='))) {
+ // 来源是搜索页面
+ returnUrl = referrer;
+ } else {
+ // 默认回到首页
+ returnUrl = '/';
}
+ // 将返回URL添加到player.html的参数中
+ playerUrl += playerUrl.includes('?') ? '&' : '?';
+ playerUrl += 'returnUrl=' + encodeURIComponent(returnUrl);
+
+ // 同时保存在localStorage中,作为备用
+ localStorage.setItem('lastPageUrl', returnUrl);
+
// 重定向到播放器页面
window.location.href = playerUrl;
};