From 121972898d188aaacc3d7d21ca4d0223d9dbab38 Mon Sep 17 00:00:00 2001 From: hehh Date: Sun, 23 Nov 2025 21:54:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(audio):=20=E5=AE=9E=E7=8E=B0=E9=9F=B3?= =?UTF-8?q?=E4=B9=90=E8=87=AA=E5=8A=A8=E6=92=AD=E6=94=BE=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加暂停时间记录与清除逻辑 - 实现24小时内暂停后不自动播放的判断 - 更新音频播放前的自动播放条件检查 - 优化本地存储中时间数据的读取与写入方式 --- js/about.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/about.js b/js/about.js index c1b446e..0ccb53d 100644 --- a/js/about.js +++ b/js/about.js @@ -639,8 +639,12 @@ class UIManager { if (this.audio) { if (this.audio.paused) { this.audio.play().catch(() => {}); + // 清除暂停时间记录,允许下次自动播放 + localStorage.removeItem('musicPauseTime'); } else { this.audio.pause(); + // 记录暂停时间 + localStorage.setItem('musicPauseTime', new Date().getTime().toString()); } } updateLabels(); @@ -653,7 +657,17 @@ class UIManager { if (!el) return; this.audio = el; this.audio.loop = true; - const tryPlay = () => { this.audio.play().catch(() => {}); }; + + // 检查是否在24小时内用户暂停过音乐 + const pauseTime = localStorage.getItem('musicPauseTime'); + const now = new Date().getTime(); + const shouldAutoPlay = !(pauseTime && (now - parseInt(pauseTime)) < 24 * 60 * 60 * 1000); + + const tryPlay = () => { + if (shouldAutoPlay) { + this.audio.play().catch(() => {}); + } + }; tryPlay(); }