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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// DOM Elements
|
| 2 |
+
const videoElement = document.getElementById('funk-video');
|
| 3 |
+
const themeToggle = document.getElementById('theme-toggle');
|
| 4 |
+
const musicToggle = document.getElementById('music-toggle');
|
| 5 |
+
const authSection = document.getElementById('auth-section');
|
| 6 |
+
const botSection = document.getElementById('bot-section');
|
| 7 |
+
const loginForm = document.getElementById('login-form');
|
| 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 |
+
// Handle registration
|
| 164 |
+
function handleRegister() {
|
| 165 |
+
const username = document.getElementById('register-username').value;
|
| 166 |
+
const password = document.getElementById('register-password').value;
|
| 167 |
+
const confirm = document.getElementById('register-confirm').value;
|
| 168 |
+
|
| 169 |
+
if (!username || !password || !confirm) {
|
| 170 |
+
showMessage('register-message', 'Please fill all fields', 'error');
|
| 171 |
+
return;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
if (password !== confirm) {
|
| 175 |
+
showMessage('register-message', 'Passwords do not match', 'error');
|
| 176 |
+
return;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
if (password.length < 8) {
|
| 180 |
+
showMessage('register-message', 'Password must be at least 8 characters', 'error');
|
| 181 |
+
return;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
socket.emit('register', { username, password });
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
// Deploy bot
|
| 188 |
+
function deployBot() {
|
| 189 |
+
const repoUrl = document.getElementById('repo-url').value;
|
| 190 |
+
const entryFile = document.getElementById('entry-file').value;
|
| 191 |
+
|
| 192 |
+
if (!repoUrl || !entryFile) {
|
| 193 |
+
alert('Please fill all fields');
|
| 194 |
+
return;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
socket.emit('deploy-bot', {
|
| 198 |
+
userId: currentUser,
|
| 199 |
+
repoUrl,
|
| 200 |
+
entryFile
|
| 201 |
+
});
|
| 202 |
+
|
| 203 |
+
appendToOutput(`π Starting deployment: ${repoUrl}\n`, 'info');
|
| 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);
|