Flüssigkeiten Angebote

// Function to add the class "atr_artikel" to the span element function addClassToSpan(spanElement) { // Trim the text content to remove leading comma and whitespace const trimmedText = spanElement.textContent.trim(); spanElement.textContent = trimmedText; // Add the class "atr_artikel" and set opacity to 1 spanElement.classList.add('atr_artikel'); spanElement.style.opacity = 1; } // Function to observe changes in the DOM and apply changes to span elements function observeDOMChanges() { const spansWithClassThumbTitle = document.querySelectorAll('.thumb-title.small.stretched-link span'); spansWithClassThumbTitle.forEach((spanElement) => { if (!spanElement.classList.contains('atr_artikel')) { // Call the function to add the class when necessary addClassToSpan(spanElement); } }); } // Create a MutationObserver to watch for changes in the DOM const observer = new MutationObserver((mutationsList) => { for (const mutation of mutationsList) { if (mutation.type === 'childList') { // Iterate through added nodes and check if they are spans mutation.addedNodes.forEach((node) => { if (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'SPAN') { const spanElement = node; if (!spanElement.classList.contains('atr_artikel')) { // Call the function to add the class when necessary addClassToSpan(spanElement); } } }); } } }); // Observe changes in the entire document, including dynamically added elements observer.observe(document, { childList: true, subtree: true }); // Initialize the script on page load window.addEventListener('load', observeDOMChanges);