From 75fc3c4a56f5e0f66b5730f551dc4e956d8ff24b Mon Sep 17 00:00:00 2001 From: ody Date: Mon, 24 Nov 2025 14:37:12 +0700 Subject: [PATCH] js top up --- ody git.js | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/ody git.js b/ody git.js index 241e76e..4ad2143 100644 --- a/ody git.js +++ b/ody git.js @@ -235,3 +235,154 @@ window.addEventListener('keydown', e=>{ }); updateUI(); + +// Tambahkan variabel global untuk top up +let topUpAmount = 0; +let topUpHistory = []; + +// DOM elements untuk top up +const topUpBtn = document.getElementById('top-up-btn'); +const topUpModal = document.getElementById('top-up-modal'); +const topUpClose = document.getElementById('top-up-close'); +const topUpInput = document.getElementById('top-up-input'); +const topUpConfirm = document.getElementById('top-up-confirm'); +const topUpHistoryEl = document.getElementById('top-up-history'); +const topUpBalanceEl = document.getElementById('top-up-balance'); + +// Fungsi untuk menampilkan modal top up +function showTopUpModal() { + topUpModal.style.display = 'block'; + topUpInput.value = ''; + updateTopUpHistory(); +} + +// Fungsi untuk menyembunyikan modal top up +function hideTopUpModal() { + topUpModal.style.display = 'none'; +} + +// Fungsi untuk memproses top up +function processTopUp() { + const amount = Number(topUpInput.value) || 0; + + if (amount <= 0) { + alert('Masukkan jumlah top up yang valid!'); + return; + } + + if (amount > 1000000) { + alert('Maksimal top up adalah 1.000.000!'); + return; + } + + // Simulasi proses top up (dalam implementasi nyata, ini akan terhubung ke payment gateway) + balance += amount; + topUpAmount += amount; + + // Tambahkan ke riwayat top up + topUpHistory.push({ + amount: amount, + date: new Date().toLocaleString('id-ID'), + balanceAfter: balance + }); + + // Update UI + updateUI(); + updateTopUpHistory(); + + // Tampilkan pesan sukses + setMessage(`Top up berhasil! +${amount.toLocaleString('id-ID')}`, 'win'); + + // Sembunyikan modal + hideTopUpModal(); +} + +// Fungsi untuk memperbarui riwayat top up +function updateTopUpHistory() { + if (!topUpHistoryEl) return; + + topUpHistoryEl.innerHTML = ''; + + if (topUpHistory.length === 0) { + topUpHistoryEl.innerHTML = '

Belum ada riwayat top up

'; + return; + } + + // Tampilkan maksimal 5 riwayat terbaru + const recentHistory = topUpHistory.slice(-5).reverse(); + + recentHistory.forEach(record => { + const historyItem = document.createElement('div'); + historyItem.className = 'history-item'; + historyItem.innerHTML = ` +
+${record.amount.toLocaleString('id-ID')}
+
${record.date}
+
Saldo: ${record.balanceAfter.toLocaleString('id-ID')}
+ `; + topUpHistoryEl.appendChild(historyItem); + }); +} + +// Fungsi untuk memperbarui tampilan saldo top up +function updateTopUpBalance() { + if (topUpBalanceEl) { + topUpBalanceEl.textContent = `Total Top Up: ${topUpAmount.toLocaleString('id-ID')}`; + } +} + +// Event listeners untuk top up +if (topUpBtn) { + topUpBtn.addEventListener('click', showTopUpModal); +} + +if (topUpClose) { + topUpClose.addEventListener('click', hideTopUpModal); +} + +if (topUpConfirm) { + topUpConfirm.addEventListener('click', processTopUp); +} + +// Tutup modal jika klik di luar modal +window.addEventListener('click', (e) => { + if (e.target === topUpModal) { + hideTopUpModal(); + } +}); + +// Keyboard shortcut untuk top up (Ctrl+T) +window.addEventListener('keydown', e => { + if (e.ctrlKey && e.key === 't') { + e.preventDefault(); + showTopUpModal(); + } +}); + +// Modifikasi fungsi updateUI untuk menampilkan informasi top up +const originalUpdateUI = updateUI; +updateUI = function() { + originalUpdateUI(); + updateTopUpBalance(); +}; + +// Modifikasi fungsi newRound untuk reset saldo yang tidak mempengaruhi riwayat top up +const originalNewRound = newRoundBtn.onclick; +newRoundBtn.onclick = function() { + if (inRound && !confirm('Masih dalam ronde. Reset?')) return; + + // Reset saldo tapi pertahankan riwayat top up + const currentTopUpAmount = topUpAmount; + balance = 1000 + currentTopUpAmount; + currentBet = 0; + inRound = false; + dealer = []; + player = []; + deck = []; + dealerHidden = true; + setMessage('Bank di-reset.', ''); + updateUI(); +}; + +// Inisialisasi +updateTopUpHistory(); +updateTopUpBalance(); \ No newline at end of file