// Get the current script tag const scriptTag = document.currentScript; // Get the policy ID from an attribute 'policy-id' const policyId = scriptTag.getAttribute('policy-id'); // Create a new section element const dataPolicySection = document.createElement('section'); // Add a class to the section element dataPolicySection.classList.add('kfv-data-policy'); // Function to generate data policy content based on the policy ID function generateDataPolicy(policyId) { if (policyId === '999') { // Set the default content for policy ID 999 dataPolicySection.innerHTML = "Default Policy Content for ID 999"; } else { // Construct the URL dynamically based on the policy ID const apiUrl = `https://r.kfv.at/test/api/${policyId}`; // Make a request to the specified API endpoint fetch(apiUrl) .then(response => response.text()) .then(data => { // Set the fetched data as the data policy content dataPolicySection.innerHTML = data; }) .catch(error => { console.error('Error fetching API content:', error); // Set an empty content (nothing) in case of an error dataPolicySection.innerHTML = ""; }); } } // Generate Content for the Data Policy generateDataPolicy(policyId); // Append the section right after the script tag scriptTag.parentNode.insertBefore(dataPolicySection, scriptTag.nextSibling);