// Function to handle the logic for both events function handleTldSpecificContent() { // Function to extract the top-level domain from the URL function getTopLevelDomain() { var domain = window.location.hostname; return domain.substring(domain.lastIndexOf('.') + 1); } // Get the current top-level domain var tld = getTopLevelDomain(); // Define the mapping of TLDs to CSS classes var tldToShowClassMap = { 'de': 'show_only_de', 'ch': 'show_only_ch', 'ie': 'show_only_ie', 'at': 'show_only_at' }; // Remove elements that don't match the current TLD for (var key in tldToShowClassMap) { if (tldToShowClassMap.hasOwnProperty(key) && key !== tld) { document.querySelectorAll('.' + tldToShowClassMap[key]).forEach(function(element) { element.remove(); }); } } } // Attach the function to the pdp_ajax_loaded event window.addEventListener('pdp_ajax_loaded', handleTldSpecificContent); window.addEventListener('plp_ajax_loaded', handleTldSpecificContent); // Attach the function to the DOMContentLoaded event document.addEventListener('DOMContentLoaded', handleTldSpecificContent);