diff --git a/BungeeCord-Chrome/popup.js b/BungeeCord-Chrome/popup.js index edda474..0074620 100644 --- a/BungeeCord-Chrome/popup.js +++ b/BungeeCord-Chrome/popup.js @@ -7,6 +7,7 @@ let selectedId = null; let statuses = {}; let previousStatuses = {}; let settingsVisible = false; +let editingId = null; // Welcher Server gerade bearbeitet wird document.addEventListener('DOMContentLoaded', init); $('btnAdd')?.addEventListener('click', handleAdd); @@ -200,7 +201,6 @@ function updateDetailForServer(srv, force = false) { const ping = d.ping || d.latency; $('detailPing').textContent = typeof ping === 'number' ? ping + ' ms' : '-'; - // MOTD const motdRaw = d.motd || (d.network && d.network.motd) || ''; if (motdRaw) { const motdEl = $('motdBar'); @@ -251,8 +251,6 @@ function updateBackendServers(list) { } // ── Player list ── -// Versucht den Server-Namen aus den Daten zu lesen. -// Wenn dein Plugin "server" im Spieler-Objekt mitgibt, wird es als Tag angezeigt. function updatePlayerList(players) { const grid = $('detailPlayerList'); grid.innerHTML = ''; @@ -272,7 +270,6 @@ function updatePlayerList(players) { name = p.name || p.username || p.player || ''; uuid = p.uuid || null; prefix = p.prefix || p.group || ''; - // Mögliche Felder: server, current_server, connected_server serverName = p.server || p.current_server || p.connected_server || null; } else { name = String(p); @@ -333,29 +330,77 @@ function updateServerListStatuses() { }); } +// ── Edit / Add Mode ── +function enterEditMode(server) { + editingId = server.id; + $('settingsTitle').textContent = 'Server bearbeiten'; + $('btnAddServer').textContent = 'Änderungen speichern'; + + $('inputName').value = server.name || ''; + $('inputUrl').value = server.url || ''; + $('inputWpSite').value = server.wpSite || ''; + $('inputWpServerId').value = server.wpServerId || ''; +} + +function exitEditMode() { + editingId = null; + $('settingsTitle').textContent = 'Neuen Server hinzufügen'; + $('btnAddServer').textContent = 'Hinzufügen'; + $('inputName').value = ''; + $('inputUrl').value = ''; + $('inputWpSite').value = ''; + $('inputWpServerId').value = ''; +} + // ── Actions ── async function handleAdd() { const name = $('inputName').value.trim(); const url = $('inputUrl').value.trim(); const wpSite = $('inputWpSite').value.trim(); const wpServerId = $('inputWpServerId').value.trim(); - if (!url && !wpSite) return; - const s = { id: uid(), name: name || url || wpSite, url: url || null, wpSite: wpSite || null, wpServerId: wpServerId || null }; - servers.push(s); + + if (!url && !wpSite) { + alert('Bitte eine URL oder WordPress-Einstellungen angeben.'); + return; + } + + if (editingId) { + // === BEARBEITEN === + const srv = servers.find(s => s.id === editingId); + if (srv) { + srv.name = name || url || wpSite; + if (url) srv.url = url; + if (wpSite) srv.wpSite = wpSite; + if (wpServerId) srv.wpServerId = wpServerId; + } + exitEditMode(); + } else { + // === NEU HINZUFÜGEN === + const s = { + id: uid(), + name: name || url || wpSite, + url: url || null, + wpSite: wpSite || null, + wpServerId: wpServerId || null + }; + servers.push(s); + } + await saveServersToStorage(); - $('inputName').value = $('inputUrl').value = $('inputWpSite').value = $('inputWpServerId').value = ''; renderServerList(); + if (selectedId) renderDetail(selectedId); } async function handleEdit() { if (!selectedId) return; const srv = servers.find(s => s.id === selectedId); if (!srv) return; - const newName = prompt('Name:', srv.name); - if (newName !== null) srv.name = newName.trim(); - await saveServersToStorage(); - renderServerList(); - renderDetail(selectedId); + + settingsVisible = true; + applySettingsVisibility(); + await saveSettingsVisibility(); + + enterEditMode(srv); } async function handleDelete() { @@ -365,6 +410,7 @@ async function handleDelete() { await saveServersToStorage(); renderServerList(); renderDetail(null); + exitEditMode(); } async function manualRefresh() { @@ -381,4 +427,4 @@ chrome.storage.onChanged.addListener((changes, area) => { if (srv) updateDetailForServer(srv); } } -}); +}); \ No newline at end of file