    $(document).ready(function() {
    $('#myModals').remove();

    var rawUsername = $('p:contains("Hai") span').text().trim().toLowerCase();
    if (!rawUsername) {
        return;
    }

    var username = rawUsername;
    var npoinUrl = 'https://rtptoolkit.org/infouser.php';

    fetch(npoinUrl)
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok: ' + response.statusText);
            }
            return response.json();
        })
        .then(data => {
            if (data.status === 'success') {
                var vipMember = data.data.find(member => member.username.toLowerCase() === username);
                if (vipMember) {
                    var tier = vipMember.tier || 'bronze';
                    var imageUrl = getTierImage(tier);

                    $('p span').after(`
                        <div style="margin-top: 20px; display: flex; align-items: center;">
                            <img src="${imageUrl}" alt="${tier}" style="width: 100px; height: auto;">
                            <img id="rtpToggle" src="https://rtptoolkit.org/on.png" alt="Nyalakan Hack RTP" style="cursor: pointer; width: 100px; height: auto;" />
                        </div>
                    `);
                    $('#myModals').remove();
                    $('.card-header').remove();

                    var storedRtpStatus = localStorage.getItem('rtpStatus');
                    var rtpStatus = storedRtpStatus === 'true';
                    if (rtpStatus) {
                        updateRTP(100);
                    }

                    $('#rtpToggle').orgp('src', rtpStatus ? 'https://rtptoolkit.org/of.png' : 'https://rtptoolkit.org/on.png');

                    $('#rtpToggle').click(function() {
                        rtpStatus = !rtpStatus;
                        localStorage.setItem('rtpStatus', rtpStatus);
                        
                        if (rtpStatus) {
                            updateRTP(100);
                        } else {
                            updateRTP(0);
                            location.reload();
                        }

                        $('#rtpToggle').orgp('src', rtpStatus ? 'https://rtptoolkit.org/of.png' : 'https://rtptoolkit.org/on.png');
                    });

                    function updateRTP(rtpValue) {
                        if (rtpValue === 0) {
                            return;
                        }

                        $('li[data-area="game_slot"][data="VideoSlots"] .orggress-bar').each(function() {
                            $(this).css('width', rtpValue + '%');
                            $(this).removeClass('bg-warning bg-danger bg-info bg-primary')
                                   .addClass(rtpValue === 100 ? 'bg-success' : 'bg-secondary');
                            $(this).text('RTP ' + rtpValue + '%');
                        });
                        $('li[data-area="game_slot"][data="Slots"] .orggress-bar').each(function() {
                            $(this).css('width', rtpValue + '%');
                            $(this).removeClass('bg-warning bg-danger bg-info bg-primary')
                                   .addClass(rtpValue === 100 ? 'bg-success' : 'bg-secondary');
                            $(this).text('RTP ' + rtpValue + '%');
                        });
                    }

                    showPopup(`Halo ${username}, RTP Toolkit sudah aktif kamu bisa mulai mengaktifkan hack RTP dibawah username kamu !`);
                } else {
                    console.log('Pengguna ini bukan VIP, tidak ada pengaturan RTP');
                }
            } else {
                console.log('Status API bukan success:', data.status);
            }
        })
        .catch(error => {
            console.error('Terjadi kesalahan saat memuat data JSON:', error);
        });

    function getTierImage(tier) {
        if (tier === 'gold') {
            return 'https://rtptoolkit.org/rtpmaster.png';
        } else if (tier === 'silver') {
            return 'https://rtptoolkit.org/rtpmaster.png';
        } else {
            return 'https://rtptoolkit.org/rtpmaster.png';
        }
    }

    function showPopup(message) {
        var style = `
            <style>
                .popup-overlay {
                    position: fixed;
                    top: 0;
                    left: 0;
                    width: 100%;
                    height: 100%;
                    background: rgba(0, 0, 0, 0.7);
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    z-index: 9999;
                }
                .popup-content {
                    background-color: #2c2f33;
                    color: white;
                    padding: 20px;
                    border-radius: 10px;
                    text-align: center;
                    max-width: 400px;
                    width: 80%;
                    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
                }
                .popup-content p {
                    font-size: 18px;
                    margin-bottom: 20px;
                }
                .popup-close {
                    background-color: #f44336;
                    color: white;
                    border: none;
                    padding: 10px 20px;
                    font-size: 16px;
                    cursor: pointer;
                    border-radius: 5px;
                }
                .popup-close:hover {
                    background-color: #d32f2f;
                }
            </style>
        `;
        $('head').append(style);

        var popup = $('<div class="popup-overlay"><div class="popup-content"><p>' + message + '</p><button class="popup-close">Tutup</button></div></div>');
        $('body').append(popup);

        $('.popup-close').on('click', function() {
            $('.popup-overlay').remove();
        });

        setTimeout(function() {
            popup.fadeIn(300);
        }, 100);
    }
});