AUR Departures: More Politicians Leaving Simion’s Party
This code snippet is a JavaScript function designed to embed a video player from ivm.antenaplay.ro onto a webpage,handling GDPR consent requirements. Let’s break down its functionality step-by-step:
1. insertIvmEmbed(ivm_wrapper_id) Function:
* Purpose: This function is the core of the embedding process. It dynamically creates a <script> tag, sets its src attribute to a URL that includes video ID, dimensions, and other parameters, and then appends the script to the document.body.
* ivm_wrapper_id: This parameter seems to be a flag indicating whether to insert the embed. The ternary operator (1 == ivm_wrapper_id) ? 1 : 0 suggests it’s used to control whether the embed is actually initiated. If ivm_wrapper_id is 1, the value 1 is used; otherwise, 0 is used. This likely influences a later conditional check.
* s = document.createElement('script');: Creates a new <script> element.
* s.setAttribute(...): Sets the attributes of the script tag. Let’s dissect the src URL:
* //ivm.antenaplay.ro/js/embed_weegoo.js: The base URL of the embed script.
* ?id=" + str.dataset.guid: appends the video ID (guid) from the data-guid attribute of the element referenced by str. This is how the specific video to be played is identified.
* &width=" + w: Appends the width of the video player.
* &height="+h: Appends the height of the video player.
* &next=" + playRelated: Appends a flag indicating whether to play related videos after the current one finishes.
* &autoplay=0: Disables autoplay.
* &wide=true: Sets the player to wide mode.
* &muted=1: Mutes the player by default.
* &div_id=" + div_id: Appends the ID of the container div were the video player will be embedded.
* &ads=" + (ads?1:0): Appends a flag indicating whether to show ads. If the ads variable is truthy, it appends 1; or else, it appends 0.
* document.body.appendChild(s);: Adds the newly created script tag to the end of the <body> of the document. This triggers the script to download and execute, embedding the video player.
2. GDPR Consent Handling:
* setInterval(...): This sets up a recurring timer that checks for GDPR consent every 0.1 seconds. This is crucial because the consent management platform (CMP) might take some time to load and provide consent data.
* cnt += 1;: Increments a counter to track how manny times the interval has run.
* if( cnt === 600 ) clearInterval(consentSetInterval);: If the counter reaches 600 (representing 60 seconds), the interval is cleared. This prevents the code from running indefinitely if consent is never granted.
* if ( typeof window.__tcfapi !== 'undefined' ): Checks if the window.__tcfapi object exists. This object is provided by the CMP and is the interface for accessing consent data.
* clearInterval(consentSetInterval);: If __tcfapi is found, the interval is cleared because the CMP is ready.
* window.__tcfapi( 'addEventListener', 2, function( tcData,listenerSuccess ) { ...});: This is the core of the GDPR consent handling. It registers an event listener with the CMP to be notified when consent data is available.
* 'addEventListener':