Skip to content

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

feat(password): 优化密码验证流程并提升页面加载体验

wudi65398f97b9bd
diff --git a/js/password.js b/js/password.js
index 3b693d8..345fb87 100644
--- a/js/password.js
+++ b/js/password.js
@@ -136,6 +136,9 @@ async function handlePasswordSubmit() {
if (await verifyPassword(password)) {
hidePasswordError();
hidePasswordModal();
+
+ // 触发密码验证成功事件
+ document.dispatchEvent(new CustomEvent('passwordVerified'));
} else {
showPasswordError();
if (passwordInput) {
@@ -176,4 +179,4 @@ function initPasswordProtection() {
}
// 在页面加载完成后初始化密码保护
-document.addEventListener('DOMContentLoaded', initPasswordProtection);
\ No newline at end of file
+document.addEventListener('DOMContentLoaded', initPasswordProtection);
diff --git a/player.html b/player.html
index 26d7aaa..32a4299 100644
--- a/player.html
+++ b/player.html
@@ -5,7 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LibreTV 播放器</title>
<script src="https://cdn.tailwindcss.com"></script>
- <script src="js/password.js"></script>
<link rel="stylesheet" href="css/styles.css">
<style>
body, html {
@@ -270,10 +269,28 @@
<span id="shortcutText"></span>
</div>
+ <!-- 引入纯 JS sha256(HTTP 下依然可用) -->
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/sha256.min.js"></script>
+ <script>
+ // 保存原始 js‑sha256 实现,避免被 password.js 覆盖
+ window._jsSha256 = window.sha256;
+ </script>
<script src="https://s4.zstatic.net/ajax/libs/hls.js/1.5.6/hls.min.js" integrity="sha256-X1GmLMzVcTBRiGjEau+gxGpjRK96atNczcLBg5w6hKA=" crossorigin="anonymous"></script>
<script src="https://s4.zstatic.net/ajax/libs/dplayer/1.26.0/DPlayer.min.js" integrity="sha256-OJg03lDZP0NAcl3waC9OT5jEa8XZ8SM2n081Ik953o4=" crossorigin="anonymous"></script>
<script src="js/config.js"></script>
+ <script src="js/password.js"></script>
+
<script>
+ // 创建全局环境变量对象
+ window.__ENV__ = window.__ENV__ || {};
+
+ // 注入服务器端环境变量 (将由服务器端替换)
+ // PASSWORD 变量将在这里被服务器端注入
+ window.__ENV__.PASSWORD = "{{PASSWORD}}";
+
+ // =================================
+ // ============== PLAYER ==========
+ // =================================
// 全局变量
let currentVideoTitle = '';
let currentEpisodeIndex = 0;
@@ -291,6 +308,25 @@
// 页面加载
document.addEventListener('DOMContentLoaded', function() {
+ // 先检查用户是否已通过密码验证
+ if (!isPasswordVerified()) {
+ // 隐藏加载提示
+ document.getElementById('loading').style.display = 'none';
+ return;
+ }
+
+ initializePageContent();
+ });
+
+ // 监听密码验证成功事件
+ document.addEventListener('passwordVerified', () => {
+ document.getElementById('loading').style.display = 'block';
+
+ initializePageContent();
+ });
+
+ // 初始化页面内容
+ function initializePageContent() {
// 解析URL参数
const urlParams = new URLSearchParams(window.location.search);
const videoUrl = urlParams.get('url');
@@ -358,7 +394,7 @@
// 设置页面标题
document.title = currentVideoTitle + ' - LibreTV播放器';
document.getElementById('videoTitle').textContent = currentVideoTitle;
-
+
// 初始化播放器
if (videoUrl) {
initPlayer(videoUrl);
@@ -429,7 +465,7 @@
clearInterval(waitForVideo);
}
}, 200);
- });
+ }
// 处理键盘快捷键
function handleKeyboardShortcuts(e) {