mejora la seguridad y el rendimiento de esto

const pageCache = {};

function inicializarScripts() {
    ['inicializarWaveforms', 'inicializarReproductorAudio', 'minimizarform', 'selectorformtipo', 'ajax_submit', 'borrarcomentario', 'colab', 'configuser', 'deletepost', 'diferidopost', 'editarcomentario', 'like', 'notificacioncolab', 'busqueda', 'updateBackgroundColor', 'presentacionmusic', 'seguir', 'registro', 'comentarios', 'botoneditarpost', 'fan', 'perfilpanel', 'smooth', 'navpanel', 'borderborder', 'initializeFormFunctions', 'initializeModalregistro', 'submenu', 'selectortipousuario', 'empezarcolab', 'subidaRolaForm', 'avances', 'updateDates', 'initializeProgressSegments', 'initializeCustomTooltips', 'fondoAcciones', 'pestanasgroup', 'manejoDeLogs', 'progresosinteractive', 'setupScrolling', 'inicializarDescargas', 'handleAllRequests', 'textflux', 'autoFillUserInfo', 'inicializarPestanas', 'meta', 'reporteScript',  'reiniciarDiferidoPost', 'generarGrafico', 'grafico', 'IniciadoresConfigPerfil', 'proyectoForm', 'inicializarAlerta', 'autoRows', 'iniciarRS'].forEach(func => {
        if (typeof window[func] === 'function') {
            try {
                window[func]();
            } catch (error) {
                console.error(`Error al ejecutar ${func}:`, error);
            }
        }
    });

    // 'IniciadorSample', 'inicialRsForm',

    ['manageSeparatorsAndOrder', 'updateDaysElapsed'].forEach(func => {
        if (typeof window[func] === 'function') {
            window[func](func === 'manageSeparatorsAndOrder' ? ['.spaceprogreso', '#toggleOrderButton'] : '2024-01-01');
        }
    });
}

function reinicializar() {
    inicializarScripts();
    if (window.location.hash && typeof window.mostrarPestana === 'function') {
        window.mostrarPestana(window.location.hash);
    }
}

window.reinicializar = reinicializar;

function loadStripe(callback) {
    if (typeof Stripe !== 'undefined') return callback();
    const script = document.createElement('script');
    script.src = 'https://js.stripe.com/v3/';
    script.async = true;
    script.onload = callback;
    document.head.appendChild(script);
}

function initializeStripeFunctions() {
    ['stripepro', 'stripecompra'].forEach(func => {
        if (typeof window[func] === 'function') window[func]();
        else console.warn(`${func} no está definida`);
    });
}

function shouldCache(url) {
    return !['https://2upra.com/nocache'].some(noCacheUrl => new RegExp(noCacheUrl.replace('*', '.*')).test(url));
}

function loadContent(enlace, isPushState) {
    console.log('Iniciando carga de contenido:', enlace);
    if (!enlace || enlace.startsWith('javascript:') || enlace.includes('#') || enlace.includes('descarga_token')) return;

    if (pageCache[enlace] && shouldCache(enlace)) {
        document.getElementById('content').innerHTML = pageCache[enlace];
        if (isPushState) history.pushState(null, '', enlace);
        return reinicializar();
    }

    const loadingBar = document.getElementById('loadingBar');
    loadingBar.style.cssText = 'width: 70%; opacity: 1; transition: width 0.4s ease';

    fetch(enlace)
        .then(response => response.text())
        .then(data => {
            const parser = new DOMParser();
            const doc = parser.parseFromString(data, 'text/html');
            const content = doc.getElementById('content').innerHTML;
            document.getElementById('content').innerHTML = content;

            if (shouldCache(enlace)) pageCache[enlace] = content;

            loadingBar.style.cssText = 'width: 100%; transition: width 0.1s ease, opacity 0.3s ease';
            setTimeout(() => loadingBar.style.cssText = 'width: 0%; opacity: 0', 100);

            if (isPushState) history.pushState(null, '', enlace);

            doc.querySelectorAll('script').forEach(script => {
                const newScript = document.createElement('script');
                newScript.textContent = script.textContent;
                document.body.appendChild(newScript);
            });

            setTimeout(reinicializar, 100);
        })
        .catch(error => console.error('Error al cargar la página:', error));
}

document.addEventListener('DOMContentLoaded', function () {
    if (!window.location.href.includes('?fb-edit=1')) {
        if (!window.galleInicializado && typeof window.galle === 'function') {
            window.galle();
            window.galleInicializado = true;
        }
        reinicializar();
        loadStripe(initializeStripeFunctions);
    }

    function handleContentLoad(event, enlace, element) {
        if (element.classList.contains('no-ajax') || element.closest('.no-ajax')) return true;
        const lowerCaseLink = enlace.trim().toLowerCase();
        if (!enlace || lowerCaseLink.endsWith('.pdf') || ['https://2upra.com/nocache', 'javascript:', 'data:', 'vbscript:'].some(prefix => lowerCaseLink.startsWith(prefix)) || enlace.includes('#')) return true;
        event.preventDefault();
        loadContent(enlace, true);
    }

    document.querySelectorAll('a, button a, .botones-panel').forEach(element => {
        element.addEventListener('click', function (event) {
            const enlace = this.getAttribute('href') || this.getAttribute('data-href') || this.querySelector('a')?.getAttribute('href');
            return handleContentLoad(event, enlace, this);
        });
    });

    window.addEventListener('popstate', () => loadContent(location.href, false));
});