document.addEventListener('DOMContentLoaded', function() {
console.log('DOM fully loaded and parsed');
// Function to check if we are on the specific product page
function isSpecificProductPage() {
const productId = '362148245'; // Specific product ID
const isSpecific = window.location.href.includes(`p${productId}`);
console.log('isSpecificProductPage:', isSpecific);
return isSpecific;
}
// Function to toggle the visibility of the text box
function toggleWunschtextTextbox() {
const wunschtextRadio = document.querySelector('input[value="Wunschtext"]');
const wunschtextTextbox = document.querySelector('input[aria-label="Wunschtext Rückseite (max. 20 Zeichen)"]');
console.log('toggleWunschtextTextbox:', { wunschtextRadio, wunschtextTextbox });
if (wunschtextRadio && wunschtextTextbox) {
if (wunschtextRadio.checked) {
wunschtextTextbox.style.display = 'block';
} else {
wunschtextTextbox.style.display = 'none';
}
}
}
// Function to initialize the script
function init() {
if (isSpecificProductPage()) {
const observer = new MutationObserver((mutations, obs) => {
const radioContainer = document.querySelector('.product-details-module.details-product-option--radio.details-product-option--R00fcckseit');
console.log('MutationObserver:', { radioContainer });
if (radioContainer) {
const keineRadio = document.querySelector('input[value="Keine"]');
const gleichWieVorderseiteRadio = document.querySelector('input[value="Gleich wie Vorderseite"]');
const wunschtextRadio = document.querySelector('input[value="Wunschtext"]');
const wunschtextTextbox = document.querySelector('input[aria-label="Wunschtext Rückseite (max. 20 Zeichen)"]');
console.log('Found radio buttons and text box:', { keineRadio, gleichWieVorderseiteRadio, wunschtextRadio, wunschtextTextbox });
if (keineRadio && gleichWieVorderseiteRadio && wunschtextRadio && wunschtextTextbox) {
// Attach event listeners to radio buttons
keineRadio.addEventListener('change', toggleWunschtextTextbox);
gleichWieVorderseiteRadio.addEventListener('change', toggleWunschtextTextbox);
wunschtextRadio.addEventListener('change', toggleWunschtextTextbox);
// Initial call to set the correct state on page load
toggleWunschtextTextbox();
obs.disconnect(); // Stop observing once we have the elements
}
}
});
// Start observing the body for changes
observer.observe(document.body, {
childList: true,
subtree: true
});
}
}
// Run the init function after a delay to ensure the page is fully loaded
setTimeout(init, 3000);
});