Skip to content

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

feat: add PWA support Signed-off-by: JohnsonRan <[email protected]>

JohnsonRan9220ca8eef98
diff --git a/about.html b/about.html
index 7825efd..9121c47 100644
--- a/about.html
+++ b/about.html
@@ -6,6 +6,7 @@
<title>关于我们 - LibreTV</title>
<script src="libs/tailwindcss.min.js"></script>
<link rel="stylesheet" href="css/styles.css">
+ <link rel="manifest" href="manifest.json">
</head>
<body class="page-bg text-white">
@@ -40,7 +41,7 @@
</div>
</main>
<footer class="mt-12 text-center">
- <a href="index.html" class="text-gray-400 hover:text-white transition-colors">回到首页</a>
+ <a href="/" class="text-gray-400 hover:text-white transition-colors">回到首页</a>
</footer>
</div>
</body>
diff --git a/index.html b/index.html
index e1348b1..8785358 100644
--- a/index.html
+++ b/index.html
@@ -26,6 +26,7 @@
<!-- Favicon -->
<link rel="icon" href="https://images.icon-icons.com/38/PNG/512/retrotv_5520.png">
<link rel="apple-touch-icon" href="https://images.icon-icons.com/38/PNG/512/retrotv_5520.png">
+ <link rel="manifest" href="manifest.json">
<!-- Canonical URL -->
<link rel="canonical" href="https://libretv.is-an.org/">
@@ -409,6 +410,15 @@
<script src="js/app.js"></script>
<script src="js/douban.js"></script>
+ <!-- PWA 注册 -->
+ <script>
+ if ('serviceWorker' in navigator) {
+ window.addEventListener('load', () => {
+ navigator.serviceWorker.register('/service-worker.js');
+ });
+ }
+ </script>
+
<!-- 环境变量注入脚本 -->
<script>
// 创建全局环境变量对象
diff --git a/js/app.js b/js/app.js
index 924a604..2fba93a 100644
--- a/js/app.js
+++ b/js/app.js
@@ -969,8 +969,8 @@ function playVideo(url, vod_name, sourceCode, episodeIndex = 0) {
// 构建播放页面URL,传递必要参数
const playerUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(videoTitle)}&index=${episodeIndex}&source=${encodeURIComponent(sourceName)}&source_code=${encodeURIComponent(sourceCode)}`;
- // 在新标签页中打开播放页面
- window.open(playerUrl, '_blank');
+ // 在当前标签页中打开播放页面
+ window.location.href = playerUrl;
}
// 播放上一集
diff --git a/js/douban.js b/js/douban.js
index d14be3f..2b582ec 100644
--- a/js/douban.js
+++ b/js/douban.js
@@ -89,6 +89,9 @@ function initDouban() {
// 初始更新显示状态
updateDoubanVisibility();
+
+ // 滚动到页面顶部
+ window.scrollTo(0, 0);
}
// 加载用户标签
diff --git a/js/ui.js b/js/ui.js
index 75a276e..ce286e1 100644
--- a/js/ui.js
+++ b/js/ui.js
@@ -483,17 +483,17 @@ function playFromHistory(url, title, episodeIndex, playbackPosition = 0) {
if (playbackPosition > 10) {
playUrl.searchParams.set('position', Math.floor(playbackPosition).toString());
}
- window.open(playUrl.toString(), '_blank');
+ window.location.href = playUrl.toString();
} else {
// 原始URL,构造player页面链接
const playerUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&index=${episodeIndex}${positionParam}`;
- window.open(playerUrl, '_blank');
+ window.location.href = playerUrl;
}
} catch (e) {
console.error('从历史记录播放失败:', e);
// 回退到原始简单URL
const simpleUrl = `player.html?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}&index=${episodeIndex}`;
- window.open(simpleUrl, '_blank');
+ window.location.href = simpleUrl;
}
}
@@ -686,4 +686,3 @@ function clearLocalStorage() {
}
});
}
-
diff --git a/manifest.json b/manifest.json
new file mode 100644
index 0000000..d677fea
--- /dev/null
+++ b/manifest.json
@@ -0,0 +1,18 @@
+{
+ "name": "LibreTV",
+ "short_name": "LibreTV",
+ "description": "免费在线视频搜索与观看平台",
+ "start_url": ".",
+ "display": "standalone",
+ "background_color": "#0f1622",
+ "theme_color": "#000000",
+ "apple-mobile-web-app-capable": "yes",
+ "apple-mobile-web-app-status-bar-style": "black",
+ "icons": [
+ {
+ "src": "https://images.icon-icons.com/38/PNG/512/retrotv_5520.png",
+ "sizes": "512x512",
+ "type": "image/png"
+ }
+ ]
+ }
diff --git a/player.html b/player.html
index 465d075..727349c 100644
--- a/player.html
+++ b/player.html
@@ -4,6 +4,12 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LibreTV 播放器</title>
+
+ <!-- Favicon -->
+ <link rel="icon" href="https://images.icon-icons.com/38/PNG/512/retrotv_5520.png">
+ <link rel="apple-touch-icon" href="https://images.icon-icons.com/38/PNG/512/retrotv_5520.png">
+ <link rel="manifest" href="manifest.json">
+
<script src="libs/tailwindcss.min.js"></script>
<link rel="stylesheet" href="css/styles.css">
<style>
@@ -158,7 +164,7 @@
<body>
<header class="bg-[#111] p-4 flex items-center border-b border-[#333] gap-2 player-header">
<div class="flex items-center min-w-0">
- <a href="index.html" class="flex items-center min-w-0">
+ <a href="/" class="flex items-center min-w-0">
<svg class="w-8 h-8 mr-2 text-[#00ccff] logo-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"></path>
</svg>
@@ -166,7 +172,7 @@
</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="index.html" 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="/" 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 xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 mr-1" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M19 21V9.5l-7-5-7 5V21a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2z" />
<path d="M9 22V12h6v10" />
diff --git a/privacy.html b/privacy.html
index b6bc13b..28caeda 100644
--- a/privacy.html
+++ b/privacy.html
@@ -6,6 +6,7 @@
<title>隐私政策 - LibreTV</title>
<script src="libs/tailwindcss.min.js"></script>
<link rel="stylesheet" href="css/styles.css">
+ <link rel="manifest" href="manifest.json">
</head>
<body class="page-bg text-white">
<div class="container mx-auto px-4 py-8">
@@ -21,7 +22,7 @@
</p>
</main>
<footer class="mt-12 text-center">
- <a href="index.html" class="text-gray-400 hover:text-white transition-colors">回到首页</a>
+ <a href="/" class="text-gray-400 hover:text-white transition-colors">回到首页</a>
</footer>
</div>
</body>
diff --git a/service-worker.js b/service-worker.js
new file mode 100644
index 0000000..f26b12f
--- /dev/null
+++ b/service-worker.js
@@ -0,0 +1,40 @@
+const CACHE_NAME = 'libre-tv-cache-v1';
+const urlsToCache = [
+ '/',
+ '/css/styles.css',
+ '/js/app.js',
+ '/js/config.js',
+ '/js/ui.js',
+ '/js/api.js',
+ '/js/password.js',
+ '/libs/tailwindcss.min.js',
+ '/libs/DPlayer.min.js',
+ '/libs/hls.min.js',
+ '/libs/sha256.min.js',
+ '/https://images.icon-icons.com/38/PNG/512/retrotv_5520.png',
+ '/manifest.json'
+];
+
+self.addEventListener('install', event => {
+ event.waitUntil(
+ caches.open(CACHE_NAME)
+ .then(cache => {
+ console.log('Opened cache');
+ return cache.addAll(urlsToCache);
+ })
+ );
+});
+
+self.addEventListener('fetch', event => {
+ event.respondWith(
+ caches.match(event.request)
+ .then(response => {
+ // Cache hit - return response
+ if (response) {
+ return response;
+ }
+ return fetch(event.request);
+ }
+ )
+ );
+});
diff --git a/watch.html b/watch.html
index a96c091..39e3984 100644
--- a/watch.html
+++ b/watch.html
@@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=player.html">
<title>重定向到播放器</title>
+ <link rel="manifest" href="manifest.json">
</head>
<body>
<p>如果您没有被自动重定向,请<a href="player.html">点击这里</a>前往播放页面。</p>