一分钟搭建影视站,支持Docker等部署方式
feat: add version check (#367)
旋律已经死了。e868282080f0
diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.ymlindex a8ca09e..312b13d 100644--- a/.github/workflows/sync.yml+++ b/.github/workflows/sync.yml@@ -45,8 +45,8 @@ jobs:upstream_sync_branch: maintarget_sync_branch: maintarget_repo_token: ${{ secrets.GITHUB_TOKEN }}- commit_user_name: github-actions[bot]- commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com+ git_config_user: github-actions[bot]+ git_config_email: 41898282+github-actions[bot]@users.noreply.github.comtest_mode: false- name: Sync checkdiff --git a/.github/workflows/version.yml b/.github/workflows/version.ymlnew file mode 100644index 0000000..801974f--- /dev/null+++ b/.github/workflows/version.yml@@ -0,0 +1,34 @@+name: Bump version++on:+ push:+ branches:+ - main+ workflow_dispatch:++jobs:+ bump-version:+ runs-on: ubuntu-latest+ env:+ TZ: 'Asia/Shanghai'++ steps:+ - name: Checkout repository+ uses: actions/checkout@v4+ - name: Bump version and commit changes+ run: |+ CURRENT_TIME=$(date +"%Y-%m-%d %H:%M")+ git config user.name 'github-actions[bot]'+ git config user.email 'github-actions[bot]@users.noreply.github.com'+ echo $(date +"%Y%m%d%H%M") > VERSION.txt+ git add VERSION.txt+ git commit -m "Auto Update $CURRENT_TIME"+ git push origin main++ - name: Delete workflow runs+ uses: Mattraks/delete-workflow-runs@main+ with:+ token: ${{ secrets.GITHUB_TOKEN }}+ repository: ${{ github.repository }}+ retain_days: 0+ keep_minimum_runs: 2\ No newline at end of filediff --git a/VERSION.txt b/VERSION.txtnew file mode 100644index 0000000..adfaa78--- /dev/null+++ b/VERSION.txt@@ -0,0 +1 @@+202505121430\ No newline at end of filediff --git a/image/retrotv_5520.png b/image/retrotv_5520.pngnew file mode 100644index 0000000..db159acBinary files /dev/null and b/image/retrotv_5520.png differdiff --git a/index.html b/index.htmlindex f8f8359..51839f6 100644--- a/index.html+++ b/index.html@@ -24,8 +24,8 @@<meta property="twitter:image" content="https://images.icon-icons.com/38/PNG/512/retrotv_5520.png"><!-- 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="icon" href="./image/retrotv_5520.png">+ <link rel="apple-touch-icon" href="./image/retrotv_5520.png"><link rel="manifest" href="manifest.json"><!-- Canonical URL -->@@ -434,6 +434,9 @@window.__ENV__.PASSWORD = "{{PASSWORD}}";</script>+ <!-- 版本检测脚本 -->+ <script src="js/version-check.js"></script>+<!-- 弹窗显示脚本 --><script>// 在页面加载完成后检查用户是否首次访问diff --git a/js/config.js b/js/config.jsindex 2121d57..21bd941 100644--- a/js/config.js+++ b/js/config.js@@ -15,7 +15,7 @@ const SITE_CONFIG = {name: 'LibreTV',url: 'https://libretv.is-an.org',description: '免费在线视频搜索与观看平台',- logo: 'https://images.icon-icons.com/38/PNG/512/retrotv_5520.png',+ logo: './image/retrotv_5520.png',version: '1.0.3'};diff --git a/js/version-check.js b/js/version-check.jsnew file mode 100644index 0000000..a7684d9--- /dev/null+++ b/js/version-check.js@@ -0,0 +1,162 @@+// 添加动画样式+(function() {+ const style = document.createElement('style');+ style.textContent = `+ @keyframes pulse {+ 0%, 100% {+ opacity: 1;+ }+ 50% {+ opacity: 0.6;+ }+ }+ .animate-pulse {+ animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;+ }+ `;+ document.head.appendChild(style);+})();++// 版本检查函数+async function checkForUpdates() {+ try {+ const currentVersionResponse = await fetch('/VERSION.txt', {+ cache: 'no-store'+ });++ if (!currentVersionResponse.ok) {+ throw new Error('获取当前版本失败');+ }++ const currentVersion = await currentVersionResponse.text();++ // 获取最新版本+ const latestVersionResponse = await fetch('https://raw.githubusercontent.com/JohnsonRan/LibreTV/main/VERSION.txt');+ if (!latestVersionResponse.ok) {+ throw new Error('获取最新版本失败');+ }++ const latestVersion = await latestVersionResponse.text();++ console.log('当前版本:', currentVersion);+ console.log('最新版本:', latestVersion);++ // 清理版本字符串(移除可能的空格或换行符)+ const cleanCurrentVersion = currentVersion.trim();+ const cleanLatestVersion = latestVersion.trim();++ // 返回版本信息+ return {+ current: cleanCurrentVersion,+ latest: cleanLatestVersion,+ hasUpdate: parseInt(cleanLatestVersion) > parseInt(cleanCurrentVersion),+ currentFormatted: formatVersion(cleanCurrentVersion),+ latestFormatted: formatVersion(cleanLatestVersion)+ };+ } catch (error) {+ console.error('版本检测出错:', error);+ throw error;+ }+}++// 格式化版本号为可读形式 (yyyyMMddhhmm -> yyyy-MM-dd hh:mm)+function formatVersion(versionString) {+ // 检测版本字符串是否有效+ if (!versionString) {+ return '未知版本';+ }++ // 清理版本字符串(移除可能的空格或换行符)+ const cleanedString = versionString.trim();++ // 格式化标准12位版本号+ if (cleanedString.length === 12) {+ const year = cleanedString.substring(0, 4);+ const month = cleanedString.substring(4, 6);+ const day = cleanedString.substring(6, 8);+ const hour = cleanedString.substring(8, 10);+ const minute = cleanedString.substring(10, 12);++ return `${year}-${month}-${day} ${hour}:${minute}`;+ }++ return cleanedString;+}++// 创建错误版本信息元素+function createErrorVersionElement(errorMessage) {+ const errorElement = document.createElement('p');+ errorElement.className = 'text-gray-400 text-xs mt-1 text-center md:text-left';+ errorElement.innerHTML = `版本: <span class="text-amber-500">检测失败</span>`;+ errorElement.title = errorMessage || "无法连接到 Github";+ return errorElement;+}++// 添加版本信息到页脚+function addVersionInfoToFooter() {+ checkForUpdates().then(result => {+ if (!result) {+ // 如果版本检测失败,显示错误信息+ const versionElement = createErrorVersionElement();+ // 在页脚显示错误元素+ displayVersionElement(versionElement);+ return;+ }++ // 创建版本信息元素+ const versionElement = document.createElement('p');+ versionElement.className = 'text-gray-400 text-xs mt-1 text-center md:text-left';++ // 添加当前版本信息+ versionElement.innerHTML = `版本: ${result.currentFormatted}`;++ // 如果有更新,添加更新提示+ if (result.hasUpdate) {+ versionElement.innerHTML += ` <span class="inline-flex items-center bg-red-600 text-white text-xs px-2 py-0.5 rounded-md ml-1 cursor-pointer animate-pulse font-medium">+ <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />+ </svg>+ 发现新版+ </span>`;++ setTimeout(() => {+ const updateBtn = versionElement.querySelector('span');+ if (updateBtn) {+ updateBtn.addEventListener('click', () => {+ window.open('https://github.com/LibreSpark/LibreTV', '_blank');+ });+ }+ }, 100);+ } else {+ // 如果没有更新,显示当前版本为最新版本+ versionElement.innerHTML = `版本: ${result.currentFormatted} <span class="text-green-500">(最新版本)</span>`;+ }++ // 显示版本元素+ displayVersionElement(versionElement);+ }).catch(error => {+ console.error('版本检测出错:', error);+ // 创建错误版本信息元素并显示+ const errorElement = createErrorVersionElement(`错误信息: ${error.message}`);+ displayVersionElement(errorElement);+ });+}++// 在页脚显示版本元素的辅助函数+function displayVersionElement(element) {+ // 获取页脚元素+ const footerElement = document.querySelector('.footer p.text-gray-500.text-sm');+ if (footerElement) {+ // 在原版权信息后插入版本信息+ footerElement.insertAdjacentElement('afterend', element);+ } else {+ // 如果找不到页脚元素,尝试在页脚区域最后添加+ const footer = document.querySelector('.footer .container');+ if (footer) {+ footer.querySelector('div').appendChild(element);+ }+ }+}++// 页面加载完成后添加版本信息+document.addEventListener('DOMContentLoaded', addVersionInfoToFooter);\ No newline at end of filediff --git a/manifest.json b/manifest.jsonindex d677fea..62714e2 100644--- a/manifest.json+++ b/manifest.json@@ -10,7 +10,7 @@"apple-mobile-web-app-status-bar-style": "black","icons": [{- "src": "https://images.icon-icons.com/38/PNG/512/retrotv_5520.png",+ "src": "./image/retrotv_5520.png","sizes": "512x512","type": "image/png"}diff --git a/player.html b/player.htmlindex 00207f1..410e338 100644--- a/player.html+++ b/player.html@@ -6,12 +6,13 @@<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="icon" href="./image/retrotv_5520.png">+ <link rel="apple-touch-icon" href="./image/retrotv_5520.png"><link rel="manifest" href="manifest.json"><script src="libs/tailwindcss.min.js"></script><script src="js/wakelock.js"></script>+ <script src="js/version-check.js"></script><link rel="stylesheet" href="css/styles.css"><style>body, html {diff --git a/readme.md b/readme.mdindex 7cc87e0..411468f 100644--- a/readme.md+++ b/readme.md@@ -1,7 +1,7 @@# LibreTV - 免费在线视频搜索与观看平台<div align="center">- <img src="https://images.icon-icons.com/38/PNG/512/retrotv_5520.png" alt="LibreTV Logo" width="120">+ <img src="./image/retrotv_5520.png" alt="LibreTV Logo" width="120"><br><p><strong>自由观影,畅享精彩</strong></p></div>diff --git a/service-worker.js b/service-worker.jsindex f26b12f..440bbc2 100644--- a/service-worker.js+++ b/service-worker.js@@ -1,40 +1,8 @@-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.skipWaiting();});-self.addEventListener('fetch', event => {- event.respondWith(- caches.match(event.request)- .then(response => {- // Cache hit - return response- if (response) {- return response;- }- return fetch(event.request);- }- )- );+self.addEventListener('activate', event => {+ event.waitUntil(self.clients.claim());});