一分钟搭建影视站,支持Docker等部署方式
feat: enhance URL handling and page redirection logic
developer74c3bef115c0
diff --git a/js/app.js b/js/app.jsindex 6452d41..11308bd 100644--- a/js/app.js+++ b/js/app.js@@ -563,6 +563,19 @@ function resetSearchArea() {if (typeof updateDoubanVisibility === 'function') {updateDoubanVisibility();}++ // 重置URL为主页+ try {+ window.history.pushState(+ {},+ `LibreTV - 免费在线视频搜索与观看平台`,+ `/`+ );+ // 更新页面标题+ document.title = `LibreTV - 免费在线视频搜索与观看平台`;+ } catch (e) {+ console.error('更新浏览器历史失败:', e);+ }}// 获取自定义API信息@@ -595,23 +608,6 @@ async function search() {return;}- // 更新URL以包含搜索查询,方便分享和返回- try {- // 使用URI编码确保特殊字符能够正确显示- const encodedQuery = encodeURIComponent(query);- // 使用HTML5 History API更新URL,不刷新页面- window.history.pushState(- { search: query },- `搜索: ${query} - LibreTV`,- `/s=${encodedQuery}`- );- // 更新页面标题- document.title = `搜索: ${query} - LibreTV`;- } catch (e) {- console.error('更新浏览器历史失败:', e);- // 如果更新URL失败,继续执行搜索- }-showLoading();try {@@ -783,6 +779,23 @@ async function search() {return;}+ // 有搜索结果时,才更新URL+ try {+ // 使用URI编码确保特殊字符能够正确显示+ const encodedQuery = encodeURIComponent(query);+ // 使用HTML5 History API更新URL,不刷新页面+ window.history.pushState(+ { search: query },+ `搜索: ${query} - LibreTV`,+ `/s=${encodedQuery}`+ );+ // 更新页面标题+ document.title = `搜索: ${query} - LibreTV`;+ } catch (e) {+ console.error('更新浏览器历史失败:', e);+ // 如果更新URL失败,继续执行搜索+ }+// 处理搜索结果过滤:如果启用了黄色内容过滤,则过滤掉分类含有敏感内容的项目const yellowFilterEnabled = localStorage.getItem('yellowFilterEnabled') === 'true';if (yellowFilterEnabled) {diff --git a/player.html b/player.htmlindex 33a1dd2..453013d 100644--- a/player.html+++ b/player.html@@ -1239,7 +1239,14 @@if (sourceCode) {newUrl.searchParams.set('source_code', sourceCode);}- window.history.pushState({}, '', newUrl);++ // 保留referrer参数,如果存在+ const referrer = urlParams.get('referrer');+ if (referrer) {+ newUrl.searchParams.set('referrer', referrer);+ }++ window.history.replaceState({}, '', newUrl);// 更新播放器if (dp) {diff --git a/watch.html b/watch.htmlindex 73880a7..407a18b 100644--- a/watch.html+++ b/watch.html@@ -25,16 +25,21 @@// 如果有referrer并且包含搜索参数,保存它以便返回if (referrer && (referrer.includes('/s=') || referrer.includes('?s='))) {// 如果已经有参数,添加&,否则添加?- const separator = playerUrl.includes('?') ? '&' : '?';- playerUrl += separator + 'referrer=' + encodeURIComponent(referrer);+ playerUrl += playerUrl.includes('?') ? '&' : '?';+ playerUrl += 'referrer=' + encodeURIComponent(referrer);++ // 同时保存在localStorage中,作为备用+ localStorage.setItem('lastSearchPage', referrer);}- // 重定向到player.html- window.location.replace(playerUrl);+ // 重定向到播放器页面+ window.location.href = playerUrl;};</script></head><body>- <p>如果您没有被自动重定向,请<a href="player.html">点击这里</a>前往播放页面。</p>+ <div style="text-align: center; padding-top: 100px;">+ 正在重定向到播放器...+ </div></body></html>