更新 index.php
This commit is contained in:
323
index.php
323
index.php
@@ -3,7 +3,7 @@ require_once 'config.php';
|
||||
|
||||
// 页面标题和版本信息
|
||||
$pageTitle = "落日音乐 - 发现好音乐";
|
||||
$siteVersion = "1.8.3.6016";
|
||||
$siteVersion = "1.8.3.6016.001";
|
||||
$bqsy = "2024-2025 落日音乐. JGZ_YES. 版权所有";
|
||||
|
||||
// 定义网站版权信息
|
||||
@@ -622,21 +622,6 @@ $currentPageUrl = getCurrentPageURL();
|
||||
background-color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.recommendations-link {
|
||||
display: block;
|
||||
text-align: center;
|
||||
margin-top: 1rem;
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
padding: 0.5rem 0;
|
||||
font-family: var(--main-font); /* 应用自定义字体 */
|
||||
}
|
||||
|
||||
.recommendations-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
@@ -1094,6 +1079,42 @@ $currentPageUrl = getCurrentPageURL();
|
||||
.dark-mode .avatar-loading::after {
|
||||
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><path d="M16 12a4 4 0 1 1-8 0"></path></svg>');
|
||||
}
|
||||
.recommendations-link {
|
||||
/* 让链接成为一个块级元素,方便控制 */
|
||||
display: inline-block;
|
||||
|
||||
/* 为 transform 和 box-shadow 的变化添加过渡效果, duration 0.3s, timing-function ease */
|
||||
/* 这会让悬浮效果更丝滑,而不是瞬间变化 */
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
|
||||
/* 可选:移除图片下方可能出现的小间隙 */
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
/* 当鼠标悬浮在链接上时 */
|
||||
.recommendations-link:hover {
|
||||
transform: translateY(-5px) scale(1.05); /* 向上移动5px并放大1.05倍 */
|
||||
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
/* 确保图片本身是响应式的,这里沿用你 inline 的 style */
|
||||
.recommendations-link img {
|
||||
/* 你原有的宽度设置,这里保持一致 */
|
||||
width: 120px;
|
||||
height: auto;
|
||||
|
||||
/* 可选:为图片添加圆角,视觉效果更好 */
|
||||
/* border-radius: 8px; */
|
||||
}
|
||||
.music-item.centered-links {
|
||||
display: flex;
|
||||
flex-direction: column; /* 让子元素垂直排列 */
|
||||
align-items: center; /* 水平居中对齐 */
|
||||
justify-content: center; /* 垂直居中(如果容器有高度) */
|
||||
text-align: center; /* 确保内部文本也居中 */
|
||||
gap: 15px; /* 增加元素之间的间距,替代<br> */
|
||||
padding: 20px 0; /* 上下增加一些内边距 */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -1304,17 +1325,24 @@ $currentPageUrl = getCurrentPageURL();
|
||||
</div>
|
||||
|
||||
<!-- 快捷链接 -->
|
||||
<div class="music-item">
|
||||
<div class="music-item centered-links">
|
||||
<h2>其他链接</h2>
|
||||
|
||||
<a href="http://leonmmcoset.jjxmm.win:8010/developer_apps.php?id=9" class="recommendations-link" target="_blank" rel="noopener noreferrer">
|
||||
<img src="https://shanwogou.cn/icon/leonapp.png" alt="LeonAPP" style="width: 120px; height: auto;">
|
||||
</a>
|
||||
|
||||
<a href="https://space.bilibili.com/2143228115?spm_id_from=333.1387.0.0" class="recommendations-link" target="_blank" rel="noopener noreferrer">
|
||||
<img src="https://shanwogou.cn/icon/bilibili.png" alt="bilibili" style="width: 120px; height: auto;">
|
||||
</a>
|
||||
|
||||
<a href="https://afdian.com/a/sunmusic" class="recommendations-link" target="_blank" rel="noopener noreferrer">
|
||||
<img src="https://shanwogou.cn/icon/aifadian.png" alt="爱发电支持" style="width: 120px; height: auto;">
|
||||
</a>
|
||||
|
||||
<a href="http://leonmmcoset.jjxmm.win:2000/JGZ_YES/SunShineMusic" class="recommendations-link" target="_blank" rel="noopener noreferrer">
|
||||
<img src="https://shanwogou.cn/icon/leongit-jgz&leon.png" alt="LeonGit" style="width: 120px; height: auto;">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="music-item">
|
||||
@@ -1427,7 +1455,7 @@ $currentPageUrl = getCurrentPageURL();
|
||||
<!-- 分享功能 -->
|
||||
<div class="share-section">
|
||||
<div class="share-link-container">
|
||||
<input type="text" class="share-link" value="<?php echo htmlspecialchars($shareUrl); ?>" readonly>
|
||||
<input type="text" class="share-link" value="<?php echo htmlspecialchars($shareUrl); ?>" readonly data-audio="<?php echo $music['id']; ?>">
|
||||
<button class="copy-button" data-audio="<?php echo $music['id']; ?>" title="复制链接">
|
||||
<i class="fas fa-copy"></i>
|
||||
</button>
|
||||
@@ -1482,6 +1510,43 @@ $currentPageUrl = getCurrentPageURL();
|
||||
return minutes + ":" + (secs < 10 ? "0" + secs : secs);
|
||||
}
|
||||
|
||||
// 获取下一首要播放的音频ID
|
||||
function getNextAudioId(currentId) {
|
||||
// 获取当前激活的分类
|
||||
const activeCategory = q('.category-btn.active').getAttribute('data-category');
|
||||
|
||||
// 获取当前分类下所有可见的音乐项
|
||||
let visibleItems = Array.from(qa(`.music-item[data-category="${activeCategory}"]`)).filter(item => {
|
||||
return item.style.display !== 'none';
|
||||
});
|
||||
|
||||
// 如果当前分类没有歌曲(不太可能),则获取所有歌曲
|
||||
if (visibleItems.length === 0) {
|
||||
visibleItems = Array.from(qa('.music-item'));
|
||||
}
|
||||
|
||||
const totalItems = visibleItems.length;
|
||||
if (totalItems === 0) return null;
|
||||
|
||||
// 查找当前歌曲在列表中的索引
|
||||
let currentIndex = -1;
|
||||
for (let i = 0; i < totalItems; i++) {
|
||||
if (visibleItems[i].getAttribute('data-id') === currentId) {
|
||||
currentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没找到当前歌曲或只有一首歌,则返回第一首
|
||||
if (currentIndex === -1 || totalItems === 1) {
|
||||
return visibleItems[0].getAttribute('data-id');
|
||||
}
|
||||
|
||||
// 返回下一首的ID,如果是最后一首,则返回第一首
|
||||
const nextIndex = (currentIndex + 1) % totalItems;
|
||||
return visibleItems[nextIndex].getAttribute('data-id');
|
||||
}
|
||||
|
||||
// 切换播放/暂停状态
|
||||
function togglePlayback(audio, playBtn) {
|
||||
if (audio.paused) {
|
||||
@@ -1495,6 +1560,33 @@ $currentPageUrl = getCurrentPageURL();
|
||||
|
||||
audio.play();
|
||||
playBtn.textContent = '⏸';
|
||||
|
||||
// 为当前播放的音频注册结束事件,用于自动播放下一首
|
||||
audio.onended = function() {
|
||||
// 保存当前歌曲的进度为0
|
||||
savePlaybackPosition(audio.id, 0);
|
||||
playBtn.textContent = '▶';
|
||||
|
||||
// 获取下一首歌曲的ID
|
||||
const nextId = getNextAudioId(audio.id);
|
||||
if (nextId) {
|
||||
const nextAudio = q('#' + nextId);
|
||||
const nextPlayBtn = q('.play-pause[data-audio="' + nextId + '"]');
|
||||
if (nextAudio && nextPlayBtn) {
|
||||
// 滚动到下一首歌曲
|
||||
const nextMusicItem = nextAudio.closest('.music-item');
|
||||
if (nextMusicItem) {
|
||||
nextMusicItem.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
// 播放下一首歌曲
|
||||
setTimeout(function() {
|
||||
togglePlayback(nextAudio, nextPlayBtn);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} else {
|
||||
audio.pause();
|
||||
playBtn.textContent = '▶';
|
||||
@@ -1506,12 +1598,10 @@ $currentPageUrl = getCurrentPageURL();
|
||||
const sidebar = q('#sidebar');
|
||||
const toggleBtn = q('#sidebar-toggle');
|
||||
|
||||
// 点击切换按钮显示/隐藏侧边栏
|
||||
addEvt(toggleBtn, 'click', function() {
|
||||
sidebar.classList.toggle('show');
|
||||
});
|
||||
|
||||
// 点击侧边栏外的区域关闭侧边栏
|
||||
addEvt(d, 'click', function(e) {
|
||||
if (!sidebar.contains(e.target) &&
|
||||
e.target !== toggleBtn &&
|
||||
@@ -1521,11 +1611,9 @@ $currentPageUrl = getCurrentPageURL();
|
||||
}
|
||||
});
|
||||
|
||||
// 在小屏幕上,点击历史项后关闭侧边栏
|
||||
const historyItems = qa('.history-item');
|
||||
historyItems.forEach(function(item) {
|
||||
addEvt(item, 'click', function() {
|
||||
// 检测是否为移动设备
|
||||
if (document.documentElement.classList.contains('mobile')) {
|
||||
sidebar.classList.remove('show');
|
||||
}
|
||||
@@ -1539,7 +1627,6 @@ $currentPageUrl = getCurrentPageURL();
|
||||
const themeIcon = themeToggle.querySelector('i');
|
||||
const themeText = themeToggle.querySelector('span');
|
||||
|
||||
// 检查用户偏好或本地存储
|
||||
if (localStorage.getItem('theme') === 'dark' ||
|
||||
(!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||
d.body.classList.add('dark-mode');
|
||||
@@ -1548,10 +1635,8 @@ $currentPageUrl = getCurrentPageURL();
|
||||
themeText.textContent = '明亮模式';
|
||||
}
|
||||
|
||||
// 绑定切换事件
|
||||
addEvt(themeToggle, 'click', function() {
|
||||
d.body.classList.toggle('dark-mode');
|
||||
|
||||
if (d.body.classList.contains('dark-mode')) {
|
||||
themeIcon.classList.remove('fa-moon');
|
||||
themeIcon.classList.add('fa-sun');
|
||||
@@ -1573,18 +1658,15 @@ $currentPageUrl = getCurrentPageURL();
|
||||
const logoutBtn = q('#logout-btn');
|
||||
|
||||
if (userMenuBtn && userDropdown) {
|
||||
// 点击用户按钮显示/隐藏下拉菜单
|
||||
addEvt(userMenuBtn, 'click', function(e) {
|
||||
e.stopPropagation();
|
||||
userDropdown.classList.toggle('show');
|
||||
});
|
||||
|
||||
// 点击其他区域关闭下拉菜单
|
||||
addEvt(d, 'click', function() {
|
||||
userDropdown.classList.remove('show');
|
||||
});
|
||||
|
||||
// 登出功能
|
||||
if (logoutBtn) {
|
||||
addEvt(logoutBtn, 'click', function() {
|
||||
if (confirm('确定要退出登录吗?')) {
|
||||
@@ -1601,122 +1683,70 @@ $currentPageUrl = getCurrentPageURL();
|
||||
const clearHistoryBtn = q('#clear-history');
|
||||
const placeholder = historyList.querySelector('.history-placeholder');
|
||||
|
||||
// 从localStorage获取历史记录
|
||||
function getHistory() {
|
||||
return JSON.parse(localStorage.getItem('playHistory') || '[]');
|
||||
}
|
||||
function getHistory() { return JSON.parse(localStorage.getItem('playHistory') || '[]'); }
|
||||
function saveHistory(history) { localStorage.setItem('playHistory', JSON.stringify(history)); }
|
||||
|
||||
// 保存历史记录到localStorage
|
||||
function saveHistory(history) {
|
||||
localStorage.setItem('playHistory', JSON.stringify(history));
|
||||
}
|
||||
|
||||
// 更新历史记录UI
|
||||
function updateHistoryUI() {
|
||||
const history = getHistory();
|
||||
|
||||
// 清空现有内容(除了占位符)
|
||||
const items = historyList.querySelectorAll('.history-item');
|
||||
items.forEach(item => item.remove());
|
||||
|
||||
// 显示或隐藏占位符
|
||||
if (history.length === 0) {
|
||||
if (placeholder) placeholder.style.display = 'block';
|
||||
} else {
|
||||
if (placeholder) placeholder.style.display = 'none';
|
||||
|
||||
// 添加历史记录项
|
||||
history.forEach(item => {
|
||||
const historyItem = d.createElement('div');
|
||||
historyItem.className = 'history-item';
|
||||
historyItem.setAttribute('data-audio', item.id);
|
||||
|
||||
// 格式化时间
|
||||
const date = new Date(item.timestamp);
|
||||
const formattedTime = `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
|
||||
|
||||
historyItem.innerHTML = `
|
||||
<div class="history-info">
|
||||
<h4 class="history-title">${item.title}</h4>
|
||||
<p class="history-artist">${item.artist}</p>
|
||||
</div>
|
||||
<span class="history-time">${formattedTime}</span>
|
||||
`;
|
||||
|
||||
// 点击历史项播放音乐
|
||||
<span class="history-time">${formattedTime}</span>`;
|
||||
addEvt(historyItem, 'click', function() {
|
||||
const audioId = this.getAttribute('data-audio');
|
||||
const audio = q('#' + audioId);
|
||||
const playBtn = q('.play-pause[data-audio="' + audioId + '"]');
|
||||
|
||||
if (audio && playBtn) {
|
||||
// 滚动到音乐项
|
||||
const musicItem = audio.closest('.music-item');
|
||||
if (musicItem) {
|
||||
musicItem.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
// 播放音乐
|
||||
if (audio.paused) {
|
||||
togglePlayback(audio, playBtn);
|
||||
}
|
||||
if (musicItem) { musicItem.scrollIntoView({ behavior: 'smooth', block: 'start' }); }
|
||||
if (audio.paused) { togglePlayback(audio, playBtn); }
|
||||
}
|
||||
});
|
||||
|
||||
historyList.appendChild(historyItem);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 添加到历史记录
|
||||
window.addToHistory = function(songId, songTitle, artist) {
|
||||
let history = getHistory();
|
||||
|
||||
// 移除已存在的相同歌曲(避免重复)
|
||||
history = history.filter(item => item.id !== songId);
|
||||
|
||||
// 添加新记录到最前面
|
||||
history.unshift({
|
||||
id: songId,
|
||||
title: songTitle,
|
||||
artist: artist,
|
||||
timestamp: new Date().getTime()
|
||||
});
|
||||
|
||||
// 限制历史记录数量
|
||||
if (history.length > 20) {
|
||||
history = history.slice(0, 20);
|
||||
}
|
||||
|
||||
history.unshift({ id: songId, title: songTitle, artist: artist, timestamp: new Date().getTime() });
|
||||
if (history.length > 20) { history = history.slice(0, 20); }
|
||||
saveHistory(history);
|
||||
updateHistoryUI();
|
||||
};
|
||||
|
||||
// 清空历史记录
|
||||
addEvt(clearHistoryBtn, 'click', function() {
|
||||
if (confirm('确定要清空所有播放历史吗?')) {
|
||||
localStorage.removeItem('playHistory');
|
||||
updateHistoryUI();
|
||||
}
|
||||
});
|
||||
|
||||
// 初始加载历史记录
|
||||
updateHistoryUI();
|
||||
}
|
||||
|
||||
// 播放进度记忆功能
|
||||
function initPlaybackPositionMemory() {
|
||||
// 保存播放进度
|
||||
window.savePlaybackPosition = function(songId, position) {
|
||||
const positions = JSON.parse(localStorage.getItem('playbackPositions') || '{}');
|
||||
positions[songId] = {
|
||||
position: position,
|
||||
timestamp: new Date().getTime()
|
||||
};
|
||||
positions[songId] = { position: position, timestamp: new Date().getTime() };
|
||||
localStorage.setItem('playbackPositions', JSON.stringify(positions));
|
||||
};
|
||||
|
||||
// 恢复播放进度
|
||||
window.restorePlaybackPosition = function(songId) {
|
||||
const positions = JSON.parse(localStorage.getItem('playbackPositions') || '{}');
|
||||
return positions[songId] ? positions[songId].position : 0;
|
||||
@@ -1727,23 +1757,12 @@ $currentPageUrl = getCurrentPageURL();
|
||||
function initTitleEffects() {
|
||||
const originalTitle = document.title;
|
||||
let titleChangeTimer = null;
|
||||
|
||||
// 监听页面可见性变化
|
||||
addEvt(document, 'visibilitychange', function() {
|
||||
// 清除之前的定时器
|
||||
if (titleChangeTimer) {
|
||||
clearTimeout(titleChangeTimer);
|
||||
titleChangeTimer = null;
|
||||
}
|
||||
|
||||
if (titleChangeTimer) { clearTimeout(titleChangeTimer); titleChangeTimer = null; }
|
||||
if (document.hidden) {
|
||||
// 页面不可见时显示挽留信息
|
||||
document.title = '你不要走啊 ! ..(。•ˇ‸ˇ•。)…';
|
||||
} else {
|
||||
// 页面可见时先显示欢迎回来信息
|
||||
document.title = '耶,又回来了!(^_^)';
|
||||
|
||||
// 3秒后恢复原始标题
|
||||
titleChangeTimer = setTimeout(function() {
|
||||
document.title = originalTitle;
|
||||
titleChangeTimer = null;
|
||||
@@ -1767,7 +1786,6 @@ $currentPageUrl = getCurrentPageURL();
|
||||
const volumeBtn = q('.volume-button[data-audio="' + id + '"]');
|
||||
const volumeSlider = q('.volume-slider[data-audio="' + id + '"]');
|
||||
|
||||
// 获取歌曲信息
|
||||
const musicItem = audio.closest('.music-item');
|
||||
const songTitle = musicItem.querySelector('h2').textContent;
|
||||
const artist = musicItem.querySelector('.artist-info').textContent.replace('作者:', '');
|
||||
@@ -1775,17 +1793,12 @@ $currentPageUrl = getCurrentPageURL();
|
||||
let originalVolume = 1;
|
||||
let isDragging = false;
|
||||
|
||||
// 音频加载完成 - 恢复上次播放进度
|
||||
addEvt(audio, 'loadedmetadata', function() {
|
||||
totalTime.textContent = formatTime(audio.duration);
|
||||
audio.volume = volumeSlider.value;
|
||||
|
||||
// 恢复播放进度
|
||||
const savedPosition = restorePlaybackPosition(id);
|
||||
if (savedPosition > 0 && savedPosition < audio.duration) {
|
||||
audio.currentTime = savedPosition;
|
||||
|
||||
// 更新UI
|
||||
const progress = (savedPosition / audio.duration) * 100;
|
||||
progressFill.style.width = progress + '%';
|
||||
progressHandle.style.left = progress + '%';
|
||||
@@ -1793,123 +1806,67 @@ $currentPageUrl = getCurrentPageURL();
|
||||
}
|
||||
});
|
||||
|
||||
// 播放/暂停
|
||||
addEvt(playBtn, 'click', function() {
|
||||
togglePlayback(audio, playBtn);
|
||||
// 添加到播放历史
|
||||
addToHistory(id, songTitle, artist);
|
||||
});
|
||||
|
||||
// 循环播放
|
||||
addEvt(loopBtn, 'click', function() {
|
||||
audio.loop = !audio.loop;
|
||||
loopBtn.classList.toggle('active', audio.loop);
|
||||
if (audio.loop) {
|
||||
loopBtn.style.transform = 'scale(1.1)';
|
||||
setTimeout(function() {
|
||||
loopBtn.style.transform = 'scale(1)';
|
||||
}, 200);
|
||||
setTimeout(() => loopBtn.style.transform = 'scale(1)', 200);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新进度 - 并保存播放进度
|
||||
addEvt(audio, 'timeupdate', function() {
|
||||
if (!isDragging) {
|
||||
const progress = (audio.currentTime / audio.duration) * 100;
|
||||
progressFill.style.width = progress + '%';
|
||||
progressHandle.style.left = progress + '%';
|
||||
currentTime.textContent = formatTime(audio.currentTime);
|
||||
|
||||
// 定期保存播放进度(每30秒或进度有显著变化时)
|
||||
if (audio.currentTime > 0 &&
|
||||
(audio.currentTime % 30 < 0.1 ||
|
||||
Math.abs(audio.currentTime - (audio.duration * 0.9)) < 0.5)) {
|
||||
if (audio.currentTime > 0 && (audio.currentTime % 30 < 0.1 || Math.abs(audio.currentTime - (audio.duration * 0.9)) < 0.5)) {
|
||||
savePlaybackPosition(id, audio.currentTime);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 播放结束时保存最终进度
|
||||
addEvt(audio, 'ended', function() {
|
||||
savePlaybackPosition(id, 0); // 播放结束后重置进度
|
||||
playBtn.textContent = '▶';
|
||||
});
|
||||
|
||||
// 进度条拖动
|
||||
const startDrag = function(e) {
|
||||
isDragging = true;
|
||||
progressHandle.classList.add('dragging');
|
||||
updateProgress(e);
|
||||
};
|
||||
|
||||
const updateProgress = function(e) {
|
||||
// 进度条拖动逻辑
|
||||
const startDrag = (e) => { isDragging = true; progressHandle.classList.add('dragging'); updateProgress(e); };
|
||||
const updateProgress = (e) => {
|
||||
if (!audio.duration) return;
|
||||
|
||||
// 获取进度条的位置和宽度
|
||||
const rect = progressBar.getBoundingClientRect();
|
||||
let pos = (e.clientX - rect.left) / rect.width;
|
||||
pos = Math.max(0, Math.min(1, pos)); // 限制在0-1之间
|
||||
|
||||
// 更新UI
|
||||
pos = Math.max(0, Math.min(1, pos));
|
||||
const percentage = pos * 100;
|
||||
progressFill.style.width = percentage + '%';
|
||||
progressHandle.style.left = percentage + '%';
|
||||
currentTime.textContent = formatTime(pos * audio.duration);
|
||||
};
|
||||
|
||||
const endDrag = function() {
|
||||
const endDrag = () => {
|
||||
if (!isDragging) return;
|
||||
|
||||
isDragging = false;
|
||||
progressHandle.classList.remove('dragging');
|
||||
|
||||
// 设置音频位置
|
||||
const pos = parseFloat(progressFill.style.width) / 100;
|
||||
audio.currentTime = pos * audio.duration;
|
||||
savePlaybackPosition(id, audio.currentTime);
|
||||
};
|
||||
|
||||
// 进度条事件
|
||||
addEvt(progressBar, 'click', updateProgress);
|
||||
addEvt(progressHandle, 'mousedown', startDrag);
|
||||
addEvt(d, 'mousemove', function(e) { if (isDragging) updateProgress(e); });
|
||||
addEvt(d, 'mousemove', (e) => { if (isDragging) updateProgress(e); });
|
||||
addEvt(d, 'mouseup', endDrag);
|
||||
addEvt(d, 'mouseleave', endDrag);
|
||||
|
||||
// 移动端触摸事件
|
||||
addEvt(progressBar, 'touchstart', function(e) {
|
||||
e.preventDefault();
|
||||
startDrag(e.touches[0]);
|
||||
});
|
||||
|
||||
addEvt(d, 'touchmove', function(e) {
|
||||
if (isDragging) {
|
||||
e.preventDefault();
|
||||
updateProgress(e.touches[0]);
|
||||
}
|
||||
});
|
||||
|
||||
addEvt(progressBar, 'touchstart', (e) => { e.preventDefault(); startDrag(e.touches[0]); });
|
||||
addEvt(d, 'touchmove', (e) => { if (isDragging) { e.preventDefault(); updateProgress(e.touches[0]); } });
|
||||
addEvt(d, 'touchend', endDrag);
|
||||
|
||||
// 音量控制
|
||||
addEvt(volumeBtn, 'click', function() {
|
||||
if (audio.volume > 0) {
|
||||
originalVolume = audio.volume;
|
||||
audio.volume = 0;
|
||||
volumeBtn.textContent = '🔇';
|
||||
volumeSlider.value = 0;
|
||||
} else {
|
||||
audio.volume = originalVolume;
|
||||
volumeBtn.textContent = '🔊';
|
||||
volumeSlider.value = originalVolume;
|
||||
}
|
||||
});
|
||||
|
||||
addEvt(volumeSlider, 'input', function() {
|
||||
audio.volume = this.value;
|
||||
originalVolume = this.value;
|
||||
volumeBtn.textContent = this.value > 0 ? '🔊' : '🔇';
|
||||
if (audio.volume > 0) { originalVolume = audio.volume; audio.volume = 0; volumeBtn.textContent = '🔇'; volumeSlider.value = 0; }
|
||||
else { audio.volume = originalVolume; volumeBtn.textContent = '🔊'; volumeSlider.value = originalVolume; }
|
||||
});
|
||||
addEvt(volumeSlider, 'input', function() { audio.volume = this.value; originalVolume = this.value; volumeBtn.textContent = this.value > 0 ? '🔊' : '🔇'; });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2015,8 +1972,7 @@ $currentPageUrl = getCurrentPageURL();
|
||||
copyButtons.forEach(function(btn) {
|
||||
addEvt(btn, 'click', function() {
|
||||
const audioId = this.getAttribute('data-audio');
|
||||
const shareLink = q('.share-link[data-audio="' + audioId + '"]') ||
|
||||
this.parentElement.querySelector('.share-link');
|
||||
const shareLink = q('.share-link[data-audio="' + audioId + '"]');
|
||||
|
||||
if (shareLink) {
|
||||
shareLink.select();
|
||||
@@ -2078,7 +2034,7 @@ $currentPageUrl = getCurrentPageURL();
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化头像加载(核心修复部分)
|
||||
// 初始化头像加载
|
||||
function initAvatarLoading() {
|
||||
// 获取头像URL列表(从PHP传递过来)
|
||||
<?php
|
||||
@@ -2091,12 +2047,10 @@ $currentPageUrl = getCurrentPageURL();
|
||||
|
||||
// 获取头像元素
|
||||
const userAvatarImg = q('#user-avatar-img');
|
||||
const dropdownAvatarImg = q('#dropdown-avatar-img');
|
||||
const userAvatarContainer = q('#user-avatar-container');
|
||||
const dropdownAvatarContainer = q('#dropdown-avatar-container');
|
||||
|
||||
// 如果没有头像元素,直接返回
|
||||
if (!userAvatarImg || !dropdownAvatarImg) {
|
||||
if (!userAvatarImg || !userAvatarContainer) {
|
||||
console.log("未找到头像元素,跳过头像加载");
|
||||
return;
|
||||
}
|
||||
@@ -2107,11 +2061,8 @@ $currentPageUrl = getCurrentPageURL();
|
||||
if (index >= urls.length) {
|
||||
console.error("所有头像URL都加载失败,使用默认头像");
|
||||
userAvatarImg.src = urls[urls.length - 1];
|
||||
dropdownAvatarImg.src = urls[urls.length - 1];
|
||||
userAvatarImg.style.display = 'block';
|
||||
dropdownAvatarImg.style.display = 'block';
|
||||
userAvatarContainer.classList.remove('avatar-loading');
|
||||
dropdownAvatarContainer.classList.remove('avatar-loading');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2126,11 +2077,8 @@ $currentPageUrl = getCurrentPageURL();
|
||||
testImg.onload = function() {
|
||||
console.log(`头像加载成功:`, currentUrl);
|
||||
userAvatarImg.src = currentUrl;
|
||||
dropdownAvatarImg.src = currentUrl;
|
||||
userAvatarImg.style.display = 'block';
|
||||
dropdownAvatarImg.style.display = 'block';
|
||||
userAvatarContainer.classList.remove('avatar-loading');
|
||||
dropdownAvatarContainer.classList.remove('avatar-loading');
|
||||
};
|
||||
|
||||
// 加载失败,尝试下一个URL
|
||||
@@ -2180,4 +2128,3 @@ $currentPageUrl = getCurrentPageURL();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user