Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const VAULT_PASSWORD = 'demo123'; // In production, use proper authentication
+ const loginSection = document.getElementById('loginSection');
+ const uploadSection = document.getElementById('uploadSection');
+ const audioList = document.getElementById('audioList');
+ const loginBtn = document.getElementById('loginBtn');
+
+ let isLoggedIn = false;
+
+ // Login handling
+ document.getElementById('loginForm').addEventListener('submit', (e) => {
+ e.preventDefault();
+ const password = document.getElementById('password').value;
+
+ if (password === VAULT_PASSWORD) {
+ isLoggedIn = true;
+ loginSection.classList.add('hidden');
+ uploadSection.classList.remove('hidden');
+ audioList.classList.remove('hidden');
+ loginBtn.textContent = 'Logout';
+ loadAudioFiles();
+ } else {
+ alert('Invalid password');
+ }
+ });
+
+ // Login/Logout button
+ loginBtn.addEventListener('click', () => {
+ if (isLoggedIn) {
+ isLoggedIn = false;
+ loginSection.classList.remove('hidden');
+ uploadSection.classList.add('hidden');
+ audioList.classList.add('hidden');
+ loginBtn.textContent = 'Login';
+ document.getElementById('password').value = '';
+ }
+ });
+
+ // File upload handling
+ document.getElementById('uploadForm').addEventListener('submit', (e) => {
+ e.preventDefault();
+ const file = document.getElementById('audioFile').files[0];
+ if (file) {
+ uploadAudioFile(file);
+ }
+ });
+
+ // Drag and drop handling
+ const uploadArea = document.querySelector('.upload-area');
+
+ uploadArea.addEventListener('dragover', (e) => {
+ e.preventDefault();
+ uploadArea.style.borderColor = var(--primary);
+ });
+
+ uploadArea.addEventListener('dragleave', () => {
+ uploadArea.style.borderColor = '#e1e1e1';
+ });
+
+ uploadArea.addEventListener('drop', (e) => {
+ e.preventDefault();
+ uploadArea.style.borderColor = '#e1e1e1';
+ const file = e.dataTransfer.files[0];
+ if (file.type.startsWith('audio/')) {
+ uploadAudioFile(file);
+ } else {
+ alert('Please upload audio files only');
+ }
+ });
+
+ function uploadAudioFile(file) {
+ // In production, implement actual file upload to server
+ const audioFiles = JSON.parse(localStorage.getItem('audioFiles') || '[]');
+ audioFiles.push({
+ name: file.name,
+ date: new Date().toISOString(),
+ size: file.size
+ });
+ localStorage.setItem('audioFiles', JSON.stringify(audioFiles));
+ loadAudioFiles();
+ }
+
+ function loadAudioFiles() {
+ const container = document.querySelector('.list-container');
+ container.innerHTML = '';
+
+ const audioFiles = JSON.parse(localStorage.getItem('audioFiles') || '[]');
+ audioFiles.sort((a, b) => new Date(b.date) - new Date(a.date));
+
+ audioFiles.forEach(file => {
+ const item = document.createElement('div');
+ item.className = 'audio-item';
+ item.innerHTML = `
+ ${file.name}
+ ${new Date(file.date).toLocaleDateString()}
+ ${formatFileSize(file.size)}
+ `;
+ container.appendChild(item);
+ });
+ }
+
+ function formatFileSize(bytes) {
+ if (bytes === 0) return '0 Bytes';
+ const k = 1024;
+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
+ }
+ });