Delete app.js
Browse files
app.js
DELETED
|
@@ -1,1519 +0,0 @@
|
|
| 1 |
-
// ═══════════════════════════════════════════════════════════════
|
| 2 |
-
// NOAHSCHAT — app.js
|
| 3 |
-
// ═══════════════════════════════════════════════════════════════
|
| 4 |
-
|
| 5 |
-
// ─── CONFIG ───────────────────────────────────────────────────
|
| 6 |
-
const OWNER_NAME = 'Noah';
|
| 7 |
-
const OWNER_PASS = 'Noah100419!';
|
| 8 |
-
const PING_URL = 'https://noah33565-noahsapp.static.hf.space/';
|
| 9 |
-
const PING_INTERVAL = 24 * 60 * 60 * 1000; // 24h
|
| 10 |
-
|
| 11 |
-
// ─── STATE ────────────────────────────────────────────────────
|
| 12 |
-
let currentUser = null;
|
| 13 |
-
let currentChannel= 'allgemein';
|
| 14 |
-
let currentDM = null;
|
| 15 |
-
let pollTimer = null;
|
| 16 |
-
let pingTimer = null;
|
| 17 |
-
let lastMsgCount = {};
|
| 18 |
-
let unreadCounts = {};
|
| 19 |
-
let spamTs = [];
|
| 20 |
-
let captchaData = {};
|
| 21 |
-
let pendingSpamMsg= null;
|
| 22 |
-
let appConfig = {};
|
| 23 |
-
let voiceActive = false;
|
| 24 |
-
let voiceChannel = null;
|
| 25 |
-
let micMuted = false;
|
| 26 |
-
let deafened = false;
|
| 27 |
-
let voiceParticipants = {};
|
| 28 |
-
let ticketCounter = 1;
|
| 29 |
-
let translationEnabled = false;
|
| 30 |
-
let userLanguage = 'de';
|
| 31 |
-
|
| 32 |
-
// ─── STORAGE ──────────────────────────────────────────────────
|
| 33 |
-
const DB = {
|
| 34 |
-
async get(key) {
|
| 35 |
-
try {
|
| 36 |
-
if (window.storage) {
|
| 37 |
-
const r = await window.storage.get(key, true);
|
| 38 |
-
return r ? JSON.parse(r.value) : null;
|
| 39 |
-
}
|
| 40 |
-
const v = localStorage.getItem('nc2_' + key);
|
| 41 |
-
return v ? JSON.parse(v) : null;
|
| 42 |
-
} catch { return null; }
|
| 43 |
-
},
|
| 44 |
-
async set(key, val) {
|
| 45 |
-
try {
|
| 46 |
-
const s = JSON.stringify(val);
|
| 47 |
-
if (window.storage) {
|
| 48 |
-
await window.storage.set(key, s, true);
|
| 49 |
-
} else {
|
| 50 |
-
localStorage.setItem('nc2_' + key, s);
|
| 51 |
-
}
|
| 52 |
-
} catch(e) { console.error('DB.set error:', e); }
|
| 53 |
-
}
|
| 54 |
-
};
|
| 55 |
-
|
| 56 |
-
// ─── FINGERPRINT ──────────────────────────────────────────────
|
| 57 |
-
function getFingerprint() {
|
| 58 |
-
const str = navigator.userAgent + screen.width + 'x' + screen.height + screen.colorDepth
|
| 59 |
-
+ (Intl.DateTimeFormat().resolvedOptions().timeZone || '') + navigator.language;
|
| 60 |
-
let h = 0;
|
| 61 |
-
for (let i = 0; i < str.length; i++) { h = ((h << 5) - h) + str.charCodeAt(i); h = h & h; }
|
| 62 |
-
return Math.abs(h).toString(36);
|
| 63 |
-
}
|
| 64 |
-
const MY_FP = getFingerprint();
|
| 65 |
-
|
| 66 |
-
// ─── ROLE HELPERS ─────────────────────────────────────────────
|
| 67 |
-
const ROLE_PRIORITY = { owner:5, admin:4, mod:3, vip:2, member:1 };
|
| 68 |
-
const ROLE_BADGE = { owner:'👑', admin:'🔰', mod:'⭐', vip:'💎', member:'' };
|
| 69 |
-
const ROLE_LABELS = { owner:'Owner', admin:'Admin', mod:'Moderator', vip:'VIP', member:'Mitglied' };
|
| 70 |
-
const ROLE_COLORS = { owner:'name-color-1', admin:'name-color-0', mod:'name-color-2', vip:'name-color-4', member:'' };
|
| 71 |
-
|
| 72 |
-
function hasRole(role) {
|
| 73 |
-
return currentUser && ROLE_PRIORITY[currentUser.role] >= ROLE_PRIORITY[role];
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
// ─── CAPTCHA ──────────────────────────────────────────────────
|
| 77 |
-
function genCaptcha() {
|
| 78 |
-
const a = Math.floor(Math.random() * 18) + 2;
|
| 79 |
-
const b = Math.floor(Math.random() * 18) + 2;
|
| 80 |
-
if (Math.random() > 0.4) return { q: `${a} + ${b} = ?`, ans: a + b };
|
| 81 |
-
const big = Math.max(a,b), sm = Math.min(a,b);
|
| 82 |
-
return { q: `${big} − ${sm} = ?`, ans: big - sm };
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
function refreshCaptcha(id) {
|
| 86 |
-
const d = genCaptcha();
|
| 87 |
-
captchaData[id] = d;
|
| 88 |
-
const qEl = document.getElementById(id + '-q');
|
| 89 |
-
if (qEl) qEl.textContent = d.q;
|
| 90 |
-
const aEl = document.getElementById(id + '-a');
|
| 91 |
-
if (aEl) aEl.value = '';
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
function verifyCaptcha(id) {
|
| 95 |
-
const a = parseInt(document.getElementById(id + '-a')?.value);
|
| 96 |
-
return captchaData[id] && a === captchaData[id].ans;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
// ─── TRANSLATION ──────────────────────────────────────────────
|
| 100 |
-
const TRANSLATIONS = {
|
| 101 |
-
// Simple dictionary for common words (offline fallback)
|
| 102 |
-
greetings: { hallo: 'hello', hi: 'hi', servus: 'hello', moin: 'morning', ciao: 'ciao', bye: 'bye', tschüss: 'bye', tschüss: 'bye' }
|
| 103 |
-
};
|
| 104 |
-
|
| 105 |
-
async function translateText(text, targetLang) {
|
| 106 |
-
// Use free LibreTranslate-compatible endpoint if available, else return as-is
|
| 107 |
-
try {
|
| 108 |
-
const res = await fetch('https://libretranslate.de/translate', {
|
| 109 |
-
method: 'POST',
|
| 110 |
-
headers: { 'Content-Type': 'application/json' },
|
| 111 |
-
body: JSON.stringify({ q: text, source: 'auto', target: targetLang }),
|
| 112 |
-
signal: AbortSignal.timeout(3000)
|
| 113 |
-
});
|
| 114 |
-
if (res.ok) {
|
| 115 |
-
const data = await res.json();
|
| 116 |
-
return data.translatedText || null;
|
| 117 |
-
}
|
| 118 |
-
} catch {}
|
| 119 |
-
return null; // silently fail
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
// ─── PING KEEPALIVE ───────────────────────────────────────────
|
| 123 |
-
async function pingServer() {
|
| 124 |
-
try { await fetch(PING_URL, { mode: 'no-cors', cache: 'no-cache' }); }
|
| 125 |
-
catch {}
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
function startPingTimer() {
|
| 129 |
-
pingServer();
|
| 130 |
-
pingTimer = setInterval(pingServer, PING_INTERVAL);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
// ─── AUTH TAB ─────────────────────────────────────────────────
|
| 134 |
-
function switchTab(tab) {
|
| 135 |
-
['login','register'].forEach((t,i) => {
|
| 136 |
-
document.getElementById('tab-' + t).style.display = t === tab ? '' : 'none';
|
| 137 |
-
document.querySelectorAll('.auth-tab')[i].classList.toggle('active', t === tab);
|
| 138 |
-
});
|
| 139 |
-
document.getElementById('auth-error').textContent = '';
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
// ─── REGISTER ─────────────────────────────────────────────────
|
| 143 |
-
async function doRegister() {
|
| 144 |
-
const u = document.getElementById('reg-user').value.trim();
|
| 145 |
-
const p = document.getElementById('reg-pass').value;
|
| 146 |
-
const p2 = document.getElementById('reg-pass2').value;
|
| 147 |
-
const err = id => document.getElementById('auth-error').textContent = id;
|
| 148 |
-
|
| 149 |
-
if (u.length < 2) return err('Username mind. 2 Zeichen');
|
| 150 |
-
if (u.length > 20) return err('Username max. 20 Zeichen');
|
| 151 |
-
if (!/^[a-zA-Z0-9_]+$/.test(u)) return err('Nur Buchstaben, Zahlen, _');
|
| 152 |
-
if (p.length < 4) return err('Passwort mind. 4 Zeichen');
|
| 153 |
-
if (p !== p2) return err('Passwörter stimmen nicht überein');
|
| 154 |
-
if (!verifyCaptcha('reg')) { refreshCaptcha('reg'); return err('❌ Falsches Captcha!'); }
|
| 155 |
-
|
| 156 |
-
const mod = (await DB.get('moderation')) || {};
|
| 157 |
-
if (mod.bans?.[u.toLowerCase()]) return err('Dieser Account ist gesperrt.');
|
| 158 |
-
if (mod.banned_fps?.[MY_FP]) return showBanned();
|
| 159 |
-
|
| 160 |
-
const users = (await DB.get('users')) || {};
|
| 161 |
-
if (users[u.toLowerCase()]) return err('Username bereits vergeben');
|
| 162 |
-
|
| 163 |
-
users[u.toLowerCase()] = {
|
| 164 |
-
username: u, password: encode(p),
|
| 165 |
-
color: Math.floor(Math.random() * 5), role: 'member', joined: Date.now(),
|
| 166 |
-
settings: { lang: 'de', translate: false, notif: true }
|
| 167 |
-
};
|
| 168 |
-
await DB.set('users', users);
|
| 169 |
-
refreshCaptcha('reg');
|
| 170 |
-
showAuthSuccess('✓ Account erstellt! Du kannst dich jetzt einloggen.');
|
| 171 |
-
setTimeout(() => { switchTab('login'); document.getElementById('login-user').value = u; }, 1300);
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
// ─── LOGIN ────────────────────────────────────────────────────
|
| 175 |
-
async function doLogin() {
|
| 176 |
-
const u = document.getElementById('login-user').value.trim();
|
| 177 |
-
const p = document.getElementById('login-pass').value;
|
| 178 |
-
const err = t => document.getElementById('auth-error').textContent = t;
|
| 179 |
-
|
| 180 |
-
if (!verifyCaptcha('login')) { refreshCaptcha('login'); return err('❌ Falsches Captcha!'); }
|
| 181 |
-
|
| 182 |
-
const mod = (await DB.get('moderation')) || {};
|
| 183 |
-
if (mod.banned_fps?.[MY_FP]) return showBanned();
|
| 184 |
-
|
| 185 |
-
const users = (await DB.get('users')) || {};
|
| 186 |
-
const entry = users[u.toLowerCase()];
|
| 187 |
-
if (!entry) return err('Falscher Username oder Passwort');
|
| 188 |
-
if (decode(entry.password) !== p) return err('Falscher Username oder Passwort');
|
| 189 |
-
if (mod.bans?.[u.toLowerCase()]) return err('🚫 Du bist von NoahsChat gebannt.');
|
| 190 |
-
|
| 191 |
-
currentUser = { ...entry };
|
| 192 |
-
refreshCaptcha('login');
|
| 193 |
-
|
| 194 |
-
const fps = (await DB.get('user_fps')) || {};
|
| 195 |
-
fps[entry.username.toLowerCase()] = MY_FP;
|
| 196 |
-
await DB.set('user_fps', fps);
|
| 197 |
-
|
| 198 |
-
const online = (await DB.get('online')) || {};
|
| 199 |
-
online[entry.username] = Date.now();
|
| 200 |
-
await DB.set('online', online);
|
| 201 |
-
|
| 202 |
-
userLanguage = entry.settings?.lang || 'de';
|
| 203 |
-
translationEnabled = entry.settings?.translate || false;
|
| 204 |
-
|
| 205 |
-
launchApp();
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
// ─── LOGOUT ───────────────────────────────────────────────────
|
| 209 |
-
async function doLogout() {
|
| 210 |
-
if (!currentUser) return;
|
| 211 |
-
const online = (await DB.get('online')) || {};
|
| 212 |
-
delete online[currentUser.username];
|
| 213 |
-
await DB.set('online', online);
|
| 214 |
-
if (voiceActive) await leaveVoice();
|
| 215 |
-
currentUser = null;
|
| 216 |
-
clearInterval(pollTimer);
|
| 217 |
-
clearInterval(pingTimer);
|
| 218 |
-
document.getElementById('app').classList.remove('visible');
|
| 219 |
-
document.getElementById('auth-screen').style.display = 'flex';
|
| 220 |
-
document.getElementById('login-pass').value = '';
|
| 221 |
-
refreshCaptcha('login');
|
| 222 |
-
}
|
| 223 |
-
|
| 224 |
-
// ─── LAUNCH APP ───────────────────────────────────────────────
|
| 225 |
-
async function launchApp() {
|
| 226 |
-
document.getElementById('auth-screen').style.display = 'none';
|
| 227 |
-
document.getElementById('app').classList.add('visible');
|
| 228 |
-
|
| 229 |
-
// Load config
|
| 230 |
-
appConfig = (await DB.get('config')) || {};
|
| 231 |
-
if (!appConfig.channels) {
|
| 232 |
-
appConfig.channels = window.DEFAULT_CHANNELS || [];
|
| 233 |
-
appConfig.automod = window.DEFAULT_AUTOMOD || {};
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
updateTopbar();
|
| 237 |
-
buildChannelList();
|
| 238 |
-
await openChannel('allgemein');
|
| 239 |
-
startPolling();
|
| 240 |
-
startPingTimer();
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
function updateTopbar() {
|
| 244 |
-
const av = document.getElementById('topbar-avatar');
|
| 245 |
-
av.textContent = currentUser.username[0].toUpperCase();
|
| 246 |
-
av.className = `user-avatar-sm av-color-${currentUser.color}`;
|
| 247 |
-
document.getElementById('topbar-username').textContent = currentUser.username;
|
| 248 |
-
document.getElementById('topbar-role-badge').textContent = ROLE_BADGE[currentUser.role] || '';
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
// ─── BUILD SIDEBAR ────────────────────────────────────────────
|
| 252 |
-
function buildChannelList() {
|
| 253 |
-
const channels = appConfig.channels || window.DEFAULT_CHANNELS || [];
|
| 254 |
-
const list = document.getElementById('channel-list');
|
| 255 |
-
list.innerHTML = '';
|
| 256 |
-
|
| 257 |
-
const categories = {
|
| 258 |
-
info: 'Info',
|
| 259 |
-
chat: 'Text-Channels',
|
| 260 |
-
fun: 'Community',
|
| 261 |
-
voice: 'Voice',
|
| 262 |
-
staff: 'Staff'
|
| 263 |
-
};
|
| 264 |
-
|
| 265 |
-
const grouped = {};
|
| 266 |
-
for (const ch of channels) {
|
| 267 |
-
const cat = ch.category || 'chat';
|
| 268 |
-
if (!grouped[cat]) grouped[cat] = [];
|
| 269 |
-
grouped[cat].push(ch);
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
for (const [catId, label] of Object.entries(categories)) {
|
| 273 |
-
const chs = grouped[catId];
|
| 274 |
-
if (!chs) continue;
|
| 275 |
-
|
| 276 |
-
// Staff channels only visible to mods+
|
| 277 |
-
if (catId === 'staff' && !hasRole('mod')) continue;
|
| 278 |
-
|
| 279 |
-
const catEl = document.createElement('div');
|
| 280 |
-
catEl.className = 'channel-category';
|
| 281 |
-
catEl.textContent = '— ' + label;
|
| 282 |
-
list.appendChild(catEl);
|
| 283 |
-
|
| 284 |
-
for (const ch of chs) {
|
| 285 |
-
// Check visibility
|
| 286 |
-
if (ch.adminOnly && !hasRole('admin')) {
|
| 287 |
-
if (catId === 'staff') continue;
|
| 288 |
-
// Show locked version for info channels
|
| 289 |
-
const div = document.createElement('div');
|
| 290 |
-
div.className = 'channel-item ch-locked';
|
| 291 |
-
div.innerHTML = `<span class="channel-icon">${ch.icon}</span><span class="channel-name">${ch.name}</span><span style="font-size:.65rem;color:var(--muted)">🔒</span>`;
|
| 292 |
-
list.appendChild(div);
|
| 293 |
-
continue;
|
| 294 |
-
}
|
| 295 |
-
if (ch.modOnly && !hasRole('mod')) continue;
|
| 296 |
-
|
| 297 |
-
const isVoice = catId === 'voice' || ch.id === 'voicetext';
|
| 298 |
-
|
| 299 |
-
const div = document.createElement('div');
|
| 300 |
-
div.className = 'channel-item' + (ch.id === currentChannel ? ' active' : '');
|
| 301 |
-
div.dataset.channel = ch.id;
|
| 302 |
-
div.innerHTML = `
|
| 303 |
-
<span class="channel-icon">${ch.icon}</span>
|
| 304 |
-
<span class="channel-name">${ch.name}</span>
|
| 305 |
-
<span class="unread-badge" id="badge-${ch.id}" style="display:none"></span>`;
|
| 306 |
-
div.onclick = () => openChannel(ch.id);
|
| 307 |
-
list.appendChild(div);
|
| 308 |
-
}
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
// Voice channels
|
| 312 |
-
const voiceCat = document.createElement('div');
|
| 313 |
-
voiceCat.className = 'channel-category';
|
| 314 |
-
voiceCat.textContent = '— Voice Channels';
|
| 315 |
-
list.appendChild(voiceCat);
|
| 316 |
-
|
| 317 |
-
const voiceChannels = [
|
| 318 |
-
{ id: 'voice-allgemein', name: 'Allgemein', icon: '🔊' },
|
| 319 |
-
{ id: 'voice-gaming', name: 'Gaming', icon: '🎮' },
|
| 320 |
-
{ id: 'voice-musik', name: 'Musik', icon: '🎵' },
|
| 321 |
-
];
|
| 322 |
-
|
| 323 |
-
for (const vc of voiceChannels) {
|
| 324 |
-
const div = document.createElement('div');
|
| 325 |
-
div.className = 'channel-item';
|
| 326 |
-
div.dataset.vc = vc.id;
|
| 327 |
-
div.innerHTML = `<span class="channel-icon">${vc.icon}</span><span class="channel-name">${vc.name}</span>`;
|
| 328 |
-
div.onclick = () => joinVoice(vc.id, vc.name);
|
| 329 |
-
list.appendChild(div);
|
| 330 |
-
|
| 331 |
-
// Show participants
|
| 332 |
-
const parts = voiceParticipants[vc.id];
|
| 333 |
-
if (parts && parts.length > 0) {
|
| 334 |
-
const partsEl = document.createElement('div');
|
| 335 |
-
partsEl.className = 'voice-ch-participants';
|
| 336 |
-
partsEl.id = 'vpc-' + vc.id;
|
| 337 |
-
partsEl.style.paddingLeft = '22px';
|
| 338 |
-
for (const p of parts) {
|
| 339 |
-
const pe = document.createElement('div');
|
| 340 |
-
pe.className = 'voice-participant';
|
| 341 |
-
pe.innerHTML = `<span>🎙</span><span>${escHtml(p.name)}</span>`;
|
| 342 |
-
partsEl.appendChild(pe);
|
| 343 |
-
}
|
| 344 |
-
list.appendChild(partsEl);
|
| 345 |
-
}
|
| 346 |
-
}
|
| 347 |
-
}
|
| 348 |
-
|
| 349 |
-
function buildDMList() {
|
| 350 |
-
// done in updateDMList async
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
// ─── POLLING ──────────────────────────────────────────────────
|
| 354 |
-
function startPolling() {
|
| 355 |
-
pollTimer = setInterval(pollTick, 2500);
|
| 356 |
-
}
|
| 357 |
-
|
| 358 |
-
async function pollTick() {
|
| 359 |
-
if (!currentUser) return;
|
| 360 |
-
|
| 361 |
-
// Refresh user data
|
| 362 |
-
const users = (await DB.get('users')) || {};
|
| 363 |
-
const me = users[currentUser.username.toLowerCase()];
|
| 364 |
-
if (me) {
|
| 365 |
-
currentUser = { ...me };
|
| 366 |
-
updateTopbar();
|
| 367 |
-
userLanguage = me.settings?.lang || 'de';
|
| 368 |
-
translationEnabled = me.settings?.translate || false;
|
| 369 |
-
}
|
| 370 |
-
|
| 371 |
-
// Heartbeat
|
| 372 |
-
const online = (await DB.get('online')) || {};
|
| 373 |
-
online[currentUser.username] = Date.now();
|
| 374 |
-
await DB.set('online', online);
|
| 375 |
-
|
| 376 |
-
const mod = (await DB.get('moderation')) || {};
|
| 377 |
-
|
| 378 |
-
// Ban check
|
| 379 |
-
if (mod.bans?.[currentUser.username.toLowerCase()] || mod.banned_fps?.[MY_FP]) {
|
| 380 |
-
clearInterval(pollTimer);
|
| 381 |
-
document.getElementById('app').classList.remove('visible');
|
| 382 |
-
showBanned();
|
| 383 |
-
return;
|
| 384 |
-
}
|
| 385 |
-
|
| 386 |
-
// Kick check
|
| 387 |
-
const kick = mod.kicked?.[currentUser.username.toLowerCase()];
|
| 388 |
-
if (kick && Date.now() - kick.ts < 60000) {
|
| 389 |
-
clearInterval(pollTimer);
|
| 390 |
-
showKickedModal();
|
| 391 |
-
return;
|
| 392 |
-
}
|
| 393 |
-
|
| 394 |
-
// Timeout bar
|
| 395 |
-
updateTimeoutBar(mod);
|
| 396 |
-
|
| 397 |
-
// Update user list
|
| 398 |
-
await updateUserList(online);
|
| 399 |
-
|
| 400 |
-
// Unread badges
|
| 401 |
-
const channels = appConfig.channels || window.DEFAULT_CHANNELS || [];
|
| 402 |
-
for (const ch of channels) {
|
| 403 |
-
if (ch.id === currentChannel && !currentDM) continue;
|
| 404 |
-
const msgs = (await DB.get(`msgs_${ch.id}`)) || [];
|
| 405 |
-
const key = `ch_${ch.id}`;
|
| 406 |
-
const prev = lastMsgCount[key] || 0;
|
| 407 |
-
if (msgs.length > prev) {
|
| 408 |
-
unreadCounts[key] = (unreadCounts[key] || 0) + (msgs.length - prev);
|
| 409 |
-
updateBadge(`badge-${ch.id}`, unreadCounts[key]);
|
| 410 |
-
lastMsgCount[key] = msgs.length;
|
| 411 |
-
}
|
| 412 |
-
}
|
| 413 |
-
|
| 414 |
-
// DM unread
|
| 415 |
-
for (const uname of Object.keys(users)) {
|
| 416 |
-
if (uname === currentUser.username.toLowerCase()) continue;
|
| 417 |
-
const dmKey = getDMKey(currentUser.username, users[uname].username);
|
| 418 |
-
const msgs = (await DB.get(`dm_${dmKey}`)) || [];
|
| 419 |
-
const key = `dm_${uname}`;
|
| 420 |
-
if (currentDM && currentDM.toLowerCase() === uname) continue;
|
| 421 |
-
const prev = lastMsgCount[key] || 0;
|
| 422 |
-
if (msgs.length > prev) {
|
| 423 |
-
unreadCounts[key] = (unreadCounts[key] || 0) + (msgs.length - prev);
|
| 424 |
-
lastMsgCount[key] = msgs.length;
|
| 425 |
-
await updateDMList();
|
| 426 |
-
}
|
| 427 |
-
}
|
| 428 |
-
|
| 429 |
-
// Refresh voice participants
|
| 430 |
-
const vp = (await DB.get('voice_participants')) || {};
|
| 431 |
-
voiceParticipants = vp;
|
| 432 |
-
|
| 433 |
-
// Reload current view
|
| 434 |
-
if (currentDM) await loadDMMessages(currentDM);
|
| 435 |
-
else await loadMessages(currentChannel);
|
| 436 |
-
}
|
| 437 |
-
|
| 438 |
-
function updateTimeoutBar(mod) {
|
| 439 |
-
const t = mod?.timeouts?.[currentUser.username.toLowerCase()];
|
| 440 |
-
const bar = document.getElementById('timeout-bar');
|
| 441 |
-
if (t && t.until > Date.now()) {
|
| 442 |
-
bar.style.display = '';
|
| 443 |
-
const d = new Date(t.until);
|
| 444 |
-
document.getElementById('timeout-until').textContent =
|
| 445 |
-
d.toLocaleTimeString('de-DE', { hour:'2-digit', minute:'2-digit', second:'2-digit' });
|
| 446 |
-
document.getElementById('msg-input').disabled = true;
|
| 447 |
-
document.getElementById('send-btn').disabled = true;
|
| 448 |
-
} else {
|
| 449 |
-
bar.style.display = 'none';
|
| 450 |
-
const ch = (appConfig.channels || window.DEFAULT_CHANNELS || []).find(c => c.id === currentChannel);
|
| 451 |
-
const locked = ch?.adminOnly && !hasRole('admin') || ch?.readOnly && !hasRole('admin');
|
| 452 |
-
document.getElementById('msg-input').disabled = !!locked;
|
| 453 |
-
document.getElementById('send-btn').disabled = !!locked;
|
| 454 |
-
}
|
| 455 |
-
}
|
| 456 |
-
|
| 457 |
-
function updateBadge(id, count) {
|
| 458 |
-
const el = document.getElementById(id);
|
| 459 |
-
if (!el) return;
|
| 460 |
-
if (count > 0) { el.style.display = ''; el.textContent = count > 99 ? '99+' : count; }
|
| 461 |
-
else el.style.display = 'none';
|
| 462 |
-
}
|
| 463 |
-
|
| 464 |
-
// ─── CHANNELS ─────────────────────────────────────────────────
|
| 465 |
-
async function openChannel(chId) {
|
| 466 |
-
currentChannel = chId;
|
| 467 |
-
currentDM = null;
|
| 468 |
-
|
| 469 |
-
document.querySelectorAll('.channel-item').forEach(el => el.classList.remove('active'));
|
| 470 |
-
document.querySelector(`[data-channel="${chId}"]`)?.classList.add('active');
|
| 471 |
-
document.querySelectorAll('.dm-item').forEach(el => el.classList.remove('active'));
|
| 472 |
-
|
| 473 |
-
const channels = appConfig.channels || window.DEFAULT_CHANNELS || [];
|
| 474 |
-
const ch = channels.find(c => c.id === chId) || { name: chId, icon: '💬', sub: '' };
|
| 475 |
-
document.getElementById('chat-title').textContent = ch.icon + ' ' + ch.name;
|
| 476 |
-
document.getElementById('chat-sub').textContent = ch.sub || '';
|
| 477 |
-
document.getElementById('topbar-channel-name').textContent = '# ' + ch.name;
|
| 478 |
-
|
| 479 |
-
unreadCounts[`ch_${chId}`] = 0;
|
| 480 |
-
updateBadge(`badge-${chId}`, 0);
|
| 481 |
-
|
| 482 |
-
const locked = (ch.adminOnly && !hasRole('admin')) || (ch.readOnly && !hasRole('admin')) || (ch.modOnly && !hasRole('mod'));
|
| 483 |
-
document.getElementById('msg-input').disabled = locked;
|
| 484 |
-
document.getElementById('send-btn').disabled = locked;
|
| 485 |
-
document.getElementById('msg-input').placeholder = locked ? '🔒 Du kannst hier nicht schreiben' : 'Nachricht schreiben...';
|
| 486 |
-
|
| 487 |
-
await loadMessages(chId);
|
| 488 |
-
}
|
| 489 |
-
|
| 490 |
-
async function loadMessages(chId) {
|
| 491 |
-
const msgs = (await DB.get(`msgs_${chId}`)) || [];
|
| 492 |
-
lastMsgCount[`ch_${chId}`] = msgs.length;
|
| 493 |
-
await renderMessages(msgs);
|
| 494 |
-
}
|
| 495 |
-
|
| 496 |
-
// ─── DM ───────────────────────────────────────────────────────
|
| 497 |
-
function getDMKey(a, b) {
|
| 498 |
-
return [a.toLowerCase(), b.toLowerCase()].sort().join('__');
|
| 499 |
-
}
|
| 500 |
-
|
| 501 |
-
async function openDM(username) {
|
| 502 |
-
currentDM = username;
|
| 503 |
-
currentChannel = null;
|
| 504 |
-
|
| 505 |
-
document.querySelectorAll('.channel-item').forEach(el => el.classList.remove('active'));
|
| 506 |
-
document.querySelectorAll('.dm-item').forEach(el => {
|
| 507 |
-
el.classList.toggle('active', el.dataset.user === username.toLowerCase());
|
| 508 |
-
});
|
| 509 |
-
|
| 510 |
-
document.getElementById('chat-title').textContent = '@ ' + username;
|
| 511 |
-
document.getElementById('chat-sub').textContent = 'Direktnachricht — privat & verschlüsselt';
|
| 512 |
-
document.getElementById('topbar-channel-name').textContent = '@ ' + username;
|
| 513 |
-
|
| 514 |
-
document.getElementById('msg-input').disabled = false;
|
| 515 |
-
document.getElementById('send-btn').disabled = false;
|
| 516 |
-
document.getElementById('msg-input').placeholder = 'Nachricht schreiben...';
|
| 517 |
-
|
| 518 |
-
unreadCounts[`dm_${username.toLowerCase()}`] = 0;
|
| 519 |
-
await updateDMList();
|
| 520 |
-
await loadDMMessages(username);
|
| 521 |
-
}
|
| 522 |
-
|
| 523 |
-
async function loadDMMessages(username) {
|
| 524 |
-
const dmKey = getDMKey(currentUser.username, username);
|
| 525 |
-
const msgs = (await DB.get(`dm_${dmKey}`)) || [];
|
| 526 |
-
lastMsgCount[`dm_${username.toLowerCase()}`] = msgs.length;
|
| 527 |
-
await renderMessages(msgs, true);
|
| 528 |
-
}
|
| 529 |
-
|
| 530 |
-
// ─── RENDER MESSAGES ──────────────────────────────────────────
|
| 531 |
-
async function renderMessages(msgs, isDM = false) {
|
| 532 |
-
const container = document.getElementById('messages');
|
| 533 |
-
const atBottom = container.scrollHeight - container.scrollTop <= container.clientHeight + 80;
|
| 534 |
-
|
| 535 |
-
if (!msgs.length) {
|
| 536 |
-
container.innerHTML = `<div class="empty-chat"><div class="empty-chat-icon">💬</div><p>Noch keine Nachrichten hier. Schreib was!</p></div>`;
|
| 537 |
-
return;
|
| 538 |
-
}
|
| 539 |
-
|
| 540 |
-
let html = '';
|
| 541 |
-
let lastDay = '', lastAuthor = '', lastTime = 0;
|
| 542 |
-
|
| 543 |
-
for (let i = 0; i < msgs.length; i++) {
|
| 544 |
-
const m = msgs[i];
|
| 545 |
-
|
| 546 |
-
// System / AutoMod messages
|
| 547 |
-
if (m.system) {
|
| 548 |
-
html += `<div class="msg-system">⚙ ${escHtml(m.text)}</div>`;
|
| 549 |
-
lastAuthor = ''; continue;
|
| 550 |
-
}
|
| 551 |
-
if (m.automod) {
|
| 552 |
-
html += `<div class="msg-automod">🤖 AutoMod: ${escHtml(m.text)}</div>`;
|
| 553 |
-
lastAuthor = ''; continue;
|
| 554 |
-
}
|
| 555 |
-
|
| 556 |
-
const date = new Date(m.ts);
|
| 557 |
-
const day = date.toLocaleDateString('de-DE', { day:'2-digit', month:'2-digit', year:'numeric' });
|
| 558 |
-
const time = date.toLocaleTimeString('de-DE', { hour:'2-digit', minute:'2-digit' });
|
| 559 |
-
|
| 560 |
-
if (day !== lastDay) {
|
| 561 |
-
html += `<div class="day-divider">${day}</div>`;
|
| 562 |
-
lastDay = day; lastAuthor = '';
|
| 563 |
-
}
|
| 564 |
-
|
| 565 |
-
const color = m.color ?? 0;
|
| 566 |
-
const consecutive= m.author === lastAuthor && (m.ts - lastTime) < 5*60000;
|
| 567 |
-
lastAuthor = m.author; lastTime = m.ts;
|
| 568 |
-
|
| 569 |
-
const initials = (m.author || '?')[0].toUpperCase();
|
| 570 |
-
const role = m.role || 'member';
|
| 571 |
-
const badge = ROLE_BADGE[role] || '';
|
| 572 |
-
const nameClass= ROLE_COLORS[role] || `name-color-${color}`;
|
| 573 |
-
|
| 574 |
-
// Delete/mod actions
|
| 575 |
-
const canDelete = hasRole('mod') || m.author === currentUser?.username;
|
| 576 |
-
const canPin = hasRole('mod');
|
| 577 |
-
const actionsHtml = `
|
| 578 |
-
<div class="msg-actions">
|
| 579 |
-
${isDM && translationEnabled ? `<button class="msg-action-btn" onclick="translateMsg(this,'${escHtml(m.text)}')">🌐</button>` : ''}
|
| 580 |
-
${!isDM && translationEnabled ? `<button class="msg-action-btn" onclick="translateMsg(this,'${escHtml(m.text)}')">🌐</button>` : ''}
|
| 581 |
-
${canPin ? `<button class="msg-action-btn" onclick="pinMessage('${escHtml(m.author)}','${escHtml(m.text.substring(0,50))}')">📌</button>` : ''}
|
| 582 |
-
${canDelete ? `<button class="msg-action-btn danger" onclick="deleteMsg(${i})">🗑</button>` : ''}
|
| 583 |
-
</div>`;
|
| 584 |
-
|
| 585 |
-
html += `
|
| 586 |
-
<div class="msg ${consecutive?'consecutive':''}" data-idx="${i}">
|
| 587 |
-
<div class="msg-avatar av-color-${color}" onclick="onAvatarClick(event,'${escHtml(m.author)}')">${initials}</div>
|
| 588 |
-
<div class="msg-content">
|
| 589 |
-
<div class="msg-header">
|
| 590 |
-
<span class="msg-name ${nameClass}" onclick="onAvatarClick(event,'${escHtml(m.author)}')">${escHtml(m.author)} ${badge ? `<span class="msg-role-badge">${badge}</span>` : ''}</span>
|
| 591 |
-
<span class="msg-time">${time}</span>
|
| 592 |
-
${actionsHtml}
|
| 593 |
-
</div>
|
| 594 |
-
<div class="msg-text" id="mt-${i}">${formatMsg(m.text)}</div>
|
| 595 |
-
</div>
|
| 596 |
-
</div>`;
|
| 597 |
-
}
|
| 598 |
-
|
| 599 |
-
container.innerHTML = html;
|
| 600 |
-
if (atBottom) container.scrollTop = container.scrollHeight;
|
| 601 |
-
|
| 602 |
-
// Auto-translate if enabled
|
| 603 |
-
if (translationEnabled && userLanguage !== 'de') {
|
| 604 |
-
// Don't block render, translate in background
|
| 605 |
-
translateVisibleMessages(msgs);
|
| 606 |
-
}
|
| 607 |
-
}
|
| 608 |
-
|
| 609 |
-
async function translateVisibleMessages(msgs) {
|
| 610 |
-
// Translate up to last 10 msgs silently
|
| 611 |
-
const start = Math.max(0, msgs.length - 10);
|
| 612 |
-
for (let i = start; i < msgs.length; i++) {
|
| 613 |
-
const m = msgs[i];
|
| 614 |
-
if (m.system || m.automod) continue;
|
| 615 |
-
const el = document.getElementById('mt-' + i);
|
| 616 |
-
if (!el || el.dataset.translated) continue;
|
| 617 |
-
const target = userLanguage === 'de' ? 'de' : 'en';
|
| 618 |
-
const translated = await translateText(m.text, target);
|
| 619 |
-
if (translated && translated !== m.text && el) {
|
| 620 |
-
el.dataset.translated = '1';
|
| 621 |
-
el.insertAdjacentHTML('afterend', `<div class="msg-translated">🌐 ${escHtml(translated)}</div>`);
|
| 622 |
-
}
|
| 623 |
-
}
|
| 624 |
-
}
|
| 625 |
-
|
| 626 |
-
function formatMsg(text) {
|
| 627 |
-
return escHtml(text)
|
| 628 |
-
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 629 |
-
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 630 |
-
.replace(/`(.*?)`/g, '<code style="background:rgba(0,212,255,0.08);padding:1px 5px;border-radius:2px;font-family:monospace">$1</code>')
|
| 631 |
-
.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1" target="_blank" rel="noopener">$1</a>');
|
| 632 |
-
}
|
| 633 |
-
|
| 634 |
-
async function translateMsg(btn, text) {
|
| 635 |
-
const target = userLanguage === 'de' ? 'en' : 'de';
|
| 636 |
-
btn.textContent = '⏳';
|
| 637 |
-
const result = await translateText(text, target);
|
| 638 |
-
btn.textContent = '🌐';
|
| 639 |
-
if (result) {
|
| 640 |
-
const msgEl = btn.closest('.msg-content');
|
| 641 |
-
const existing = msgEl.querySelector('.msg-translated');
|
| 642 |
-
if (existing) existing.remove();
|
| 643 |
-
else msgEl.insertAdjacentHTML('beforeend', `<div class="msg-translated">🌐 ${escHtml(result)}</div>`);
|
| 644 |
-
} else {
|
| 645 |
-
showToast('Übersetzung nicht verfügbar', 'var(--warn)');
|
| 646 |
-
}
|
| 647 |
-
}
|
| 648 |
-
|
| 649 |
-
// ─── SEND ─────────────────────────────────────────────────────
|
| 650 |
-
async function sendMessage() {
|
| 651 |
-
const input = document.getElementById('msg-input');
|
| 652 |
-
const text = input.value.trim();
|
| 653 |
-
if (!text || !currentUser) return;
|
| 654 |
-
|
| 655 |
-
// Timeout check
|
| 656 |
-
const mod = (await DB.get('moderation')) || {};
|
| 657 |
-
const to = mod.timeouts?.[currentUser.username.toLowerCase()];
|
| 658 |
-
if (to && to.until > Date.now()) { showToast('Du bist stummgeschaltet!', 'var(--warn)'); return; }
|
| 659 |
-
|
| 660 |
-
// Channel permission
|
| 661 |
-
const channels = appConfig.channels || window.DEFAULT_CHANNELS || [];
|
| 662 |
-
const ch = channels.find(c => c.id === currentChannel);
|
| 663 |
-
if (ch?.adminOnly && !hasRole('admin')) return;
|
| 664 |
-
if (ch?.readOnly && !hasRole('admin')) return;
|
| 665 |
-
if (ch?.modOnly && !hasRole('mod')) return;
|
| 666 |
-
|
| 667 |
-
// AutoMod
|
| 668 |
-
const amResult = autoModCheck(text);
|
| 669 |
-
if (amResult.blocked) {
|
| 670 |
-
showToast('🤖 AutoMod: Nachricht blockiert – ' + amResult.reason, 'var(--warn)');
|
| 671 |
-
if (hasRole('mod')) {
|
| 672 |
-
// Log for mods
|
| 673 |
-
const modLogs = (await DB.get('msgs_moderators')) || [];
|
| 674 |
-
modLogs.push({ automod: true, text: `Blockierte Nachricht von ${currentUser.username}: "${text}" (${amResult.reason})`, ts: Date.now() });
|
| 675 |
-
await DB.set('msgs_moderators', modLogs);
|
| 676 |
-
}
|
| 677 |
-
input.value = ''; input.style.height = '';
|
| 678 |
-
return;
|
| 679 |
-
}
|
| 680 |
-
|
| 681 |
-
// Spam detection
|
| 682 |
-
const now = Date.now();
|
| 683 |
-
spamTs = spamTs.filter(t => now - t < (appConfig.automod?.spamWindow || 10000));
|
| 684 |
-
spamTs.push(now);
|
| 685 |
-
const spamThreshold = appConfig.automod?.spamThreshold || 5;
|
| 686 |
-
if (spamTs.length > spamThreshold) {
|
| 687 |
-
pendingSpamMsg = text;
|
| 688 |
-
input.value = ''; input.style.height = '';
|
| 689 |
-
showSpamCaptchaModal();
|
| 690 |
-
return;
|
| 691 |
-
}
|
| 692 |
-
|
| 693 |
-
input.value = ''; input.style.height = '';
|
| 694 |
-
await _sendMsg(text);
|
| 695 |
-
}
|
| 696 |
-
|
| 697 |
-
function autoModCheck(text) {
|
| 698 |
-
const am = appConfig.automod || {};
|
| 699 |
-
if (!am.enabled) return { blocked: false };
|
| 700 |
-
|
| 701 |
-
// Max length
|
| 702 |
-
if (am.maxMsgLength && text.length > am.maxMsgLength)
|
| 703 |
-
return { blocked: true, reason: `Nachricht zu lang (max. ${am.maxMsgLength} Zeichen)` };
|
| 704 |
-
|
| 705 |
-
// Banned words
|
| 706 |
-
const lower = text.toLowerCase();
|
| 707 |
-
for (const w of (am.bannedWords || [])) {
|
| 708 |
-
if (lower.includes(w.toLowerCase()))
|
| 709 |
-
return { blocked: true, reason: 'Verbotenes Wort' };
|
| 710 |
-
}
|
| 711 |
-
|
| 712 |
-
// Caps filter
|
| 713 |
-
if (am.capsFilter && text.length > 10) {
|
| 714 |
-
const caps = (text.match(/[A-ZÄÖÜ]/g) || []).length;
|
| 715 |
-
if (caps / text.length > (am.capsThreshold || 0.7))
|
| 716 |
-
return { blocked: false, warn: 'Bitte nicht so viel in Großbuchstaben schreiben' };
|
| 717 |
-
}
|
| 718 |
-
|
| 719 |
-
return { blocked: false };
|
| 720 |
-
}
|
| 721 |
-
|
| 722 |
-
async function _sendMsg(text) {
|
| 723 |
-
const msg = {
|
| 724 |
-
author: currentUser.username, color: currentUser.color,
|
| 725 |
-
role: currentUser.role, text, ts: Date.now()
|
| 726 |
-
};
|
| 727 |
-
|
| 728 |
-
if (currentDM) {
|
| 729 |
-
const dmKey = getDMKey(currentUser.username, currentDM);
|
| 730 |
-
const msgs = (await DB.get(`dm_${dmKey}`)) || [];
|
| 731 |
-
msgs.push(msg);
|
| 732 |
-
if (msgs.length > 500) msgs.splice(0, msgs.length - 500);
|
| 733 |
-
await DB.set(`dm_${dmKey}`, msgs);
|
| 734 |
-
await loadDMMessages(currentDM);
|
| 735 |
-
} else {
|
| 736 |
-
const msgs = (await DB.get(`msgs_${currentChannel}`)) || [];
|
| 737 |
-
msgs.push(msg);
|
| 738 |
-
if (msgs.length > 500) msgs.splice(0, msgs.length - 500);
|
| 739 |
-
await DB.set(`msgs_${currentChannel}`, msgs);
|
| 740 |
-
lastMsgCount[`ch_${currentChannel}`] = msgs.length;
|
| 741 |
-
await renderMessages(msgs);
|
| 742 |
-
const c = document.getElementById('messages');
|
| 743 |
-
c.scrollTop = c.scrollHeight;
|
| 744 |
-
}
|
| 745 |
-
}
|
| 746 |
-
|
| 747 |
-
async function deleteMsg(idx) {
|
| 748 |
-
if (currentDM) {
|
| 749 |
-
const dmKey = getDMKey(currentUser.username, currentDM);
|
| 750 |
-
const msgs = (await DB.get(`dm_${dmKey}`)) || [];
|
| 751 |
-
if (msgs[idx]) {
|
| 752 |
-
if (msgs[idx].author !== currentUser.username && !hasRole('mod')) return;
|
| 753 |
-
msgs.splice(idx, 1);
|
| 754 |
-
await DB.set(`dm_${dmKey}`, msgs);
|
| 755 |
-
await loadDMMessages(currentDM);
|
| 756 |
-
}
|
| 757 |
-
} else {
|
| 758 |
-
const msgs = (await DB.get(`msgs_${currentChannel}`)) || [];
|
| 759 |
-
if (msgs[idx]) {
|
| 760 |
-
if (msgs[idx].author !== currentUser.username && !hasRole('mod')) return;
|
| 761 |
-
msgs.splice(idx, 1);
|
| 762 |
-
await DB.set(`msgs_${currentChannel}`, msgs);
|
| 763 |
-
await loadMessages(currentChannel);
|
| 764 |
-
}
|
| 765 |
-
}
|
| 766 |
-
}
|
| 767 |
-
|
| 768 |
-
async function pinMessage(author, text) {
|
| 769 |
-
const pin = { author, text, by: currentUser.username, ts: Date.now(), channel: currentChannel };
|
| 770 |
-
const pins = (await DB.get('pins')) || [];
|
| 771 |
-
pins.push(pin);
|
| 772 |
-
if (pins.length > 20) pins.shift();
|
| 773 |
-
await DB.set('pins', pins);
|
| 774 |
-
showToast('📌 Nachricht angepinnt', 'var(--green)');
|
| 775 |
-
}
|
| 776 |
-
|
| 777 |
-
function handleKey(e) {
|
| 778 |
-
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); }
|
| 779 |
-
}
|
| 780 |
-
|
| 781 |
-
function autoResize(el) {
|
| 782 |
-
el.style.height = 'auto';
|
| 783 |
-
el.style.height = Math.min(el.scrollHeight, 120) + 'px';
|
| 784 |
-
}
|
| 785 |
-
|
| 786 |
-
// ─── VOICE ────────────────────────────────────────────────────
|
| 787 |
-
async function joinVoice(vcId, vcName) {
|
| 788 |
-
if (voiceActive && voiceChannel === vcId) { await leaveVoice(); return; }
|
| 789 |
-
if (voiceActive) await leaveVoice();
|
| 790 |
-
|
| 791 |
-
voiceActive = true;
|
| 792 |
-
voiceChannel = vcId;
|
| 793 |
-
|
| 794 |
-
const vp = (await DB.get('voice_participants')) || {};
|
| 795 |
-
if (!vp[vcId]) vp[vcId] = [];
|
| 796 |
-
vp[vcId] = vp[vcId].filter(p => p.name !== currentUser.username);
|
| 797 |
-
vp[vcId].push({ name: currentUser.username, muted: false, ts: Date.now() });
|
| 798 |
-
await DB.set('voice_participants', vp);
|
| 799 |
-
voiceParticipants = vp;
|
| 800 |
-
|
| 801 |
-
const vPanel = document.getElementById('voice-panel');
|
| 802 |
-
vPanel.classList.add('active');
|
| 803 |
-
document.getElementById('voice-channel-name').textContent = '🔊 ' + vcName;
|
| 804 |
-
document.getElementById('voice-mute-btn').classList.remove('active');
|
| 805 |
-
document.getElementById('voice-deaf-btn').classList.remove('active');
|
| 806 |
-
micMuted = false; deafened = false;
|
| 807 |
-
|
| 808 |
-
buildChannelList();
|
| 809 |
-
showToast(`🔊 Voice: ${vcName}`, 'var(--green)');
|
| 810 |
-
}
|
| 811 |
-
|
| 812 |
-
async function leaveVoice() {
|
| 813 |
-
if (!voiceActive) return;
|
| 814 |
-
const vp = (await DB.get('voice_participants')) || {};
|
| 815 |
-
if (vp[voiceChannel]) {
|
| 816 |
-
vp[voiceChannel] = vp[voiceChannel].filter(p => p.name !== currentUser.username);
|
| 817 |
-
await DB.set('voice_participants', vp);
|
| 818 |
-
}
|
| 819 |
-
voiceActive = false;
|
| 820 |
-
voiceChannel = null;
|
| 821 |
-
document.getElementById('voice-panel').classList.remove('active');
|
| 822 |
-
buildChannelList();
|
| 823 |
-
showToast('Verlassen', 'var(--muted)');
|
| 824 |
-
}
|
| 825 |
-
|
| 826 |
-
function toggleMute() {
|
| 827 |
-
micMuted = !micMuted;
|
| 828 |
-
const btn = document.getElementById('voice-mute-btn');
|
| 829 |
-
btn.textContent = micMuted ? '🔇 Stumm' : '🎙 Stumm';
|
| 830 |
-
btn.classList.toggle('active', micMuted);
|
| 831 |
-
}
|
| 832 |
-
|
| 833 |
-
function toggleDeafen() {
|
| 834 |
-
deafened = !deafened;
|
| 835 |
-
const btn = document.getElementById('voice-deaf-btn');
|
| 836 |
-
btn.textContent = deafened ? '🔕 Taub' : '🔔 Taub';
|
| 837 |
-
btn.classList.toggle('active', deafened);
|
| 838 |
-
}
|
| 839 |
-
|
| 840 |
-
// ─── USER LIST ────────────────────────────────────────────────
|
| 841 |
-
async function updateUserList(online) {
|
| 842 |
-
if (!online) online = (await DB.get('online')) || {};
|
| 843 |
-
const now = Date.now();
|
| 844 |
-
const users = (await DB.get('users')) || {};
|
| 845 |
-
|
| 846 |
-
const onlineNames = Object.entries(online)
|
| 847 |
-
.filter(([, ts]) => now - ts < 12000)
|
| 848 |
-
.map(([u]) => u);
|
| 849 |
-
|
| 850 |
-
document.getElementById('online-count').textContent = onlineNames.length;
|
| 851 |
-
|
| 852 |
-
const listEl = document.getElementById('user-list');
|
| 853 |
-
listEl.innerHTML = '';
|
| 854 |
-
|
| 855 |
-
// Group by role
|
| 856 |
-
const groups = { owner:[], admin:[], mod:[], vip:[], member:[] };
|
| 857 |
-
for (const udata of Object.values(users)) {
|
| 858 |
-
const role = udata.role || 'member';
|
| 859 |
-
if (groups[role]) groups[role].push(udata);
|
| 860 |
-
else groups.member.push(udata);
|
| 861 |
-
}
|
| 862 |
-
|
| 863 |
-
for (const [roleId, roleUsers] of Object.entries(groups)) {
|
| 864 |
-
if (!roleUsers.length) continue;
|
| 865 |
-
// Only show elevated roles as groups
|
| 866 |
-
if (roleId === 'member' && roleUsers.length > 0) {
|
| 867 |
-
const online_members = roleUsers.filter(u => onlineNames.includes(u.username));
|
| 868 |
-
const offline_members = roleUsers.filter(u => !onlineNames.includes(u.username));
|
| 869 |
-
appendRoleGroup(listEl, 'Mitglieder', [...online_members, ...offline_members], onlineNames);
|
| 870 |
-
} else {
|
| 871 |
-
appendRoleGroup(listEl, ROLE_LABELS[roleId] || roleId, roleUsers, onlineNames);
|
| 872 |
-
}
|
| 873 |
-
}
|
| 874 |
-
|
| 875 |
-
await updateDMList();
|
| 876 |
-
}
|
| 877 |
-
|
| 878 |
-
function appendRoleGroup(container, label, users, onlineNames) {
|
| 879 |
-
if (!users.length) return;
|
| 880 |
-
const header = document.createElement('div');
|
| 881 |
-
header.className = 'role-group-header';
|
| 882 |
-
header.innerHTML = `<span>${label}</span><span style="color:var(--muted);font-size:.7rem">${users.length}</span>`;
|
| 883 |
-
container.appendChild(header);
|
| 884 |
-
|
| 885 |
-
for (const udata of users) {
|
| 886 |
-
const isMe = udata.username === currentUser?.username;
|
| 887 |
-
const isOnline = onlineNames.includes(udata.username);
|
| 888 |
-
const badge = ROLE_BADGE[udata.role] || '';
|
| 889 |
-
const color = udata.color ?? 0;
|
| 890 |
-
const div = document.createElement('div');
|
| 891 |
-
div.className = 'user-item' + (isMe ? ' me' : '') + (!isOnline ? ' offline' : '');
|
| 892 |
-
div.innerHTML = `
|
| 893 |
-
<div class="${isOnline ? 'online-dot' : 'offline-dot'}"></div>
|
| 894 |
-
<div class="user-avatar-sm av-color-${color}">${udata.username[0].toUpperCase()}</div>
|
| 895 |
-
<span>${escHtml(udata.username)}${badge ? ' '+badge : ''}</span>`;
|
| 896 |
-
if (!isMe) div.onclick = e => { e.stopPropagation(); showUserCtx(e, udata.username); };
|
| 897 |
-
container.appendChild(div);
|
| 898 |
-
}
|
| 899 |
-
}
|
| 900 |
-
|
| 901 |
-
async function updateDMList() {
|
| 902 |
-
const users = (await DB.get('users')) || {};
|
| 903 |
-
const dmListEl = document.getElementById('dm-list');
|
| 904 |
-
dmListEl.innerHTML = '';
|
| 905 |
-
|
| 906 |
-
for (const entry of Object.values(users)) {
|
| 907 |
-
if (entry.username === currentUser?.username) continue;
|
| 908 |
-
const unread = unreadCounts[`dm_${entry.username.toLowerCase()}`] || 0;
|
| 909 |
-
const div = document.createElement('div');
|
| 910 |
-
div.className = `channel-item dm-item ${currentDM === entry.username ? 'active' : ''}`;
|
| 911 |
-
div.dataset.user = entry.username.toLowerCase();
|
| 912 |
-
div.innerHTML = `
|
| 913 |
-
<span class="channel-icon" style="font-size:1rem">@</span>
|
| 914 |
-
<span class="channel-name">${escHtml(entry.username)}</span>
|
| 915 |
-
${unread > 0 ? `<span class="unread-badge">${unread}</span>` : ''}`;
|
| 916 |
-
div.onclick = () => openDM(entry.username);
|
| 917 |
-
dmListEl.appendChild(div);
|
| 918 |
-
}
|
| 919 |
-
}
|
| 920 |
-
|
| 921 |
-
// ─── CONTEXT MENU ─────────────────────────────────────────────
|
| 922 |
-
function onAvatarClick(e, username) {
|
| 923 |
-
e.preventDefault(); e.stopPropagation();
|
| 924 |
-
hideCtx();
|
| 925 |
-
if (username === currentUser?.username) return;
|
| 926 |
-
if (!hasRole('mod')) { openDM(username); return; }
|
| 927 |
-
showUserCtx(e, username);
|
| 928 |
-
}
|
| 929 |
-
|
| 930 |
-
function showUserCtx(e, username) {
|
| 931 |
-
e.preventDefault(); e.stopPropagation();
|
| 932 |
-
hideCtx();
|
| 933 |
-
|
| 934 |
-
const menu = document.getElementById('context-menu');
|
| 935 |
-
menu.innerHTML = '';
|
| 936 |
-
|
| 937 |
-
const h = document.createElement('div');
|
| 938 |
-
h.className = 'ctx-header';
|
| 939 |
-
h.textContent = username;
|
| 940 |
-
menu.appendChild(h);
|
| 941 |
-
|
| 942 |
-
addCtxItem(menu, '💬 Direktnachricht', '', () => { hideCtx(); openDM(username); });
|
| 943 |
-
addCtxItem(menu, '👤 Profil', '', () => { hideCtx(); showProfileModal(username); });
|
| 944 |
-
|
| 945 |
-
if (hasRole('mod')) {
|
| 946 |
-
addCtxDivider(menu);
|
| 947 |
-
addCtxItem(menu, '👢 Kicken', 'warn', () => { hideCtx(); openKickModal(username); });
|
| 948 |
-
addCtxItem(menu, '⏱ Timeout', 'warn', () => { hideCtx(); openTimeoutModal(username); });
|
| 949 |
-
addCtxItem(menu, '🗑 Nachrichten löschen', 'warn', () => { hideCtx(); clearUserMsgs(username); });
|
| 950 |
-
}
|
| 951 |
-
|
| 952 |
-
if (hasRole('admin')) {
|
| 953 |
-
addCtxItem(menu, '🚫 Bannen', 'danger', () => { hideCtx(); openBanModal(username); });
|
| 954 |
-
addCtxDivider(menu);
|
| 955 |
-
addCtxItem(menu, '🎖 Rolle ändern','', () => { hideCtx(); openRoleModal(username); });
|
| 956 |
-
}
|
| 957 |
-
|
| 958 |
-
const x = Math.min(e.clientX, window.innerWidth - 210);
|
| 959 |
-
const y = Math.min(e.clientY, window.innerHeight - 200);
|
| 960 |
-
menu.style.left = x + 'px';
|
| 961 |
-
menu.style.top = y + 'px';
|
| 962 |
-
menu.style.display = '';
|
| 963 |
-
}
|
| 964 |
-
|
| 965 |
-
function addCtxItem(menu, label, cls, fn) {
|
| 966 |
-
const item = document.createElement('div');
|
| 967 |
-
item.className = 'ctx-item' + (cls ? ' '+cls : '');
|
| 968 |
-
item.textContent = label;
|
| 969 |
-
item.onclick = fn;
|
| 970 |
-
menu.appendChild(item);
|
| 971 |
-
}
|
| 972 |
-
function addCtxDivider(menu) {
|
| 973 |
-
const d = document.createElement('div'); d.className = 'ctx-divider'; menu.appendChild(d);
|
| 974 |
-
}
|
| 975 |
-
function hideCtx() { document.getElementById('context-menu').style.display = 'none'; }
|
| 976 |
-
|
| 977 |
-
document.addEventListener('click', hideCtx);
|
| 978 |
-
|
| 979 |
-
// ─── MODALS (MODERATION) ──────────────────────────────────────
|
| 980 |
-
function openKickModal(username) {
|
| 981 |
-
showModal(`
|
| 982 |
-
<div class="modal-title">👢 Kick: ${escHtml(username)}</div>
|
| 983 |
-
<div class="modal-sub">Der User wird aus dem Chat geworfen.</div>
|
| 984 |
-
<div class="modal-field"><label>Grund (optional)</label><input type="text" id="m-reason" placeholder="z.B. Regelverstoß"></div>
|
| 985 |
-
<div class="modal-btns">
|
| 986 |
-
<button class="modal-btn secondary" onclick="clearModal()">Abbrechen</button>
|
| 987 |
-
<button class="modal-btn warn-btn" onclick="doKick('${escHtml(username)}')">Kicken</button>
|
| 988 |
-
</div>`);
|
| 989 |
-
}
|
| 990 |
-
|
| 991 |
-
async function doKick(username) {
|
| 992 |
-
const reason = document.getElementById('m-reason')?.value || '';
|
| 993 |
-
const mod = (await DB.get('moderation')) || {};
|
| 994 |
-
if (!mod.kicked) mod.kicked = {};
|
| 995 |
-
mod.kicked[username.toLowerCase()] = { by: currentUser.username, ts: Date.now(), reason };
|
| 996 |
-
await DB.set('moderation', mod);
|
| 997 |
-
await sysMsg(`${username} wurde von ${currentUser.username} gekickt.${reason ? ' Grund: '+reason : ''}`);
|
| 998 |
-
clearModal();
|
| 999 |
-
showToast(`${username} gekickt`, 'var(--warn)');
|
| 1000 |
-
}
|
| 1001 |
-
|
| 1002 |
-
function openTimeoutModal(username) {
|
| 1003 |
-
showModal(`
|
| 1004 |
-
<div class="modal-title">⏱ Timeout: ${escHtml(username)}</div>
|
| 1005 |
-
<div class="modal-sub">Stummschalten für eine bestimmte Zeit.</div>
|
| 1006 |
-
<div class="modal-field"><label>Dauer</label>
|
| 1007 |
-
<select id="m-dur">
|
| 1008 |
-
<option value="60000">1 Minute</option>
|
| 1009 |
-
<option value="300000">5 Minuten</option>
|
| 1010 |
-
<option value="600000">10 Minuten</option>
|
| 1011 |
-
<option value="1800000">30 Minuten</option>
|
| 1012 |
-
<option value="3600000">1 Stunde</option>
|
| 1013 |
-
<option value="86400000">24 Stunden</option>
|
| 1014 |
-
</select></div>
|
| 1015 |
-
<div class="modal-field"><label>Grund</label><input type="text" id="m-reason" placeholder="z.B. Spam"></div>
|
| 1016 |
-
<div class="modal-btns">
|
| 1017 |
-
<button class="modal-btn secondary" onclick="clearModal()">Abbrechen</button>
|
| 1018 |
-
<button class="modal-btn warn-btn" onclick="doTimeout('${escHtml(username)}')">Timeout</button>
|
| 1019 |
-
</div>`);
|
| 1020 |
-
}
|
| 1021 |
-
|
| 1022 |
-
async function doTimeout(username) {
|
| 1023 |
-
const dur = parseInt(document.getElementById('m-dur').value);
|
| 1024 |
-
const reason = document.getElementById('m-reason')?.value || '';
|
| 1025 |
-
const mod = (await DB.get('moderation')) || {};
|
| 1026 |
-
if (!mod.timeouts) mod.timeouts = {};
|
| 1027 |
-
mod.timeouts[username.toLowerCase()] = { until: Date.now()+dur, by: currentUser.username, reason };
|
| 1028 |
-
await DB.set('moderation', mod);
|
| 1029 |
-
const mins = Math.round(dur/60000);
|
| 1030 |
-
await sysMsg(`${username} wurde von ${currentUser.username} stummgeschaltet (${mins}min).${reason ? ' Grund: '+reason : ''}`);
|
| 1031 |
-
clearModal();
|
| 1032 |
-
showToast(`${username} stummgeschaltet`, 'var(--warn)');
|
| 1033 |
-
}
|
| 1034 |
-
|
| 1035 |
-
function openBanModal(username) {
|
| 1036 |
-
showModal(`
|
| 1037 |
-
<div class="modal-title" style="color:var(--danger)">🚫 Ban: ${escHtml(username)}</div>
|
| 1038 |
-
<div class="modal-sub">Permanenter Bann – Username + Browser-ID.</div>
|
| 1039 |
-
<div class="modal-field"><label>Grund</label><input type="text" id="m-reason" placeholder="Banngrund (Pflicht)"></div>
|
| 1040 |
-
<div class="modal-btns">
|
| 1041 |
-
<button class="modal-btn secondary" onclick="clearModal()">Abbrechen</button>
|
| 1042 |
-
<button class="modal-btn danger-btn" onclick="doBan('${escHtml(username)}')">BANNEN</button>
|
| 1043 |
-
</div>`);
|
| 1044 |
-
}
|
| 1045 |
-
|
| 1046 |
-
async function doBan(username) {
|
| 1047 |
-
const reason = document.getElementById('m-reason')?.value || '';
|
| 1048 |
-
if (!reason) { showToast('Bitte einen Grund angeben!', 'var(--danger)'); return; }
|
| 1049 |
-
const mod = (await DB.get('moderation')) || {};
|
| 1050 |
-
if (!mod.bans) mod.bans = {};
|
| 1051 |
-
mod.bans[username.toLowerCase()] = { by: currentUser.username, ts: Date.now(), reason };
|
| 1052 |
-
const fps = (await DB.get('user_fps')) || {};
|
| 1053 |
-
const targetFP = fps[username.toLowerCase()];
|
| 1054 |
-
if (targetFP) { if (!mod.banned_fps) mod.banned_fps = {}; mod.banned_fps[targetFP] = true; }
|
| 1055 |
-
await DB.set('moderation', mod);
|
| 1056 |
-
await sysMsg(`${username} wurde von ${currentUser.username} gebannt. Grund: ${reason}`);
|
| 1057 |
-
clearModal();
|
| 1058 |
-
showToast(`${username} gebannt`, 'var(--danger)');
|
| 1059 |
-
}
|
| 1060 |
-
|
| 1061 |
-
function openRoleModal(username) {
|
| 1062 |
-
showModal(`
|
| 1063 |
-
<div class="modal-title">🎖 Rolle: ${escHtml(username)}</div>
|
| 1064 |
-
<div class="modal-sub">Rolle des Users ändern.</div>
|
| 1065 |
-
<div class="modal-field"><label>Neue Rolle</label>
|
| 1066 |
-
<select id="m-role">
|
| 1067 |
-
<option value="member">Mitglied</option>
|
| 1068 |
-
<option value="vip">💎 VIP</option>
|
| 1069 |
-
<option value="mod">⭐ Moderator</option>
|
| 1070 |
-
${currentUser.role === 'owner' ? '<option value="admin">🔰 Admin</option>' : ''}
|
| 1071 |
-
</select></div>
|
| 1072 |
-
<div class="modal-btns">
|
| 1073 |
-
<button class="modal-btn secondary" onclick="clearModal()">Abbrechen</button>
|
| 1074 |
-
<button class="modal-btn primary" onclick="doSetRole('${escHtml(username)}')">Speichern</button>
|
| 1075 |
-
</div>`);
|
| 1076 |
-
}
|
| 1077 |
-
|
| 1078 |
-
async function doSetRole(username) {
|
| 1079 |
-
const newRole = document.getElementById('m-role').value;
|
| 1080 |
-
const users = (await DB.get('users')) || {};
|
| 1081 |
-
const target = users[username.toLowerCase()];
|
| 1082 |
-
if (!target) return clearModal();
|
| 1083 |
-
if (target.role === 'owner') { showToast('Owner-Rolle kann nicht geändert werden', 'var(--danger)'); return clearModal(); }
|
| 1084 |
-
if (currentUser.role !== 'owner' && ROLE_PRIORITY[target.role] >= ROLE_PRIORITY[currentUser.role]) {
|
| 1085 |
-
showToast('Keine Berechtigung', 'var(--danger)'); return clearModal();
|
| 1086 |
-
}
|
| 1087 |
-
target.role = newRole;
|
| 1088 |
-
users[username.toLowerCase()] = target;
|
| 1089 |
-
await DB.set('users', users);
|
| 1090 |
-
await sysMsg(`${username} → Rolle "${ROLE_LABELS[newRole]}" (vergeben von ${currentUser.username})`);
|
| 1091 |
-
clearModal();
|
| 1092 |
-
showToast(`${username} → ${ROLE_LABELS[newRole]}`, 'var(--green)');
|
| 1093 |
-
}
|
| 1094 |
-
|
| 1095 |
-
async function clearUserMsgs(username) {
|
| 1096 |
-
if (!hasRole('mod')) return;
|
| 1097 |
-
const msgs = (await DB.get(`msgs_${currentChannel}`)) || [];
|
| 1098 |
-
const filtered = msgs.filter(m => m.author !== username);
|
| 1099 |
-
await DB.set(`msgs_${currentChannel}`, filtered);
|
| 1100 |
-
await loadMessages(currentChannel);
|
| 1101 |
-
showToast(`Nachrichten von ${username} gelöscht`, 'var(--warn)');
|
| 1102 |
-
}
|
| 1103 |
-
|
| 1104 |
-
async function sysMsg(text) {
|
| 1105 |
-
if (!currentChannel) return;
|
| 1106 |
-
const msgs = (await DB.get(`msgs_${currentChannel}`)) || [];
|
| 1107 |
-
msgs.push({ system: true, text, ts: Date.now() });
|
| 1108 |
-
await DB.set(`msgs_${currentChannel}`, msgs);
|
| 1109 |
-
}
|
| 1110 |
-
|
| 1111 |
-
// ─── PROFILE MODAL ────────────────────────────────────────────
|
| 1112 |
-
async function showProfileModal(username) {
|
| 1113 |
-
const users = (await DB.get('users')) || {};
|
| 1114 |
-
const u = users[username.toLowerCase()];
|
| 1115 |
-
if (!u) return;
|
| 1116 |
-
const joined = new Date(u.joined || Date.now()).toLocaleDateString('de-DE');
|
| 1117 |
-
showModal(`
|
| 1118 |
-
<div class="modal-title">👤 ${escHtml(u.username)} ${ROLE_BADGE[u.role]||''}</div>
|
| 1119 |
-
<div class="modal-sub">Rolle: ${ROLE_LABELS[u.role]||'Mitglied'} · Beigetreten: ${joined}</div>
|
| 1120 |
-
<div class="modal-field" style="text-align:center">
|
| 1121 |
-
<div class="user-avatar-sm av-color-${u.color}" style="width:60px;height:60px;font-size:1.5rem;margin:0 auto 12px">${u.username[0].toUpperCase()}</div>
|
| 1122 |
-
</div>
|
| 1123 |
-
<div class="modal-btns">
|
| 1124 |
-
<button class="modal-btn secondary" onclick="clearModal()">Schließen</button>
|
| 1125 |
-
<button class="modal-btn primary" onclick="clearModal();openDM('${escHtml(u.username)}')">💬 DM senden</button>
|
| 1126 |
-
</div>`);
|
| 1127 |
-
}
|
| 1128 |
-
|
| 1129 |
-
// ─── SETTINGS MODAL ───────────────────────────────────────────
|
| 1130 |
-
function openSettings() {
|
| 1131 |
-
const s = currentUser.settings || {};
|
| 1132 |
-
showModal(`
|
| 1133 |
-
<div class="modal-title">⚙️ Einstellungen</div>
|
| 1134 |
-
<div class="modal-tabs">
|
| 1135 |
-
<button class="modal-tab active" onclick="switchSettingsTab('konto',this)">Konto</button>
|
| 1136 |
-
<button class="modal-tab" onclick="switchSettingsTab('darstellung',this)">Darstellung</button>
|
| 1137 |
-
${hasRole('mod') ? '<button class="modal-tab" onclick="switchSettingsTab(\'automod\',this)">AutoMod</button>' : ''}
|
| 1138 |
-
${hasRole('admin') ? '<button class="modal-tab" onclick="switchSettingsTab(\'tickets\',this)">Tickets</button>' : ''}
|
| 1139 |
-
</div>
|
| 1140 |
-
<div id="settings-tab-konto">
|
| 1141 |
-
<div class="settings-section">
|
| 1142 |
-
<h4>Konto</h4>
|
| 1143 |
-
<div class="modal-field"><label>Neuer Username</label><input type="text" id="s-username" placeholder="${escHtml(currentUser.username)}"></div>
|
| 1144 |
-
<div class="modal-field"><label>Neues Passwort</label><input type="password" id="s-pass" placeholder="Leer lassen = keine Änderung"></div>
|
| 1145 |
-
<div class="modal-field"><label>Passwort bestätigen</label><input type="password" id="s-pass2" placeholder="Passwort bestätigen"></div>
|
| 1146 |
-
</div>
|
| 1147 |
-
<div class="settings-section">
|
| 1148 |
-
<h4>Sprache & Übersetzung</h4>
|
| 1149 |
-
<div class="modal-field"><label>Sprache</label>
|
| 1150 |
-
<select id="s-lang">
|
| 1151 |
-
<option value="de" ${(s.lang||'de')==='de'?'selected':''}>🇩🇪 Deutsch</option>
|
| 1152 |
-
<option value="en" ${s.lang==='en'?'selected':''}>🇬🇧 English</option>
|
| 1153 |
-
</select></div>
|
| 1154 |
-
<div class="toggle-row">
|
| 1155 |
-
<label>Auto-Übersetzung aktivieren</label>
|
| 1156 |
-
<div class="toggle ${s.translate?'on':''}" id="toggle-translate" onclick="toggleSettingsToggle('translate')"></div>
|
| 1157 |
-
</div>
|
| 1158 |
-
</div>
|
| 1159 |
-
<div class="settings-section">
|
| 1160 |
-
<h4>Benachrichtigungen</h4>
|
| 1161 |
-
<div class="toggle-row">
|
| 1162 |
-
<label>DM-Benachrichtigungen</label>
|
| 1163 |
-
<div class="toggle ${s.notif!==false?'on':''}" id="toggle-notif" onclick="toggleSettingsToggle('notif')"></div>
|
| 1164 |
-
</div>
|
| 1165 |
-
</div>
|
| 1166 |
-
</div>
|
| 1167 |
-
<div id="settings-tab-darstellung" style="display:none">
|
| 1168 |
-
<div class="settings-section">
|
| 1169 |
-
<h4>Avatar-Farbe</h4>
|
| 1170 |
-
<div style="display:flex;gap:10px;margin-bottom:14px">
|
| 1171 |
-
${[0,1,2,3,4].map(i=>`<div class="user-avatar-sm av-color-${i}" style="width:36px;height:36px;cursor:pointer;border-width:2px${currentUser.color===i?';box-shadow:0 0 10px':''}" onclick="setAvatarColor(${i})">${currentUser.username[0].toUpperCase()}</div>`).join('')}
|
| 1172 |
-
</div>
|
| 1173 |
-
</div>
|
| 1174 |
-
</div>
|
| 1175 |
-
${hasRole('mod') ? `<div id="settings-tab-automod" style="display:none">
|
| 1176 |
-
<div class="settings-section">
|
| 1177 |
-
<h4>AutoMod Einstellungen</h4>
|
| 1178 |
-
<div class="toggle-row"><label>AutoMod aktiv</label><div class="toggle ${appConfig.automod?.enabled?'on':''}" id="toggle-am-enabled" onclick="toggleSettingsToggle('am-enabled')"></div></div>
|
| 1179 |
-
<div class="modal-field"><label>Max. Nachrichtenlänge</label><input type="number" id="s-maxlen" value="${appConfig.automod?.maxMsgLength||800}" min="50" max="2000"></div>
|
| 1180 |
-
<div class="modal-field"><label>Spam-Grenze (Nachrichten/10s)</label><input type="number" id="s-spam" value="${appConfig.automod?.spamThreshold||5}" min="3" max="20"></div>
|
| 1181 |
-
<div class="modal-field">
|
| 1182 |
-
<label>Verbotene Wörter</label>
|
| 1183 |
-
<div id="banned-words-tags">${(appConfig.automod?.bannedWords||[]).map(w=>`<span class="tag">${escHtml(w)}<button class="tag-remove" onclick="removeTag('${escHtml(w)}')">×</button></span>`).join('')}</div>
|
| 1184 |
-
<div style="display:flex;gap:6px;margin-top:6px">
|
| 1185 |
-
<input class="tag-input" type="text" id="new-bw" placeholder="Wort hinzufügen" style="flex:1">
|
| 1186 |
-
<button class="modal-btn primary" style="flex:none;width:auto;padding:5px 12px;font-size:.7rem" onclick="addBannedWord()">+</button>
|
| 1187 |
-
</div>
|
| 1188 |
-
</div>
|
| 1189 |
-
<div class="toggle-row"><label>Caps-Filter</label><div class="toggle ${appConfig.automod?.capsFilter?'on':''}" id="toggle-caps" onclick="toggleSettingsToggle('caps')"></div></div>
|
| 1190 |
-
<div class="toggle-row"><label>Link-Filter</label><div class="toggle ${appConfig.automod?.linkFilter?'on':''}" id="toggle-links" onclick="toggleSettingsToggle('links')"></div></div>
|
| 1191 |
-
</div>
|
| 1192 |
-
</div>` : ''}
|
| 1193 |
-
${hasRole('admin') ? `<div id="settings-tab-tickets" style="display:none">
|
| 1194 |
-
<div class="settings-section">
|
| 1195 |
-
<h4>Ticket-System</h4>
|
| 1196 |
-
<div id="admin-tickets-list">Wird geladen...</div>
|
| 1197 |
-
</div>
|
| 1198 |
-
</div>` : ''}
|
| 1199 |
-
<div class="modal-btns">
|
| 1200 |
-
<button class="modal-btn secondary" onclick="clearModal()">Schließen</button>
|
| 1201 |
-
<button class="modal-btn primary" onclick="saveSettings()">Speichern</button>
|
| 1202 |
-
</div>`, true);
|
| 1203 |
-
|
| 1204 |
-
// Load tickets if admin tab visible
|
| 1205 |
-
if (hasRole('admin')) setTimeout(() => loadAdminTickets(), 100);
|
| 1206 |
-
}
|
| 1207 |
-
|
| 1208 |
-
const _settingsToggles = {};
|
| 1209 |
-
function toggleSettingsToggle(id) {
|
| 1210 |
-
const el = document.getElementById('toggle-' + id);
|
| 1211 |
-
if (!el) return;
|
| 1212 |
-
const on = !el.classList.contains('on');
|
| 1213 |
-
el.classList.toggle('on', on);
|
| 1214 |
-
_settingsToggles[id] = on;
|
| 1215 |
-
}
|
| 1216 |
-
|
| 1217 |
-
function switchSettingsTab(tab, btn) {
|
| 1218 |
-
document.querySelectorAll('[id^="settings-tab-"]').forEach(el => el.style.display = 'none');
|
| 1219 |
-
document.querySelectorAll('.modal-tab').forEach(el => el.classList.remove('active'));
|
| 1220 |
-
const tabEl = document.getElementById('settings-tab-' + tab);
|
| 1221 |
-
if (tabEl) tabEl.style.display = '';
|
| 1222 |
-
if (btn) btn.classList.add('active');
|
| 1223 |
-
if (tab === 'tickets') loadAdminTickets();
|
| 1224 |
-
}
|
| 1225 |
-
|
| 1226 |
-
function addBannedWord() {
|
| 1227 |
-
const input = document.getElementById('new-bw');
|
| 1228 |
-
const word = input.value.trim().toLowerCase();
|
| 1229 |
-
if (!word) return;
|
| 1230 |
-
if (!appConfig.automod) appConfig.automod = {};
|
| 1231 |
-
if (!appConfig.automod.bannedWords) appConfig.automod.bannedWords = [];
|
| 1232 |
-
if (!appConfig.automod.bannedWords.includes(word)) {
|
| 1233 |
-
appConfig.automod.bannedWords.push(word);
|
| 1234 |
-
const tags = document.getElementById('banned-words-tags');
|
| 1235 |
-
tags.insertAdjacentHTML('beforeend', `<span class="tag">${escHtml(word)}<button class="tag-remove" onclick="removeTag('${escHtml(word)}')">×</button></span>`);
|
| 1236 |
-
}
|
| 1237 |
-
input.value = '';
|
| 1238 |
-
}
|
| 1239 |
-
|
| 1240 |
-
function removeTag(word) {
|
| 1241 |
-
if (!appConfig.automod?.bannedWords) return;
|
| 1242 |
-
appConfig.automod.bannedWords = appConfig.automod.bannedWords.filter(w => w !== word);
|
| 1243 |
-
// Re-render tags
|
| 1244 |
-
const tags = document.getElementById('banned-words-tags');
|
| 1245 |
-
if (tags) tags.innerHTML = appConfig.automod.bannedWords.map(w =>
|
| 1246 |
-
`<span class="tag">${escHtml(w)}<button class="tag-remove" onclick="removeTag('${escHtml(w)}')">×</button></span>`).join('');
|
| 1247 |
-
}
|
| 1248 |
-
|
| 1249 |
-
async function setAvatarColor(color) {
|
| 1250 |
-
currentUser.color = color;
|
| 1251 |
-
const users = (await DB.get('users')) || {};
|
| 1252 |
-
if (users[currentUser.username.toLowerCase()]) {
|
| 1253 |
-
users[currentUser.username.toLowerCase()].color = color;
|
| 1254 |
-
await DB.set('users', users);
|
| 1255 |
-
}
|
| 1256 |
-
updateTopbar();
|
| 1257 |
-
}
|
| 1258 |
-
|
| 1259 |
-
async function saveSettings() {
|
| 1260 |
-
const users = (await DB.get('users')) || {};
|
| 1261 |
-
const me = users[currentUser.username.toLowerCase()];
|
| 1262 |
-
if (!me) return clearModal();
|
| 1263 |
-
|
| 1264 |
-
// Username change
|
| 1265 |
-
const newUser = document.getElementById('s-username')?.value.trim();
|
| 1266 |
-
if (newUser && newUser !== currentUser.username) {
|
| 1267 |
-
if (newUser.length < 2 || newUser.length > 20) { showToast('Username: 2-20 Zeichen', 'var(--danger)'); return; }
|
| 1268 |
-
if (!/^[a-zA-Z0-9_]+$/.test(newUser)) { showToast('Nur Buchstaben, Zahlen, _', 'var(--danger)'); return; }
|
| 1269 |
-
if (users[newUser.toLowerCase()] && newUser.toLowerCase() !== currentUser.username.toLowerCase()) {
|
| 1270 |
-
showToast('Username bereits vergeben', 'var(--danger)'); return;
|
| 1271 |
-
}
|
| 1272 |
-
// Move user entry
|
| 1273 |
-
delete users[currentUser.username.toLowerCase()];
|
| 1274 |
-
me.username = newUser;
|
| 1275 |
-
users[newUser.toLowerCase()] = me;
|
| 1276 |
-
currentUser.username = newUser;
|
| 1277 |
-
}
|
| 1278 |
-
|
| 1279 |
-
// Password change
|
| 1280 |
-
const newPass = document.getElementById('s-pass')?.value;
|
| 1281 |
-
const newPass2 = document.getElementById('s-pass2')?.value;
|
| 1282 |
-
if (newPass) {
|
| 1283 |
-
if (newPass.length < 4) { showToast('Passwort mind. 4 Zeichen', 'var(--danger)'); return; }
|
| 1284 |
-
if (newPass !== newPass2) { showToast('Passwörter stimmen nicht überein', 'var(--danger)'); return; }
|
| 1285 |
-
me.password = encode(newPass);
|
| 1286 |
-
}
|
| 1287 |
-
|
| 1288 |
-
// Settings
|
| 1289 |
-
if (!me.settings) me.settings = {};
|
| 1290 |
-
const langEl = document.getElementById('s-lang');
|
| 1291 |
-
if (langEl) me.settings.lang = langEl.value;
|
| 1292 |
-
if ('translate' in _settingsToggles) me.settings.translate = _settingsToggles.translate;
|
| 1293 |
-
if ('notif' in _settingsToggles) me.settings.notif = _settingsToggles.notif;
|
| 1294 |
-
|
| 1295 |
-
users[me.username.toLowerCase()] = me;
|
| 1296 |
-
await DB.set('users', users);
|
| 1297 |
-
|
| 1298 |
-
// AutoMod save
|
| 1299 |
-
if (hasRole('mod') && appConfig.automod) {
|
| 1300 |
-
const maxlen = document.getElementById('s-maxlen');
|
| 1301 |
-
const spam = document.getElementById('s-spam');
|
| 1302 |
-
if (maxlen) appConfig.automod.maxMsgLength = parseInt(maxlen.value) || 800;
|
| 1303 |
-
if (spam) appConfig.automod.spamThreshold = parseInt(spam.value) || 5;
|
| 1304 |
-
if ('am-enabled' in _settingsToggles) appConfig.automod.enabled = _settingsToggles['am-enabled'];
|
| 1305 |
-
if ('caps' in _settingsToggles) appConfig.automod.capsFilter = _settingsToggles.caps;
|
| 1306 |
-
if ('links' in _settingsToggles) appConfig.automod.linkFilter = _settingsToggles.links;
|
| 1307 |
-
await DB.set('config', appConfig);
|
| 1308 |
-
}
|
| 1309 |
-
|
| 1310 |
-
currentUser = { ...me };
|
| 1311 |
-
userLanguage = me.settings.lang || 'de';
|
| 1312 |
-
translationEnabled = me.settings.translate || false;
|
| 1313 |
-
updateTopbar();
|
| 1314 |
-
clearModal();
|
| 1315 |
-
showToast('✓ Einstellungen gespeichert', 'var(--green)');
|
| 1316 |
-
}
|
| 1317 |
-
|
| 1318 |
-
// ─── TICKET SYSTEM ────────────────────────────────────────────
|
| 1319 |
-
async function openCreateTicket() {
|
| 1320 |
-
showModal(`
|
| 1321 |
-
<div class="modal-title">🎫 Ticket erstellen</div>
|
| 1322 |
-
<div class="modal-sub">Wende dich an das Team – wir helfen gerne!</div>
|
| 1323 |
-
<div class="modal-field"><label>Kategorie</label>
|
| 1324 |
-
<select id="t-cat">
|
| 1325 |
-
<option value="support">❓ Support</option>
|
| 1326 |
-
<option value="report">🚨 Meldung</option>
|
| 1327 |
-
<option value="appeal">⚖️ Ban-Appeal</option>
|
| 1328 |
-
<option value="other">💭 Sonstiges</option>
|
| 1329 |
-
</select></div>
|
| 1330 |
-
<div class="modal-field"><label>Betreff</label><input type="text" id="t-title" placeholder="Kurze Zusammenfassung" maxlength="80"></div>
|
| 1331 |
-
<div class="modal-field"><label>Beschreibung</label><textarea id="t-desc" placeholder="Beschreibe dein Anliegen ausführlich..." rows="4"></textarea></div>
|
| 1332 |
-
<div class="modal-btns">
|
| 1333 |
-
<button class="modal-btn secondary" onclick="clearModal()">Abbrechen</button>
|
| 1334 |
-
<button class="modal-btn primary" onclick="submitTicket()">Ticket erstellen</button>
|
| 1335 |
-
</div>`);
|
| 1336 |
-
}
|
| 1337 |
-
|
| 1338 |
-
async function submitTicket() {
|
| 1339 |
-
const cat = document.getElementById('t-cat')?.value;
|
| 1340 |
-
const title = document.getElementById('t-title')?.value.trim();
|
| 1341 |
-
const desc = document.getElementById('t-desc')?.value.trim();
|
| 1342 |
-
if (!title || !desc) { showToast('Bitte alle Felder ausfüllen', 'var(--danger)'); return; }
|
| 1343 |
-
|
| 1344 |
-
const tickets = (await DB.get('tickets')) || [];
|
| 1345 |
-
const id = 'TKT-' + String(Date.now()).slice(-5);
|
| 1346 |
-
tickets.push({
|
| 1347 |
-
id, cat, title, desc,
|
| 1348 |
-
author: currentUser.username,
|
| 1349 |
-
status: 'open',
|
| 1350 |
-
ts: Date.now(),
|
| 1351 |
-
messages: []
|
| 1352 |
-
});
|
| 1353 |
-
await DB.set('tickets', tickets);
|
| 1354 |
-
clearModal();
|
| 1355 |
-
showToast(`🎫 Ticket ${id} erstellt`, 'var(--green)');
|
| 1356 |
-
}
|
| 1357 |
-
|
| 1358 |
-
async function loadAdminTickets() {
|
| 1359 |
-
const el = document.getElementById('admin-tickets-list');
|
| 1360 |
-
if (!el) return;
|
| 1361 |
-
const tickets = (await DB.get('tickets')) || [];
|
| 1362 |
-
if (!tickets.length) { el.innerHTML = '<div style="color:var(--muted);font-size:.85rem;text-align:center;padding:20px">Keine Tickets</div>'; return; }
|
| 1363 |
-
|
| 1364 |
-
el.innerHTML = tickets.slice().reverse().map(t => `
|
| 1365 |
-
<div class="ticket-item ${t.status}" onclick="openTicketDetail('${t.id}')">
|
| 1366 |
-
<div class="ticket-meta">${t.id} · ${t.cat} · ${new Date(t.ts).toLocaleDateString('de-DE')} · ${t.author}</div>
|
| 1367 |
-
<div class="ticket-title">${escHtml(t.title)}</div>
|
| 1368 |
-
<div style="font-size:.75rem;color:${t.status==='open'?'var(--green)':'var(--muted)'}">● ${t.status === 'open' ? 'Offen' : 'Geschlossen'}</div>
|
| 1369 |
-
</div>`).join('');
|
| 1370 |
-
}
|
| 1371 |
-
|
| 1372 |
-
async function openTicketDetail(id) {
|
| 1373 |
-
const tickets = (await DB.get('tickets')) || [];
|
| 1374 |
-
const t = tickets.find(t => t.id === id);
|
| 1375 |
-
if (!t) return;
|
| 1376 |
-
showModal(`
|
| 1377 |
-
<div class="modal-title">🎫 ${escHtml(t.id)}: ${escHtml(t.title)}</div>
|
| 1378 |
-
<div class="modal-sub">Von ${escHtml(t.author)} · ${new Date(t.ts).toLocaleDateString('de-DE')} · Status: ${t.status}</div>
|
| 1379 |
-
<div style="background:rgba(0,0,0,0.3);padding:12px;border:1px solid var(--border);font-size:.9rem;margin-bottom:14px;border-radius:2px">${escHtml(t.desc)}</div>
|
| 1380 |
-
${hasRole('mod') ? `<div class="modal-btns">
|
| 1381 |
-
<button class="modal-btn secondary" onclick="clearModal()">Schließen</button>
|
| 1382 |
-
<button class="modal-btn ${t.status==='open'?'danger-btn':'success-btn'}" onclick="toggleTicket('${id}')">
|
| 1383 |
-
${t.status === 'open' ? 'Ticket schließen' : 'Ticket öffnen'}
|
| 1384 |
-
</button>
|
| 1385 |
-
</div>` : `<div class="modal-btns"><button class="modal-btn secondary" onclick="clearModal()">Schließen</button></div>`}`, true);
|
| 1386 |
-
}
|
| 1387 |
-
|
| 1388 |
-
async function toggleTicket(id) {
|
| 1389 |
-
const tickets = (await DB.get('tickets')) || [];
|
| 1390 |
-
const t = tickets.find(t => t.id === id);
|
| 1391 |
-
if (!t) return;
|
| 1392 |
-
t.status = t.status === 'open' ? 'closed' : 'open';
|
| 1393 |
-
await DB.set('tickets', tickets);
|
| 1394 |
-
clearModal();
|
| 1395 |
-
showToast(`Ticket ${id} ${t.status === 'open' ? 'geöffnet' : 'geschlossen'}`, 'var(--accent)');
|
| 1396 |
-
}
|
| 1397 |
-
|
| 1398 |
-
// ─── SPAM CAPTCHA ─────────────────────────────────────────────
|
| 1399 |
-
function showSpamCaptchaModal() {
|
| 1400 |
-
const d = genCaptcha();
|
| 1401 |
-
captchaData.spam = d;
|
| 1402 |
-
showModal(`
|
| 1403 |
-
<div class="modal-title">🤖 Anti-Spam Prüfung</div>
|
| 1404 |
-
<div class="modal-sub">Du schreibst zu schnell. Löse das Captcha um fortzufahren.</div>
|
| 1405 |
-
<div class="captcha-modal-question" id="spam-q">${d.q}</div>
|
| 1406 |
-
<div class="modal-field"><label>Antwort</label><input type="number" id="spam-a" placeholder="?" onkeydown="if(event.key==='Enter')spamSubmit()"></div>
|
| 1407 |
-
<div class="auth-error" id="spam-err"></div>
|
| 1408 |
-
<div class="modal-btns">
|
| 1409 |
-
<button class="modal-btn secondary" onclick="clearModal()">Abbrechen</button>
|
| 1410 |
-
<button class="modal-btn primary" onclick="spamSubmit()">Bestätigen</button>
|
| 1411 |
-
</div>`);
|
| 1412 |
-
}
|
| 1413 |
-
|
| 1414 |
-
async function spamSubmit() {
|
| 1415 |
-
const ans = parseInt(document.getElementById('spam-a')?.value);
|
| 1416 |
-
if (ans !== captchaData.spam?.ans) {
|
| 1417 |
-
const d = genCaptcha();
|
| 1418 |
-
captchaData.spam = d;
|
| 1419 |
-
const qEl = document.getElementById('spam-q');
|
| 1420 |
-
if (qEl) qEl.textContent = d.q;
|
| 1421 |
-
const errEl = document.getElementById('spam-err');
|
| 1422 |
-
if (errEl) errEl.textContent = '❌ Falsche Antwort!';
|
| 1423 |
-
return;
|
| 1424 |
-
}
|
| 1425 |
-
clearModal();
|
| 1426 |
-
spamTs = [];
|
| 1427 |
-
if (pendingSpamMsg) { await _sendMsg(pendingSpamMsg); pendingSpamMsg = null; }
|
| 1428 |
-
}
|
| 1429 |
-
|
| 1430 |
-
// ─── MODAL SYSTEM ─────────────────────────────────────────────
|
| 1431 |
-
function showModal(html, wide = false) {
|
| 1432 |
-
clearModal();
|
| 1433 |
-
const overlay = document.createElement('div');
|
| 1434 |
-
overlay.className = 'modal-overlay';
|
| 1435 |
-
overlay.id = 'active-modal';
|
| 1436 |
-
overlay.innerHTML = `<div class="modal${wide?' wide':''}">${html}</div>`;
|
| 1437 |
-
overlay.onclick = e => { if (e.target === overlay) clearModal(); };
|
| 1438 |
-
document.getElementById('modal-container').appendChild(overlay);
|
| 1439 |
-
}
|
| 1440 |
-
|
| 1441 |
-
function clearModal() {
|
| 1442 |
-
document.getElementById('active-modal')?.remove();
|
| 1443 |
-
}
|
| 1444 |
-
|
| 1445 |
-
function showKickedModal() {
|
| 1446 |
-
showModal(`
|
| 1447 |
-
<div class="modal-title">👢 Du wurdest gekickt</div>
|
| 1448 |
-
<div class="modal-sub">Ein Moderator hat dich aus dem Chat entfernt. Du kannst dich erneut einloggen.</div>
|
| 1449 |
-
<div class="modal-btns">
|
| 1450 |
-
<button class="modal-btn primary" onclick="doLogout();clearModal()">Zum Login</button>
|
| 1451 |
-
</div>`);
|
| 1452 |
-
}
|
| 1453 |
-
|
| 1454 |
-
// ─── HELPERS ──────────────────────────────────────────────────
|
| 1455 |
-
function encode(s) { try { return btoa(unescape(encodeURIComponent(s))); } catch { return btoa(s); } }
|
| 1456 |
-
function decode(s) { try { return decodeURIComponent(escape(atob(s))); } catch { try { return atob(s); } catch { return ''; } } }
|
| 1457 |
-
|
| 1458 |
-
function escHtml(str) {
|
| 1459 |
-
return String(str || '')
|
| 1460 |
-
.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')
|
| 1461 |
-
.replace(/"/g,'"').replace(/'/g,''');
|
| 1462 |
-
}
|
| 1463 |
-
|
| 1464 |
-
function showBanned() {
|
| 1465 |
-
document.getElementById('banned-screen').style.display = 'flex';
|
| 1466 |
-
document.getElementById('auth-screen').style.display = 'none';
|
| 1467 |
-
document.getElementById('app').classList.remove('visible');
|
| 1468 |
-
}
|
| 1469 |
-
|
| 1470 |
-
function showAuthSuccess(msg) {
|
| 1471 |
-
const el = document.getElementById('auth-error');
|
| 1472 |
-
el.style.color = 'var(--green)';
|
| 1473 |
-
el.textContent = msg;
|
| 1474 |
-
setTimeout(() => { el.style.color = ''; el.textContent = ''; }, 3000);
|
| 1475 |
-
}
|
| 1476 |
-
|
| 1477 |
-
function showToast(msg, color = 'var(--accent)') {
|
| 1478 |
-
const t = document.createElement('div');
|
| 1479 |
-
t.className = 'toast';
|
| 1480 |
-
t.style.borderColor = color;
|
| 1481 |
-
t.style.color = color;
|
| 1482 |
-
t.textContent = msg;
|
| 1483 |
-
document.body.appendChild(t);
|
| 1484 |
-
setTimeout(() => t.remove(), 3000);
|
| 1485 |
-
}
|
| 1486 |
-
|
| 1487 |
-
// ─── INIT ─────────────────────────────────────────────────────
|
| 1488 |
-
(async function init() {
|
| 1489 |
-
refreshCaptcha('login');
|
| 1490 |
-
refreshCaptcha('reg');
|
| 1491 |
-
|
| 1492 |
-
// Check fp ban
|
| 1493 |
-
const mod = (await DB.get('moderation')) || {};
|
| 1494 |
-
if (mod.banned_fps?.[MY_FP]) { showBanned(); return; }
|
| 1495 |
-
|
| 1496 |
-
// Ensure owner exists
|
| 1497 |
-
const users = (await DB.get('users')) || {};
|
| 1498 |
-
const ownerKey = OWNER_NAME.toLowerCase();
|
| 1499 |
-
if (!users[ownerKey]) {
|
| 1500 |
-
users[ownerKey] = {
|
| 1501 |
-
username: OWNER_NAME, password: encode(OWNER_PASS),
|
| 1502 |
-
color: 1, role: 'owner', joined: Date.now(),
|
| 1503 |
-
settings: { lang: 'de', translate: false, notif: true }
|
| 1504 |
-
};
|
| 1505 |
-
await DB.set('users', users);
|
| 1506 |
-
} else {
|
| 1507 |
-
users[ownerKey].role = 'owner'; // always
|
| 1508 |
-
await DB.set('users', users);
|
| 1509 |
-
}
|
| 1510 |
-
|
| 1511 |
-
// Load config
|
| 1512 |
-
let cfg = (await DB.get('config')) || {};
|
| 1513 |
-
if (!cfg.channels) {
|
| 1514 |
-
cfg.channels = window.DEFAULT_CHANNELS;
|
| 1515 |
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