document.addEventListener('DOMContentLoaded', function() { // Password section functionality const passwordInput = document.getElementById('passwordInput'); const unlockBtn = document.getElementById('unlockBtn'); const passwordSection = document.getElementById('passwordSection'); const fileSection = document.getElementById('fileSection'); // Upload functionality const uploadBtn = document.getElementById('uploadBtn'); const fileInput = document.getElementById('fileInput'); const fileList = document.getElementById('fileList'); // Sample files data (in a real app, this would come from an API) let files = []; // Check if we have a hash in URL (simulating hash-based access) const urlHash = window.location.hash.substring(1); if (urlHash) { console.log('Vault accessed via hash:', urlHash); // In a real app, you would validate this hash with your backend } // Unlock vault unlockBtn.addEventListener('click', function() { const password = passwordInput.value.trim(); if (!password) { alert('Please enter a password'); return; } // In a real app, you would verify the password with your backend // For demo purposes, we'll just check if any password was entered passwordSection.classList.add('hidden'); fileSection.classList.remove('hidden'); // Load files (in a real app, this would be an API call) loadFiles(); }); // Handle Enter key in password field passwordInput.addEventListener('keyup', function(e) { if (e.key === 'Enter') { unlockBtn.click(); } }); // Upload file uploadBtn.addEventListener('click', function() { fileInput.click(); }); fileInput.addEventListener('change', function(e) { if (e.target.files.length > 0) { const file = e.target.files[0]; uploadFile(file); } }); function uploadFile(file) { // In a real app, you would upload to your server here // For demo, we'll just add to the local list const newFile = { id: Date.now(), name: file.name, type: getFileType(file.name), size: formatFileSize(file.size), date: new Date().toLocaleDateString(), file: file // Actual file object }; files.unshift(newFile); renderFiles(); // Reset file input fileInput.value = ''; } function loadFiles() { // Simulate loading from API setTimeout(() => { // Sample files files = [ { id: 1, name: 'Project_Documentation.pdf', type: 'pdf', size: '2.4 MB', date: '2023-05-15' }, { id: 2, name: 'Budget_2023.xlsx', type: 'sheet', size: '1.1 MB', date: '2023-04-22' }, { id: 3, name: 'Team_Photo.jpg', type: 'image', size: '3.7 MB', date: '2023-03-10' }, { id: 4, name: 'Backup_Archive.zip', type: 'zip', size: '45.2 MB', date: '2023-02-05' } ]; renderFiles(); }, 800); } function renderFiles() { fileList.innerHTML = ''; if (files.length === 0) { fileList.innerHTML = `
No files in this vault yet