| |
| const elements = { |
| authSection: document.getElementById('auth-section'), |
| botSection: document.getElementById('bot-section'), |
| output: document.getElementById('output'), |
| status: document.getElementById('connection-status'), |
| loginBtn: document.getElementById('login-btn'), |
| registerBtn: document.getElementById('register-btn'), |
| deployBtn: document.getElementById('deploy-btn'), |
| commandInput: document.getElementById('command-input'), |
| sendCommand: document.getElementById('send-command'), |
| themeToggle: document.getElementById('theme-toggle'), |
| musicToggle: document.getElementById('music-toggle'), |
| videoElement: document.getElementById('funk-video') |
| }; |
|
|
| |
| let currentUser = null; |
| let isMusicPlaying = false; |
| let isDarkMode = true; |
|
|
| |
| const funkVideos = [ |
| "https://example.com/funk1.mp4", |
| "https://example.com/funk2.mp4", |
| "https://example.com/phunk1.mp4" |
| ]; |
|
|
| |
| const socket = io({ |
| reconnection: true, |
| reconnectionAttempts: Infinity, |
| reconnectionDelay: 1000, |
| timeout: 20000 |
| }); |
|
|
| |
| window.addEventListener('load', () => { |
| elements.botSection.style.display = 'block'; |
| elements.authSection.style.display = 'none'; |
| updateStatus('System loaded'); |
| playRandomVideo(); |
| }); |
|
|
| |
| function playRandomVideo() { |
| const randomVideo = funkVideos[Math.floor(Math.random() * funkVideos.length)]; |
| elements.videoElement.src = randomVideo; |
| elements.videoElement.play().catch(e => console.log("Video play error:", e)); |
| elements.videoElement.onended = playRandomVideo; |
| } |
|
|
| |
| function updateStatus(message, isError = false) { |
| elements.status.textContent = message; |
| elements.status.style.background = isError ? '#e74c3c' : '#2ecc71'; |
| appendToOutput(message, isError ? 'error' : 'info'); |
| } |
|
|
| |
| socket.on('connect', () => { |
| updateStatus('Connected to server'); |
| socket.emit('terminal-ready'); |
| }); |
|
|
| socket.on('disconnect', () => { |
| updateStatus('Disconnected', true); |
| }); |
|
|
| socket.on('connect_error', (err) => { |
| updateStatus(`Connection error: ${err.message}`, true); |
| }); |
|
|
| socket.on('terminal-output', (data) => { |
| appendToOutput(data, 'output'); |
| }); |
|
|
| socket.on('terminal-init', (data) => { |
| appendToOutput(`Terminal initialized at ${new Date().toLocaleTimeString()}`, 'success'); |
| }); |
|
|
| |
| function appendToOutput(text, type = 'output') { |
| const line = document.createElement('div'); |
| line.className = type; |
| line.textContent = text; |
| elements.output.appendChild(line); |
| elements.output.scrollTop = elements.output.scrollHeight; |
| } |
|
|
| |
| elements.sendCommand.addEventListener('click', sendCommand); |
| elements.commandInput.addEventListener('keypress', (e) => { |
| if (e.key === 'Enter') sendCommand(); |
| }); |
|
|
| function sendCommand() { |
| const command = elements.commandInput.value.trim(); |
| if (!command) return; |
| |
| appendToOutput(`$ ${command}`, 'command'); |
| socket.emit('terminal-command', { command, userId: currentUser }); |
| elements.commandInput.value = ''; |
| } |
|
|
| |
| setTimeout(() => { |
| if (elements.output.children.length === 0) { |
| appendToOutput('Running in offline mode. Some features may be limited.', 'warning'); |
| } |
| }, 5000); |
|
|
| |
| setInterval(() => { |
| elements.botSection.style.display = 'block'; |
| }, 3000); |