Buy me a coffee
<script>
document.addEventListener('DOMContentLoaded', function() {
    var urlCache = {};

    function getSourceUrl(eventPath) {
        if (urlCache[eventPath]) return urlCache[eventPath];
        urlCache[eventPath] = fetch(eventPath + '?format=json')
            .then(function(r) { return r.json(); })
            .then(function(data) {
                return data.item && data.item.sourceUrl || null;
            })
            .catch(function() { return null; });
        return urlCache[eventPath];
    }

    function replaceLinks(links) {
        var grouped = {};
        links.forEach(function(link) {
            var href = link.getAttribute('href');
            if (!href || href.charAt(0) !== '/') return;
            if (!grouped[href]) grouped[href] = [];
            grouped[href].push(link);
        });

        Object.keys(grouped).forEach(function(eventPath) {
            getSourceUrl(eventPath).then(function(sourceUrl) {
                if (!sourceUrl) return;
                grouped[eventPath].forEach(function(el) {
                    el.setAttribute('href', sourceUrl);
                });
            });
        });
    }

    var eventListLinks = document.querySelectorAll(
        '.eventlist-title-link, .eventlist-column-thumbnail, .eventlist-button'
    );
    replaceLinks(eventListLinks);

    var summaryLinks = document.querySelectorAll(
        '.summary-thumbnail-container, .summary-title-link'
    );
    replaceLinks(summaryLinks);

    var calendarSelectors = '.background-image-link, .item-link, .flyoutitem-link';

    function processCalendar() {
        var calendarLinks = document.querySelectorAll(calendarSelectors);
        if (calendarLinks.length) replaceLinks(calendarLinks);
    }

    processCalendar();

    var calendarBlock = document.querySelector('.sqs-block-calendar');
    if (calendarBlock) {
        var observer = new MutationObserver(function() {
            processCalendar();
        });
        observer.observe(calendarBlock, { childList: true, subtree: true });
    }
});
</script>