Changed around line 1
- document.getElementById('connect-form').addEventListener('submit', function(e) {
- e.preventDefault();
-
- const server = document.getElementById('server').value;
- const port = document.getElementById('port').value;
- const nickname = document.getElementById('nickname').value;
-
- // Simulate connection
- setTimeout(() => {
- document.getElementById('connection').classList.add('hidden');
- document.getElementById('chat').classList.remove('hidden');
- document.getElementById('chat-window').innerHTML = `
Connected to ${server}:${port} as ${nickname}
`;
- }, 1000);
- });
+ document.addEventListener('DOMContentLoaded', () => {
+ const connectButton = document.getElementById('connectButton');
+ const sendButton = document.getElementById('sendButton');
+ const messageInput = document.getElementById('messageInput');
+ const messages = document.getElementById('messages');
+ const connectionStatus = document.getElementById('connectionStatus');
+ const serverInput = document.getElementById('serverInput');
+ const nickInput = document.getElementById('nickInput');
+
+ let websocket = null;
+
+ connectButton.addEventListener('click', () => {
+ if (websocket && websocket.readyState === WebSocket.OPEN) {
+ websocket.close();
+ connectButton.textContent = 'Connect';
+ connectionStatus.textContent = 'Disconnected';
+ connectionStatus.classList.remove('connected');
+ return;
+ }
+
+ const server = serverInput.value;
+ const nickname = nickInput.value;
+
+ if (!server || !nickname) {
+ addMessage('System', 'Please enter server and nickname');
+ return;
+ }
- document.getElementById('message-form').addEventListener('submit', function(e) {
- e.preventDefault();
-
- const message = document.getElementById('message-input').value;
- const chatWindow = document.getElementById('chat-window');
-
- chatWindow.innerHTML += `
You: ${message}
`;
- chatWindow.scrollTop = chatWindow.scrollHeight;
-
- document.getElementById('message-input').value = '';
- });
+ // In a real implementation, we would connect to an IRC server here
+ // This is a mock implementation for demonstration
+ mockConnect(server, nickname);
+ });
+
+ sendButton.addEventListener('click', sendMessage);
+ messageInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter') sendMessage();
+ });
+
+ function sendMessage() {
+ if (!messageInput.value.trim()) return;
+
+ if (websocket && websocket.readyState === WebSocket.OPEN) {
+ addMessage(nickInput.value, messageInput.value);
+ messageInput.value = '';
+ } else {
+ addMessage('System', 'Not connected to server');
+ }
+ }
+
+ function addMessage(sender, text) {
+ const messageDiv = document.createElement('div');
+ messageDiv.innerHTML = `${sender}: ${text}`;
+ messages.appendChild(messageDiv);
+ messages.scrollTop = messages.scrollHeight;
+ }
+
+ function mockConnect(server, nickname) {
+ connectButton.textContent = 'Disconnect';
+ connectionStatus.textContent = 'Connected';
+ connectionStatus.classList.add('connected');
+ addMessage('System', `Connected to ${server} as ${nickname}`);
+
+ // Mock WebSocket connection
+ websocket = {
+ readyState: WebSocket.OPEN,
+ close: function() {
+ this.readyState = WebSocket.CLOSED;
+ addMessage('System', 'Disconnected from server');
+ }
+ };
+ }
+ });