import Bowser from 'bowser';

window.waitEvent('scripts_window', () => {
  const browser = Bowser.getParser(window.navigator.userAgent);
  const isValidBrowser = browser.satisfies({
    macos: {
      safari: '>10.1',
    },
  });

  setTimeout(() => {
    if (isValidBrowser) {
      const sources = document.querySelectorAll('source');
      sources.forEach(source => {
        const img = source.parentElement.querySelector('img');
        source.dataset.src = img.dataset.src;
        source.srcset = img.dataset.src;
        img.src = img.dataset.src;
      });
    }
  }, 3000);
});
