document.addEventListener('DOMContentLoaded', function () {
    const live = document.getElementById('result_iframe');
    const loader = document.getElementById('fake_iframeResult');
    const fakeIframe = document.getElementById('appHome');

    if (live) {
        const observer = new MutationObserver(function (mutationsList) {
            
            for (const mutation of mutationsList) {

                for (const node of mutation.addedNodes) {
                    if (node.nodeType === 1) {
                        // Kiểm tra nếu node hoặc con cháu của node có class 'league-item'
                        if (
                            node.classList.contains('load-more-btn') ||
                            node.querySelector?.('.load-more-btn') ||
                            node.querySelector?.('.upper-live-titlez') ||
                            node.querySelector?.('.table-no-tioem')
                        ) {
                            if (loader) {
                                live.style.opacity = 1;
                                setTimeout(() => {
                                    fakeIframe.classList.add('hide-fake');
                                    loader.style.transition = 'opacity 0.5s ease';
                                    loader.style.opacity = 0;
                                    loader.style.display = 'none';
                                    // loader.remove();


                                    const element = document.querySelector('#scrollIframe .mcontent');
                                    element.style.minHeight = 'inherit';
                                    element.style.setProperty('min-height', 'inherit', 'important');
                                }, 1000);
                            }
                            observer.disconnect(); // Ngừng theo dõi sau khi tìm thấy
                            return;
                        }
                    }
                }
            }
        });

        observer.observe(live, {
            childList: true,
            subtree: true // nếu div nằm sâu bên trong
        });
    }
});