document.addEventListener("DOMContentLoaded", function() {
  // Existing JavaScript code
  const figureElement = document.querySelector('.wp-block-image.is-style-optimize-image-styleone');
  const imgElement = figureElement.querySelector('img');
  const dynamicImageURL = imgElement.src;

  // Set CSS variables for pseudo-elements
  figureElement.style.setProperty('--before-background-image', `url('${dynamicImageURL}')`);
  figureElement.style.setProperty('--after-background-image', `url('${dynamicImageURL}')`);

  // Create a style element to apply the background images using the CSS variables
  const style = document.createElement('style');
  style.innerHTML = `
    .wp-block-image.is-style-optimize-image-styleone::before {
      background-image: var(--before-background-image);
    }
    .wp-block-image.is-style-optimize-image-styleone::after {
      background-image: var(--after-background-image);
    }
  `;
  document.head.appendChild(style);
});
