Teatro Italia javascript

                  const busqueda = "Palazzina di Caccia di Stupinigi" //String to find for background color changed
const colorFondo_modal = "#e8c812" //New Color for background color changed
const chrome_nav = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
const URLactual = window.location.href;

/**** Variables de Posicionado  ****/
let hora_pos_top, la_hora, title_pos_top, el_alto, top_hora, pos_hora, diferencia, mas_alto, mas_bajo = 1000000

/**** Variables de Modal  ****/
let a = 0, diaOut, mesOut, diaTxtOut, yearOut, horaOut, pos

/**** Control Modal ****/
termina = () =>
{
    /*** Background Color ***/
    cambiaFondo = false
    if (subHeaderPagina.includes(busqueda)) cambiaFondo = true
    elFondo_modal = document.querySelectorAll('.wcs-modal.wcs-modal-container')
    if (cambiaFondo) elFondo_modal[0].style = "background-color: " + colorFondo_modal + "!important"

    /*** Sub Heading ***/
    headingModal = document.querySelectorAll('.wcs-modal__title')
    headingModal[0].children[0].innerText = subHeaderPagina

    /*** Boton ***/
    boton = document.querySelectorAll('.wcs-modal__action')[0].outerHTML

    /*** Datos Fecha ***/
    fechaModal = document.querySelectorAll('.wcs-modal__meta')
    fechaDatos = fechaModal[0].firstChild.innerText
    diaOut = fechaDatos.substring(0, 2)
    for (let i = 0; i < fechaDatos.length; i++) {
        if (fechaDatos[i] === " ") {
            a = a + 1;
            switch (a) {
                case 2:
                    mesOut = fechaDatos.substring(3, i)
                    pos = i
                    break
                case 3:
                    diaTxtOut = fechaDatos.substring(pos + 1, i)
                    pos = i
                    break
                case 4:
                    yearOut = fechaDatos.substring(pos + 1, i)
                    pos = i
                    break
                case 5:
                    horaOut = fechaDatos.substring(pos + 1, i - 4)
                    break
            }
        }
    }

    /*** Imprimir y formatear ***/
    datosHora = '<span class="hora-evento">ore ' + horaOut + '</span>' //Hora
    datosFecha = '<div class="datado-modal"><span class="date-day">' + diaOut + '</span> <span class="date-short">' + mesOut + ' ' + diaTxtOut + ' ' + yearOut + '</span></div>'
    fechaModal[0].innerHTML = '<div class="datado-principal"><div class="cuadro_tiempo">' + datosFecha + datosHora + '</div>' + boton
}

laBusqueda = () =>
{
    containerModal = document.querySelectorAll('.wcs-modal__meta')
    if (containerModal.length > 0) {
        termina()
        clearInterval(interval)
    }
}


/************************************************ ******************************/
window.addEventListener('load', () =>
{
    /******   Control Modal   *****/
    document.addEventListener('click', (e) =>
    {
        if (e.target.closest('.wcs-class')) {
            contenedorPagina = e.target.closest('.wcs-class')
            subHeader = contenedorPagina.querySelectorAll('.wcs-class__excerpt')
            subHeaderPagina = subHeader[0].children[1].innerText
            interval = setInterval(function () { laBusqueda() }, 1)
        }
    })

    /******   Size and posittion adjustement for cards  ****/
    const titulos_slider = document.querySelectorAll('.titolo-evento.wcs-modal-call')

    titulos_slider.forEach((v) =>
    {
        top_hora = v.nextElementSibling.offsetTop
        if (top_hora > mas_alto) mas_alto = top_hora
        if (top_hora < mas_bajo) mas_bajo = top_hora
        diferencia = (mas_alto - mas_bajo)
    })

    if (chrome_nav) diferencia = diferencia + 40
    titulos_slider.forEach((n) =>
    {
        la_hora = n.nextElementSibling
        hora_pos_top = n.nextElementSibling.offsetTop
        title_pos_top = n.offsetTop

        el_alto = hora_pos_top - title_pos_top
        n.nextElementSibling.nextElementSibling.style.marginTop = diferencia + (diferencia - el_alto) + "px"
    })
})