// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
// 设置当前年份
const yearElement = document.querySelector('.footer-bottom p');
if (yearElement) {
yearElement.innerHTML = yearElement.innerHTML.replace('{{ current_year }}', new Date().getFullYear());
}
// 初始化SHA-256容器,默认隐藏
const sha256Containers = document.querySelectorAll('.sha256-container');
sha256Containers.forEach(container => {
container.style.display = 'none';
});
// 绑定SHA-256按钮事件
const sha256Buttons = document.querySelectorAll('.sha256-btn');
sha256Buttons.forEach(button => {
button.addEventListener('click', function() {
const category = this.getAttribute('data-category');
const filename = this.getAttribute('data-filename');
const containerId = `sha256-${category}-${filename}`;
const container = document.getElementById(containerId);
// 切换显示/隐藏状态
if (container.style.display === 'none' || container.style.display === '') {
container.style.display = 'flex';
this.innerHTML = ' 隐藏';
this.classList.add('active');
} else {
container.style.display = 'none';
this.innerHTML = ' SHA-256';
this.classList.remove('active');
}
});
});
// 平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80, // 减去导航栏高度
behavior: 'smooth'
});
}
});
});
// 为文件卡片添加hover效果
const fileCards = document.querySelectorAll('.file-card');
fileCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px)';
this.style.boxShadow = '0 10px 20px rgba(0,0,0,0.1)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0)';
this.style.boxShadow = '';
});
});
// 为下载按钮添加点击效果
const downloadButtons = document.querySelectorAll('.download-btn');
downloadButtons.forEach(button => {
button.addEventListener('mousedown', function() {
this.style.transform = 'scale(0.95)';
});
button.addEventListener('mouseup', function() {
this.style.transform = 'scale(1)';
});
button.addEventListener('click', function() {
showNotification('开始下载文件...');
});
});
});
// 复制SHA-256到剪贴板
function copyToClipboard(id) {
const containerId = `sha256-${id}`;
const container = document.getElementById(containerId);
const codeElement = container.querySelector('code');
const textToCopy = codeElement.textContent;
navigator.clipboard.writeText(textToCopy).then(function() {
showNotification('SHA-256校验和已复制到剪贴板');
}).catch(function(err) {
console.error('复制失败:', err);
showNotification('复制失败,请手动复制', 'error');
});
}
// 显示通知
function showNotification(message, type = 'success') {
const notification = document.getElementById('notification');
const notificationMessage = document.getElementById('notification-message');
notificationMessage.textContent = message;
// 设置不同类型的样式
if (type === 'error') {
notification.style.backgroundColor = '#d73a49';
} else {
notification.style.backgroundColor = '#2ea44f';
}
// 显示通知
notification.classList.add('show');
// 3秒后隐藏通知
setTimeout(function() {
notification.classList.remove('show');
}, 3000);
}
// 监听滚动事件,动态调整导航栏样式
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.boxShadow = '0 4px 6px rgba(0,0,0,0.1)';
navbar.style.padding = '12px 0';
} else {
navbar.style.boxShadow = '';
navbar.style.padding = '16px 0';
}
});
// 图片懒加载效果
function lazyLoadImages() {
const images = document.querySelectorAll('img[data-src]');
const imgObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.removeAttribute('data-src');
observer.unobserve(img);
}
});
});
images.forEach(img => imgObserver.observe(img));
}
// 加载更多文件时的平滑动画
function animateFileIn(fileElement) {
fileElement.style.opacity = '0';
fileElement.style.transform = 'translateY(20px)';
setTimeout(() => {
fileElement.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
fileElement.style.opacity = '1';
fileElement.style.transform = 'translateY(0)';
}, 10);
}