Changed around line 1
+ const users = {
+ "黄春霖-Xiaoiec": "xiaoiec123456",
+ "梁冠宇": "lianggy",
+ "苏俊鸿": "sujh"
+ };
+
+ const loginContainer = document.getElementById('login-container');
+ const chatContainer = document.getElementById('chat-container');
+ const usernameSelect = document.getElementById('username-select');
+ const passwordInput = document.getElementById('password-input');
+ const loginBtn = document.getElementById('login-btn');
+ const messageInput = document.getElementById('message-input');
+ const sendBtn = document.getElementById('send-btn');
+ const fileUploadBtn = document.getElementById('file-upload-btn');
+ const chatHistory = document.getElementById('chat-history');
+
+ let currentUser = null;
+
+ loginBtn.addEventListener('click', () => {
+ const username = usernameSelect.value;
+ const password = passwordInput.value;
+
+ if (users[username] === password) {
+ currentUser = username;
+ loginContainer.style.opacity = '0';
+ loginContainer.style.transform = 'scale(0.9)';
+ setTimeout(() => {
+ loginContainer.classList.add('hidden');
+ chatContainer.classList.remove('hidden');
+ chatContainer.style.opacity = '1';
+ chatContainer.style.transform = 'scale(1)';
+ }, 300);
+ } else {
+ alert('Invalid username or password');
+ }
+ });
+
+ messageInput.addEventListener('focus', () => {
+ document.getElementById('input-wrapper').classList.add('active');
+ });
+
+ messageInput.addEventListener('blur', () => {
+ if (messageInput.value === '') {
+ document.getElementById('input-wrapper').classList.remove('active');
+ }
+ });
+
+ sendBtn.addEventListener('click', () => {
+ const message = messageInput.value.trim();
+ if (message !== '') {
+ sendMessage(message);
+ messageInput.value = '';
+ }
+ });
+
+ function sendMessage(message) {
+ const messageElement = document.createElement('div');
+ messageElement.classList.add('message');
+
+ const usernameElement = document.createElement('div');
+ usernameElement.classList.add('username');
+ usernameElement.textContent = currentUser;
+
+ const contentElement = document.createElement('div');
+ contentElement.classList.add('content');
+ contentElement.textContent = message;
+
+ const timestampElement = document.createElement('div');
+ timestampElement.classList.add('timestamp');
+ timestampElement.textContent = new Date().toLocaleString();
+
+ messageElement.appendChild(usernameElement);
+ messageElement.appendChild(contentElement);
+ messageElement.appendChild(timestampElement);
+
+ chatHistory.appendChild(messageElement);
+ chatHistory.scrollTop = chatHistory.scrollHeight;
+ }
+
+ fileUploadBtn.addEventListener('click', () => {
+ const fileInput = document.createElement('input');
+ fileInput.type = 'file';
+ fileInput.accept = '*';
+ fileInput.style.display = 'none';
+
+ fileInput.addEventListener('change', (e) => {
+ const file = e.target.files[0];
+ if (file) {
+ uploadFile(file);
+ }
+ });
+
+ document.body.appendChild(fileInput);
+ fileInput.click();
+ document.body.removeChild(fileInput);
+ });
+
+ function uploadFile(file) {
+ // Implement file upload logic here
+ console.log('Uploading file:', file.name);
+ // Show upload progress
+ // Send file to server
+ // Update chat history with file message
+ }