2025-12-19 00:54:35 +07:00

66 lines
2.0 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
// --- 1. LOGIKA MUSIK (FIXED) ---
const musicBtn = document.getElementById('musicBtn');
const bgMusic = document.getElementById('bgMusic');
if (musicBtn && bgMusic) {
// Cek status awal: Kalau lagu pause, icon harus mute
if (bgMusic.paused) {
musicBtn.textContent = '🔇';
} else {
musicBtn.textContent = '🔊';
}
musicBtn.addEventListener('click', () => {
if (bgMusic.paused) {
// Kalau lagi mati, nyalakan
bgMusic.play().then(() => {
musicBtn.textContent = '🔊';
}).catch((e) => {
console.log("Browser memblokir audio:", e);
});
} else {
// Kalau lagi nyala, matikan
bgMusic.pause();
musicBtn.textContent = '🔇';
}
});
} else {
console.error("Element Audio/Tombol tidak ditemukan!");
}
// --- 2. LOGOUT ---
const logoutBtn = document.getElementById("logoutBtn");
if (logoutBtn) {
logoutBtn.addEventListener("click", () => {
window.location.href = "logout.php";
});
}
// --- 3. LEADERBOARD ---
const leaderboardBtn = document.getElementById("leaderboardBtn");
if (leaderboardBtn) {
leaderboardBtn.addEventListener("click", () => {
window.location.href = "Leaderboard.php";
});
}
});
// --- FUNGSI GLOBAL (Bisa dipanggil dari onclick HTML) ---
// NAVIGATION
function selectStage(stage) {
console.log("Pindah ke stage:", stage); // Debugging
window.location.href = "gameboard-" + stage + ".php";
}
// OVERLAY CREDITS
function openCredits() {
const overlay = document.getElementById('creditsOverlay');
if(overlay) overlay.style.display = 'flex';
}
function closeCredits() {
const overlay = document.getElementById('creditsOverlay');
if(overlay) overlay.style.display = 'none';
}