(function () { const BREAKPOINT = 1200; const adSel = '.sidebar__wrapper > .banner__ad-250:first-of-type'; const targetSel = '.article__content > .article-horizontal'; const sidebarSel = '.sidebar__wrapper'; function relocate() { const ad = document.querySelector(adSel); const target = document.querySelector(targetSel); const sidebar = document.querySelector(sidebarSel); if (!ad || !target || !sidebar) return; const isMobile = window.matchMedia(`(max-width:${BREAKPOINT - 1}px)`).matches; if (isMobile) { // przed pierwszym article-horizontal if (ad.parentNode !== target.parentNode || ad.nextSibling !== target) { target.parentNode.insertBefore(ad, target); } } else { // desktop: wrzuć z powrotem do sidebara (np. na początek) if (ad.parentNode !== sidebar) { sidebar.insertBefore(ad, sidebar.firstChild); } } } window.addEventListener('DOMContentLoaded', relocate); window.addEventListener('resize', relocate, { passive: true }); })();