/* ================================ Eigene Benachrichtigung ================================ */ function showNotification(message, title = "Hinweis", icon = "⚔️") { const overlay = document.getElementById("game-notification-overlay"); const notification = document.getElementById("game-notification"); const msgEl = document.getElementById("notification-message"); const titleEl = document.getElementById("notification-title"); const iconEl = document.getElementById("notification-icon"); const okBtn = document.getElementById("notification-ok"); msgEl.innerText = message; titleEl.innerText = title; iconEl.innerText = icon; overlay.classList.add("show"); notification.style.display = "block"; requestAnimationFrame(() => { notification.classList.add("show"); }); okBtn.onclick = () => { notification.classList.remove("show"); overlay.classList.remove("show"); setTimeout(() => { notification.style.display = "none"; }, 200); }; } export async function loadSchwarzmarkt() { const ui = document.querySelector(".building-ui"); ui.innerHTML = `

Erweitere deinen Taschenplatz indem du zusätzliche Taschen freischaltest

⚗️ Noch keine Artefakte verfügbar

🤫 Schwarzmarkt Angebote folgen bald...

`; loadPages(); initMarketTabs(); } async function loadPages() { try { const res = await fetch("/api/blackmarket/pages"); if (!res.ok) throw new Error("API Fehler"); const data = await res.json(); const container = document.getElementById("market-pages"); let html = ""; for (let i = 1; i <= data.maxPages; i++) { const price = data.prices.find((p) => p.page === i); if (data.ownedPages.includes(i)) { html += `
Beutel ${i}
`; } else if (price) { html += `
Beutel ${i}
${price.price} 🪙
`; } else { html += `
Beutel ${i}
🔒
`; } } container.innerHTML = html; } catch (err) { console.error("Schwarzmarkt Fehler:", err); } } /* Kaufen */ document.addEventListener("click", async (e) => { const button = e.target.closest(".buy-button"); if (!button) return; const slot = button.closest(".market-slot"); const page = slot.dataset.page; try { const res = await fetch("/api/blackmarket/buy-page", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ page }), }); if (!res.ok) throw new Error("API Fehler"); const data = await res.json(); if (data.error) { if (data.missing) { showNotification( `Du hast ${data.gold} 🪙 Gold.\nDu brauchst ${data.price} 🪙 Gold.\nEs fehlen dir noch ${data.missing} 🪙 Gold.`, "Nicht genug Gold", "🪙", ); } else { showNotification(data.error, "Hinweis", "⚠️"); } return; } loadPages(); } catch (err) { console.error("Kauf Fehler:", err); showNotification( "Fehler beim Kauf. Bitte erneut versuchen.", "Fehler", "⚠️", ); } }); /* Tabs */ function initMarketTabs() { document.querySelectorAll(".market-tab").forEach((tab) => { tab.addEventListener("click", () => { document .querySelectorAll(".market-tab") .forEach((t) => t.classList.remove("active")); tab.classList.add("active"); document .querySelectorAll(".market-tab-content") .forEach((c) => c.classList.remove("active")); document .getElementById("market-" + tab.dataset.tab) .classList.add("active"); }); }); }