Update public/script.js
Browse files- public/script.js +61 -244
public/script.js
CHANGED
|
@@ -1,246 +1,63 @@
|
|
| 1 |
-
//
|
| 2 |
-
const
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
const registerForm = document.getElementById('register-form');
|
| 9 |
-
const loginBtn = document.getElementById('login-btn');
|
| 10 |
-
const registerBtn = document.getElementById('register-btn');
|
| 11 |
-
const deployBtn = document.getElementById('deploy-btn');
|
| 12 |
-
const commandInput = document.getElementById('command-input');
|
| 13 |
-
const sendCommand = document.getElementById('send-command');
|
| 14 |
-
const outputDiv = document.getElementById('output');
|
| 15 |
-
const tabs = document.querySelectorAll('.tab');
|
| 16 |
-
|
| 17 |
-
// State
|
| 18 |
-
let currentUser = null;
|
| 19 |
-
let socket = null;
|
| 20 |
-
let isMusicPlaying = false;
|
| 21 |
-
let isDarkMode = true;
|
| 22 |
-
|
| 23 |
-
// Funk/Phunk videos
|
| 24 |
-
const funkVideos = [
|
| 25 |
-
"https://cdn.glitch.global/6e2c1a9d-1e8a-4f4d-8a0b-5e5b5d5b5e5b/funk1.mp4",
|
| 26 |
-
"https://cdn.glitch.global/6e2c1a9d-1e8a-4f4d-8a0b-5e5b5d5b5e5b/funk2.mp4",
|
| 27 |
-
"https://cdn.glitch.global/6e2c1a9d-1e8a-4f4d-8a0b-5e5b5d5b5e5b/funk3.mp4",
|
| 28 |
-
"https://cdn.glitch.global/6e2c1a9d-1e8a-4f4d-8a0b-5e5b5d5b5e5b/phunk1.mp4",
|
| 29 |
-
"https://cdn.glitch.global/6e2c1a9d-1e8a-4f4d-8a0b-5e5b5d5b5e5b/phunk2.mp4"
|
| 30 |
-
];
|
| 31 |
-
|
| 32 |
-
// Initialize
|
| 33 |
-
function init() {
|
| 34 |
-
setupEventListeners();
|
| 35 |
-
setupSocket();
|
| 36 |
-
playRandomVideo();
|
| 37 |
-
updateUptime();
|
| 38 |
-
setInterval(updateUptime, 1000);
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
// Event Listeners
|
| 42 |
-
function setupEventListeners() {
|
| 43 |
-
// Theme toggle
|
| 44 |
-
themeToggle.addEventListener('click', toggleTheme);
|
| 45 |
-
|
| 46 |
-
// Music toggle
|
| 47 |
-
musicToggle.addEventListener('click', toggleMusic);
|
| 48 |
-
|
| 49 |
-
// Tab switching
|
| 50 |
-
tabs.forEach(tab => {
|
| 51 |
-
tab.addEventListener('click', () => {
|
| 52 |
-
tabs.forEach(t => t.classList.remove('active'));
|
| 53 |
-
tab.classList.add('active');
|
| 54 |
-
|
| 55 |
-
document.querySelectorAll('.form').forEach(form => {
|
| 56 |
-
form.classList.remove('active');
|
| 57 |
-
});
|
| 58 |
-
|
| 59 |
-
document.getElementById(`${tab.dataset.tab}-form`).classList.add('active');
|
| 60 |
-
});
|
| 61 |
-
});
|
| 62 |
-
|
| 63 |
-
// Login
|
| 64 |
-
loginBtn.addEventListener('click', handleLogin);
|
| 65 |
-
|
| 66 |
-
// Register
|
| 67 |
-
registerBtn.addEventListener('click', handleRegister);
|
| 68 |
-
|
| 69 |
-
// Deploy bot
|
| 70 |
-
deployBtn.addEventListener('click', deployBot);
|
| 71 |
-
|
| 72 |
-
// Send command
|
| 73 |
-
sendCommand.addEventListener('click', sendBotCommand);
|
| 74 |
-
commandInput.addEventListener('keypress', (e) => {
|
| 75 |
-
if (e.key === 'Enter') sendBotCommand();
|
| 76 |
-
});
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
// Socket.io setup
|
| 80 |
-
function setupSocket() {
|
| 81 |
-
socket = io();
|
| 82 |
-
|
| 83 |
-
// Handle connection events
|
| 84 |
-
socket.on('connect', () => {
|
| 85 |
-
console.log("Connected to server");
|
| 86 |
-
});
|
| 87 |
-
|
| 88 |
-
// Bot output
|
| 89 |
-
socket.on('bot-output', (data) => {
|
| 90 |
-
appendToOutput(data, 'output');
|
| 91 |
-
});
|
| 92 |
-
|
| 93 |
-
socket.on('bot-error', (data) => {
|
| 94 |
-
appendToOutput(data, 'error');
|
| 95 |
-
});
|
| 96 |
-
|
| 97 |
-
// Auth responses
|
| 98 |
-
socket.on('login-success', (data) => {
|
| 99 |
-
currentUser = data.userId;
|
| 100 |
-
authSection.classList.add('hidden');
|
| 101 |
-
botSection.classList.remove('hidden');
|
| 102 |
-
showMessage('login-message', `Welcome back!`, 'success');
|
| 103 |
-
|
| 104 |
-
// Start playing music if enabled
|
| 105 |
-
if (isMusicPlaying) {
|
| 106 |
-
videoElement.muted = false;
|
| 107 |
-
}
|
| 108 |
-
});
|
| 109 |
-
|
| 110 |
-
socket.on('login-error', (message) => {
|
| 111 |
-
showMessage('login-message', message, 'error');
|
| 112 |
-
});
|
| 113 |
-
|
| 114 |
-
socket.on('register-success', () => {
|
| 115 |
-
showMessage('register-message', 'Registration successful! Please login.', 'success');
|
| 116 |
-
tabs[0].click();
|
| 117 |
-
});
|
| 118 |
-
|
| 119 |
-
socket.on('register-error', (message) => {
|
| 120 |
-
showMessage('register-message', message, 'error');
|
| 121 |
-
});
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
// Play random funk/phunk video
|
| 125 |
-
function playRandomVideo() {
|
| 126 |
-
const randomVideo = funkVideos[Math.floor(Math.random() * funkVideos.length)];
|
| 127 |
-
videoElement.src = randomVideo;
|
| 128 |
-
videoElement.play();
|
| 129 |
-
|
| 130 |
-
// When video ends, play another random one
|
| 131 |
-
videoElement.onended = () => {
|
| 132 |
-
playRandomVideo();
|
| 133 |
-
};
|
| 134 |
-
}
|
| 135 |
-
|
| 136 |
-
// Toggle music
|
| 137 |
-
function toggleMusic() {
|
| 138 |
-
isMusicPlaying = !isMusicPlaying;
|
| 139 |
-
videoElement.muted = !isMusicPlaying;
|
| 140 |
-
musicToggle.textContent = isMusicPlaying ? "🔊 Music On" : "🔇 Music Off";
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
// Toggle theme
|
| 144 |
-
function toggleTheme() {
|
| 145 |
-
isDarkMode = !isDarkMode;
|
| 146 |
-
document.body.classList.toggle('light-theme', !isDarkMode);
|
| 147 |
-
themeToggle.textContent = isDarkMode ? "🌙 Dark Mode" : "☀️ Light Mode";
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
// Handle login
|
| 151 |
-
function handleLogin() {
|
| 152 |
-
const username = document.getElementById('login-username').value;
|
| 153 |
-
const password = document.getElementById('login-password').value;
|
| 154 |
-
|
| 155 |
-
if (!username || !password) {
|
| 156 |
-
showMessage('login-message', 'Please fill all fields', 'error');
|
| 157 |
-
return;
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
socket.emit('login', { username, password });
|
| 161 |
-
}
|
| 162 |
|
| 163 |
-
//
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
}
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
// Send command to bot
|
| 207 |
-
function sendBotCommand() {
|
| 208 |
-
const command = commandInput.value.trim();
|
| 209 |
-
if (!command) return;
|
| 210 |
-
|
| 211 |
-
appendToOutput(`$ ${command}\n`, 'command');
|
| 212 |
-
socket.emit('send-command', { userId: currentUser, command });
|
| 213 |
-
commandInput.value = '';
|
| 214 |
-
}
|
| 215 |
-
|
| 216 |
-
// Append to output terminal
|
| 217 |
-
function appendToOutput(text, type = 'output') {
|
| 218 |
-
const line = document.createElement('div');
|
| 219 |
-
line.textContent = text;
|
| 220 |
-
line.className = type;
|
| 221 |
-
outputDiv.appendChild(line);
|
| 222 |
-
outputDiv.scrollTop = outputDiv.scrollHeight;
|
| 223 |
-
}
|
| 224 |
-
|
| 225 |
-
// Show message
|
| 226 |
-
function showMessage(elementId, message, type) {
|
| 227 |
-
const element = document.getElementById(elementId);
|
| 228 |
-
element.textContent = message;
|
| 229 |
-
element.className = `message ${type}`;
|
| 230 |
-
}
|
| 231 |
-
|
| 232 |
-
// Update uptime counter
|
| 233 |
-
function updateUptime() {
|
| 234 |
-
const uptimeElement = document.getElementById('uptime');
|
| 235 |
-
if (!uptimeElement) return;
|
| 236 |
-
|
| 237 |
-
const now = new Date();
|
| 238 |
-
const hours = String(now.getHours()).padStart(2, '0');
|
| 239 |
-
const minutes = String(now.getMinutes()).padStart(2, '0');
|
| 240 |
-
const seconds = String(now.getSeconds()).padStart(2, '0');
|
| 241 |
-
|
| 242 |
-
uptimeElement.textContent = `${hours}:${minutes}:${seconds}`;
|
| 243 |
-
}
|
| 244 |
-
|
| 245 |
-
// Initialize when DOM is loaded
|
| 246 |
-
document.addEventListener('DOMContentLoaded', init);
|
|
|
|
| 1 |
+
// Initialize Socket.io with forced connection
|
| 2 |
+
const socket = io({
|
| 3 |
+
reconnection: true,
|
| 4 |
+
reconnectionAttempts: Infinity,
|
| 5 |
+
reconnectionDelay: 1000,
|
| 6 |
+
timeout: 20000
|
| 7 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
// DOM Elements
|
| 10 |
+
const elements = {
|
| 11 |
+
authSection: document.getElementById('auth-section'),
|
| 12 |
+
botSection: document.getElementById('bot-section'),
|
| 13 |
+
output: document.getElementById('output'),
|
| 14 |
+
status: document.getElementById('connection-status')
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
// Immediately show terminal for debugging
|
| 18 |
+
elements.botSection.style.display = 'block';
|
| 19 |
+
elements.authSection.style.display = 'none';
|
| 20 |
+
|
| 21 |
+
// Connection monitoring
|
| 22 |
+
function updateStatus(message, isError = false) {
|
| 23 |
+
elements.status.textContent = message;
|
| 24 |
+
elements.status.style.background = isError ? '#e74c3c' : '#2ecc71';
|
| 25 |
+
elements.output.innerHTML += `<div class="${isError ? 'error' : 'info'}">${message}</div>`;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// Socket event handlers
|
| 29 |
+
socket.on('connect', () => {
|
| 30 |
+
updateStatus('Connected to server');
|
| 31 |
+
socket.emit('force-terminal-visible');
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
socket.on('disconnect', () => {
|
| 35 |
+
updateStatus('Disconnected', true);
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
socket.on('connect_error', (err) => {
|
| 39 |
+
updateStatus(`Connection error: ${err.message}`, true);
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
socket.on('terminal-output', (data) => {
|
| 43 |
+
elements.output.innerHTML += `<div class="output">${data}</div>`;
|
| 44 |
+
elements.output.scrollTop = elements.output.scrollHeight;
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
socket.on('terminal-init', (data) => {
|
| 48 |
+
elements.output.innerHTML = `<div class="success">Terminal initialized at ${new Date().toLocaleTimeString()}</div>`;
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
// Fallback: If no connection after 5 seconds, show terminal anyway
|
| 52 |
+
setTimeout(() => {
|
| 53 |
+
if (elements.output.innerHTML === '') {
|
| 54 |
+
elements.output.innerHTML = `<div class="warning">Running in offline mode. Some features may be limited.</div>`;
|
| 55 |
}
|
| 56 |
+
}, 5000);
|
| 57 |
+
|
| 58 |
+
// Force terminal visibility on load
|
| 59 |
+
window.addEventListener('load', () => {
|
| 60 |
+
elements.botSection.style.display = 'block';
|
| 61 |
+
elements.authSection.style.display = 'none';
|
| 62 |
+
updateStatus('System loaded');
|
| 63 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|