fix: YouTube-Elementor-widget zeigt video auch nach reload (v1.4.7)

Nach reload mit bereits erteilter einwilligung blieb das e-youtube-base-video
leer: ich kehrte frueh zurueck und ueberliess es Elementors eigenem render
(unzuverlaessig). Die anderen blocker haben einen server-platzhalter, den
loadPreConsented direkt laedt - das JS-gebaute YouTube-element nicht.

Jetzt verwalte ich das widget mit embed-URL komplett selbst:
- nicht eingewilligt -> platzhalter (eingeklappt, kein weissraum)
- eingewilligt (auch nach reload) -> iframe wird sofort direkt gebaut (16:9),
  unabhaengig von Elementor/iframe_api.
Reload-fallback nur noch ohne URL.

+ version 1.4.7.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
s4luorth
2026-06-08 13:46:17 +02:00
parent 6c034ed714
commit 3c93027253
2 changed files with 26 additions and 19 deletions

View File

@@ -415,28 +415,35 @@
} }
if ( ! svc ) return; if ( ! svc ) return;
if ( hasConsent( svc.id ) ) return; // consented → let Elementor build it
// Neutralise Elementor so it won't build the player / load the overlay.
widget.removeAttribute( 'data-settings' );
// With an embed URL we build the iframe ourselves on consent (reliable,
// independent of Elementor/iframe_api). The iframe gets a responsive
// 16:9 aspect so it loads full-width at its original proportions.
// Without a URL we fall back to reloading so Elementor renders it.
const placeholder = buildPlaceholder( svc, embed, {} );
if ( embed ) { if ( embed ) {
placeholder.dataset.cbAspect = '16 / 9'; // We fully manage this widget — independent of Elementor's own JS
} else { // build (which is unreliable and needs the blocked iframe_api).
placeholder.setAttribute( 'data-cb-reload', '1' ); // This also means it works the same on a fresh load AND after a
const remember = placeholder.querySelector( '.cb-blocker__remember' ); // reload when consent is already stored.
if ( remember ) remember.remove(); widget.removeAttribute( 'data-settings' );
container.innerHTML = '';
const placeholder = buildPlaceholder( svc, embed, {} );
placeholder.dataset.cbAspect = '16 / 9'; // responsive, original proportions
container.appendChild( placeholder );
if ( hasConsent( svc.id ) ) {
loadContent( placeholder ); // already consented → show the video now
} else {
collapseAncestors( placeholder ); // no whitespace while blocked
}
return;
} }
// No URL found in the DOM → we can't build the iframe ourselves. Fall
// back to a reload so Elementor renders the player. If already
// consented, leave the widget untouched for Elementor.
if ( hasConsent( svc.id ) ) return;
widget.removeAttribute( 'data-settings' );
container.innerHTML = ''; container.innerHTML = '';
const placeholder = buildPlaceholder( svc, embed, {} );
placeholder.setAttribute( 'data-cb-reload', '1' );
const remember = placeholder.querySelector( '.cb-blocker__remember' );
if ( remember ) remember.remove();
container.appendChild( placeholder ); container.appendChild( placeholder );
// Collapse the wrapper's reserved aspect height so there is no
// whitespace while the (small) placeholder is shown.
collapseAncestors( placeholder ); collapseAncestors( placeholder );
} ); } );
} }

View File

@@ -3,7 +3,7 @@
* Plugin Name: GDPR Content Blocker * Plugin Name: GDPR Content Blocker
* Plugin URI: https://lucas-orth.de * Plugin URI: https://lucas-orth.de
* Description: DSGVO-konformer Consent-Blocker für externe iframes. Lädt Drittinhalte erst nach aktiver Einwilligung. * Description: DSGVO-konformer Consent-Blocker für externe iframes. Lädt Drittinhalte erst nach aktiver Einwilligung.
* Version: 1.4.6 * Version: 1.4.7
* Author: Lucas Orth * Author: Lucas Orth
* Author URI: https://lucas-orth.de * Author URI: https://lucas-orth.de
* Text Domain: gdpr-content-blocker * Text Domain: gdpr-content-blocker
@@ -15,7 +15,7 @@
defined( 'ABSPATH' ) || exit; defined( 'ABSPATH' ) || exit;
define( 'CB_VERSION', '1.4.6' ); define( 'CB_VERSION', '1.4.7' );
define( 'CB_FILE', __FILE__ ); define( 'CB_FILE', __FILE__ );
define( 'CB_DIR', plugin_dir_path( __FILE__ ) ); define( 'CB_DIR', plugin_dir_path( __FILE__ ) );
define( 'CB_URL', plugin_dir_url( __FILE__ ) ); define( 'CB_URL', plugin_dir_url( __FILE__ ) );