一分钟搭建影视站,支持Docker等部署方式
Add files via upload
ykq0072fb1efab3ced
diff --git a/js/app.js b/js/app.jsindex 868c2af..6512e82 100644--- a/js/app.js+++ b/js/app.js@@ -810,16 +810,16 @@ async function search() {const safeResults = allResults.map(item => {const safeId = item.vod_id ? item.vod_id.toString().replace(/[^\w-]/g, '') : '';const safeName = (item.vod_name || '').toString()- .replace(/</g, '<')- .replace(/>/g, '>')- .replace(/"/g, '"');+ .replace(/</g, '<')+ .replace(/>/g, '>')+ .replace(/"/g, '"');const sourceInfo = item.source_name ?`<span class="bg-[#222] text-xs px-1.5 py-0.5 rounded-full">${item.source_name}</span>` : '';const sourceCode = item.source_code || '';// 添加API URL属性,用于详情获取const apiUrlAttr = item.api_url ?- `data-api-url="${item.api_url.replace(/"/g, '"')}"` : '';+ `data-api-url="${item.api_url.replace(/"/g, '"')}"` : '';// 修改为水平卡片布局,图片在左侧,文本在右侧,并优化样式const hasCover = item.vod_pic && item.vod_pic.startsWith('http');@@ -842,9 +842,9 @@ async function search() {<h3 class="font-semibold mb-2 break-words line-clamp-2 ${hasCover ? '' : 'text-center'}" title="${safeName}">${safeName}</h3><div class="flex flex-wrap ${hasCover ? '' : 'justify-center'} gap-1 mb-2">- ${(item.type_name || '').toString().replace(/</g, '<') ?+ ${(item.type_name || '').toString().replace(/</g, '<') ?`<span class="text-xs py-0.5 px-1.5 rounded bg-opacity-20 bg-blue-500 text-blue-300">- ${(item.type_name || '').toString().replace(/</g, '<')}+ ${(item.type_name || '').toString().replace(/</g, '<')}</span>` : ''}${(item.vod_year || '') ?`<span class="text-xs py-0.5 px-1.5 rounded bg-opacity-20 bg-purple-500 text-purple-300">@@ -852,7 +852,7 @@ async function search() {</span>` : ''}</div><p class="text-gray-400 line-clamp-2 overflow-hidden ${hasCover ? '' : 'text-center'} mb-2">- ${(item.vod_remarks || '暂无介绍').toString().replace(/</g, '<')}+ ${(item.vod_remarks || '暂无介绍').toString().replace(/</g, '<')}</p></div>@@ -876,6 +876,8 @@ async function search() {}).join('');resultsDiv.innerHTML = safeResults;+ sessionStorage.setItem('cachedSearchResults', JSON.stringify(allResults));+ sessionStorage.setItem('cachedQuery', query);} catch (error) {console.error('搜索错误:', error);if (error.name === 'AbortError') {@@ -1176,7 +1178,7 @@ function renderEpisodes(vodName, sourceCode, vodId) {// 根据倒序状态计算真实的剧集索引const realIndex = episodesReversed ? currentEpisodes.length - 1 - index : index;return `- <button id="episode-${realIndex}" onclick="playVideo('${episode}','${vodName.replace(/"/g, '"')}', '${sourceCode}', ${realIndex}, '${vodId}')"+ <button id="episode-${realIndex}" onclick="playVideo('${episode}','${vodName.replace(/"/g, '"')}', '${sourceCode}', ${realIndex}, '${vodId}')"class="px-4 py-2 bg-[#222] hover:bg-[#333] border border-[#333] rounded-lg transition-colors text-center episode-btn">${realIndex + 1}</button>@@ -1431,4 +1433,149 @@ function saveStringAsFile(content, fileName) {window.URL.revokeObjectURL(url);}+function renderSearchResultsFromCache(results) {+ if (!results || results.length === 0) return false;+ const resultsDiv = document.getElementById('results');+ if (!resultsDiv) return false;+ document.getElementById('searchArea').classList.remove('flex-1');+ document.getElementById('searchArea').classList.add('mb-8');+ document.getElementById('resultsArea').classList.remove('hidden');+ const searchResultsCount = document.getElementById('searchResultsCount');+ if (searchResultsCount) {+ searchResultsCount.textContent = results.length;+ }+ let html = '';+ results.forEach(item => {+ const safeId = item.vod_id ? item.vod_id.toString().replace(/[^\w-]/g, '') : '';+ const safeName = (item.vod_name || '').toString()+ .replace(/</g, '<')+ .replace(/>/g, '>')+ .replace(/"/g, '"');+ html += `<div onclick="showDetails('${safeId}', '${safeName}', '${item.source_code}')">${safeName}</div>`;+ });+ resultsDiv.innerHTML = html;+ return true;+}++function restoreSearchFromCache() {+ const cachedResults = sessionStorage.getItem('cachedSearchResults');+ const cachedQuery = sessionStorage.getItem('cachedQuery');+ if (cachedResults && cachedQuery) {+ const searchInput = document.getElementById('searchInput');+ searchInput.value = cachedQuery;++ // Show loading state+ showLoading();++ // Show results area+ document.getElementById('searchArea').classList.remove('flex-1');+ document.getElementById('searchArea').classList.add('mb-8');+ document.getElementById('resultsArea').classList.remove('hidden');++ // Hide douban area if exists+ const doubanArea = document.getElementById('doubanArea');+ if (doubanArea) {+ doubanArea.classList.add('hidden');+ }++ // Parse and render results+ const results = JSON.parse(cachedResults);+ const resultsDiv = document.getElementById('results');++ if (!results || results.length === 0) {+ resultsDiv.innerHTML = `+ <div class="col-span-full text-center py-16">+ <svg class="mx-auto h-12 w-12 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"+ d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />+ </svg>+ <h3 class="mt-2 text-lg font-medium text-gray-400">没有找到匹配的结果</h3>+ <p class="mt-1 text-sm text-gray-500">请尝试其他关键词或更换数据源</p>+ </div>+ `;+ hideLoading();+ return true;+ }++ // Update search results count+ const searchResultsCount = document.getElementById('searchResultsCount');+ if (searchResultsCount) {+ searchResultsCount.textContent = results.length;+ }++ // Format and display results using the same HTML structure as the search function+ const safeResults = results.map(item => {+ const safeId = item.vod_id ? item.vod_id.toString().replace(/[^\w-]/g, '') : '';+ const safeName = (item.vod_name || '').toString()+ .replace(/</g, '<')+ .replace(/>/g, '>')+ .replace(/"/g, '"');+ const sourceInfo = item.source_name ?+ `<span class="bg-[#222] text-xs px-1.5 py-0.5 rounded-full">${item.source_name}</span>` : '';+ const sourceCode = item.source_code || '';+ const apiUrlAttr = item.api_url ?+ `data-api-url="${item.api_url.replace(/"/g, '"')}"` : '';+ const hasCover = item.vod_pic && item.vod_pic.startsWith('http');++ return `+ <div class="card-hover bg-[#111] rounded-lg overflow-hidden cursor-pointer transition-all hover:scale-[1.02] h-full shadow-sm hover:shadow-md"+ onclick="showDetails('${safeId}','${safeName}','${sourceCode}')" ${apiUrlAttr}>+ <div class="flex h-full">+ ${hasCover ? `+ <div class="relative flex-shrink-0 search-card-img-container">+ <img src="${item.vod_pic}" alt="${safeName}"+ class="h-full w-full object-cover transition-transform hover:scale-110"+ onerror="this.onerror=null; this.src='https://via.placeholder.com/300x450?text=无封面'; this.classList.add('object-contain');"+ loading="lazy">+ <div class="absolute inset-0 bg-gradient-to-r from-black/30 to-transparent"></div>+ </div>` : ''}++ <div class="p-2 flex flex-col flex-grow">+ <div class="flex-grow">+ <h3 class="font-semibold mb-2 break-words line-clamp-2 ${hasCover ? '' : 'text-center'}" title="${safeName}">${safeName}</h3>++ <div class="flex flex-wrap ${hasCover ? '' : 'justify-center'} gap-1 mb-2">+ ${(item.type_name || '').toString().replace(/</g, '<') ?+ `<span class="text-xs py-0.5 px-1.5 rounded bg-opacity-20 bg-blue-500 text-blue-300">+ ${(item.type_name || '').toString().replace(/</g, '<')}+ </span>` : ''}+ ${(item.vod_year || '') ?+ `<span class="text-xs py-0.5 px-1.5 rounded bg-opacity-20 bg-purple-500 text-purple-300">+ ${item.vod_year}+ </span>` : ''}+ </div>+ <p class="text-gray-400 line-clamp-2 overflow-hidden ${hasCover ? '' : 'text-center'} mb-2">+ ${(item.vod_remarks || '暂无介绍').toString().replace(/</g, '<')}+ </p>+ </div>++ <div class="flex justify-between items-center mt-1 pt-1 border-t border-gray-800">+ ${sourceInfo ? `<div>${sourceInfo}</div>` : '<div></div>'}+ </div>+ </div>+ </div>+ </div>+ `;+ }).join('');++ resultsDiv.innerHTML = safeResults;+ hideLoading();++ // Update URL to show search query+ try {+ const encodedQuery = encodeURIComponent(cachedQuery);+ window.history.replaceState(+ { search: cachedQuery },+ `搜索: ${cachedQuery} - LibreTV`,+ `/s=${encodedQuery}`+ );+ document.title = `搜索: ${cachedQuery} - LibreTV`;+ } catch (e) {+ console.error('更新浏览器历史失败:', e);+ }++ return true;+ }+ return false;+}// 移除Node.js的require语句,因为这是在浏览器环境中运行的diff --git a/js/index-page.js b/js/index-page.jsindex e88d63e..291bbed 100644--- a/js/index-page.js+++ b/js/index-page.js@@ -24,6 +24,18 @@ document.addEventListener('DOMContentLoaded', function() {// 播放URL,不做额外处理,watch.html会处理重定向return;}++ // 判断是否从播放页返回+ const isReturningFromPlayer = localStorage.getItem('returningFromPlayer') === 'true';+ if (isReturningFromPlayer) {+ localStorage.removeItem('returningFromPlayer');+ if (typeof restoreSearchFromCache === 'function') {+ const restored = restoreSearchFromCache();+ if (restored) {+ return; // 直接恢复缓存结果,跳过后续搜索逻辑+ }+ }+ }// 检查页面路径中的搜索参数 (格式: /s=keyword)const path = window.location.pathname;diff --git a/js/player.js b/js/player.jsindex 0da055f..037cb7b 100644--- a/js/player.js+++ b/js/player.js@@ -1,35 +1,37 @@-// 改进返回功能function goBack(event) {// 防止默认链接行为if (event) event.preventDefault();-++ // 设置返回标志,通知首页恢复缓存搜索结果+ localStorage.setItem('returningFromPlayer', 'true');+// 1. 优先检查URL参数中的returnUrlconst urlParams = new URLSearchParams(window.location.search);const returnUrl = urlParams.get('returnUrl');-+if (returnUrl) {// 如果URL中有returnUrl参数,优先使用window.location.href = decodeURIComponent(returnUrl);return;}-+// 2. 检查localStorage中保存的lastPageUrlconst lastPageUrl = localStorage.getItem('lastPageUrl');if (lastPageUrl && lastPageUrl !== window.location.href) {window.location.href = lastPageUrl;return;}-+// 3. 检查是否是从搜索页面进入的播放器const referrer = document.referrer;-+// 检查 referrer 是否包含搜索参数if (referrer && (referrer.includes('/s=') || referrer.includes('?s='))) {// 如果是从搜索页面来的,返回到搜索页面window.location.href = referrer;return;}-+// 4. 如果是在iframe中打开的,尝试关闭iframeif (window.self !== window.top) {try {@@ -40,13 +42,13 @@ function goBack(event) {console.error('调用父窗口closeVideoPlayer失败:', e);}}-+// 5. 无法确定上一页,则返回首页if (!referrer || referrer === '') {window.location.href = '/';return;}-+// 6. 以上都不满足,使用默认行为:返回上一页window.history.back();}