<script>
document.addEventListener('DOMContentLoaded', function() {
    
    function buildAddressString(location) {
        const parts = [];
        if (location.addressTitle) parts.push(location.addressTitle);
        if (location.addressLine1) parts.push(location.addressLine1);
        if (location.addressLine2) parts.push(location.addressLine2);
        if (location.addressCountry) parts.push(location.addressCountry);
        return parts.join(', ').trim();
    }
    
    function buildLocationDisplayText(location) {
        const parts = [];
        if (location.addressTitle) parts.push(location.addressTitle);
        if (location.addressLine2) parts.push(location.addressLine2);
        return parts.join(', ').trim();
    }
    
    function hasLocationData(secondaryMetadata) {
        return secondaryMetadata.querySelector('.summary-metadata-item--location') !== null;
    }
    
    function addLocationToItem(summaryItem, location) {
        const secondaryMetadatas = summaryItem.querySelectorAll('.summary-metadata--secondary');
        
        secondaryMetadatas.forEach(function(secondaryMetadata) {
            if (hasLocationData(secondaryMetadata)) {
                return;
            }
            
            if (!location || (!location.addressTitle && !location.addressLine1 && !location.addressLine2)) {
                return;
            }
            
            const addressString = buildAddressString(location);
            const displayText = buildLocationDisplayText(location);
            
            if (!displayText) {
                return;
            }
            
            const locationHTML = '<span class="summary-metadata-item summary-metadata-item--location"><a href="http://maps.google.com?q=' + encodeURIComponent(addressString) + '" target="_blank">' + displayText + '</a></span>';
            
            secondaryMetadata.insertAdjacentHTML('beforeend', locationHTML);
        });
    }
    
    function updateEventListLinks() {
        const eventItems = document.querySelectorAll('.eventlist-event');
        
        eventItems.forEach(function(eventItem) {
            const eventLink = eventItem.querySelector('.eventlist-title-link');
            const thumbnailLink = eventItem.querySelector('.eventlist-column-thumbnail');
            const viewButton = eventItem.querySelector('.eventlist-button');
            
            if (eventLink) {
                const eventUrl = eventLink.getAttribute('href');
                
                fetch(eventUrl + '?format=json')
                    .then(response => response.json())
                    .then(data => {
                        const sourceUrl = data.item && data.item.sourceUrl;
                        
                        if (sourceUrl) {
                            if (eventLink) {
                                eventLink.setAttribute('href', sourceUrl);
                            }
                            
                            if (thumbnailLink) {
                                thumbnailLink.setAttribute('href', sourceUrl);
                            }
                            
                            if (viewButton) {
                                viewButton.setAttribute('href', sourceUrl);
                            }
                        }
                    })
                    .catch(error => {
                        console.log('Error fetching event data:', error);
                    });
            }
        });
    }
    
    function updateSummaryBlockLinks() {
        const summaryItems = document.querySelectorAll('.summary-item');
        
        summaryItems.forEach(function(summaryItem) {
            const titleLink = summaryItem.querySelector('.summary-title-link');
            const thumbnailLink = summaryItem.querySelector('.summary-thumbnail-container');
            
            if (titleLink) {
                const originalEventUrl = titleLink.getAttribute('href');
                
                fetch(originalEventUrl + '?format=json')
                    .then(response => response.json())
                    .then(data => {
                        const sourceUrl = data.item && data.item.sourceUrl;
                        const location = data.item && data.item.location;
                        
                        if (location) {
                            addLocationToItem(summaryItem, location);
                        }
                        
                        if (sourceUrl) {
                            if (titleLink) {
                                titleLink.setAttribute('href', sourceUrl);
                            }
                            
                            if (thumbnailLink) {
                                thumbnailLink.setAttribute('href', sourceUrl);
                            }
                        }
                    })
                    .catch(error => {
                        console.log('Error fetching summary event data:', error);
                    });
            }
        });
    }
    
    updateEventListLinks();
    updateSummaryBlockLinks();
});
</script>

 

Buy me a coffee