1/** 2 * ÐомплекÑнÑй ÑкÑÐ¸Ð¿Ñ Ð´Ð¸Ð½Ð°Ð¼Ð¸ÑеÑкой вÑÑавки Google AdSense. 3 * ÐклÑÑаеÑ: ленивÑÑ Ð·Ð°Ð³ÑÑзкÑ, абÑолÑÑнÑÑ Ð¼Ð°ÑемаÑÐ¸ÐºÑ Ð¿ÑÐ¸Ð»Ð¸Ð¿Ð°Ð½Ð¸Ñ Ð¸ Ñлежение за изменением DOM. 4 * ÐеÑÑÐ¸Ñ ÑинÑакÑиÑа адапÑиÑована Ð´Ð»Ñ ÑÑаÑÑÑ ÑедакÑоÑов кода. 5 */ 6window.addEventListener('load', function() { 7 8 console.log('Шаг 1: СкÑÐ¸Ð¿Ñ Ð¸Ð½Ð¸ÑиализиÑован.'); 9 10 // 1. ÐÑклÑÑаем ÑабоÑÑ Ð½Ð° ÑмаÑÑÑÐ¾Ð½Ð°Ñ Ð¸ планÑеÑÐ°Ñ 11 if (window.innerWidth < 992) { 12 console.log('ÐÑÑановка: ÐобилÑное ÑÑÑÑойÑÑво.'); 13 return; 14 } 15 16 // 2. ÐÑем оÑновнÑе конÑейнеÑÑ ÑÑÑаниÑÑ 17 const mainContent = document.querySelector('.content'); 18 const widgetArea = document.querySelector('.widget-area'); 19 20 if (!mainContent) console.error('ÐÑибка: не найдена Ð»ÐµÐ²Ð°Ñ ÐºÐ¾Ð»Ð¾Ð½ÐºÐ° (.content)'); 21 if (!widgetArea) console.error('ÐÑибка: не найдена облаÑÑÑ Ð²Ð¸Ð´Ð¶ÐµÑов (.widget-area)'); 22 if (!mainContent || !widgetArea) return; 23 24 // Флаг, блокиÑÑÑÑий повÑоÑнÑÑ Ð²ÑÑÐ°Ð²ÐºÑ ÑÐµÐºÐ»Ð°Ð¼Ñ 25 let isBannerInserted = false; 26 27 /** 28 * ÐÐ»Ð°Ð²Ð½Ð°Ñ Ð»Ð¾Ð³Ð¸ÑеÑÐºÐ°Ñ ÑÑнкÑиÑ: пÑовеÑÑÐµÑ Ð¼ÐµÑÑо и вÑÑавлÑÐµÑ Ð±Ð°Ð½Ð½ÐµÑ. 29 */ 30 function tryInsertBanner() { 31 if (isBannerInserted) return; 32 33 const emptySpace = mainContent.offsetHeight - widgetArea.offsetHeight; 34 console.log('Шаг 2: Ðнализ вÑÑоÑÑ. Свободно: ' + emptySpace + 'px'); 35 36 let adSlotId = ''; 37 let adFormat = ''; 38 39 if (emptySpace >= 650) { 40 console.log('Шаг 3: ÐÑбÑан ÐÐÐЬШÐÐ Ð±Ð°Ð½Ð½ÐµÑ (300x600).'); 41 adSlotId = '3411197132'; 42 adFormat = 'display:inline-block;width:100%;height:600px;'; 43 } else if (emptySpace >= 300) { 44 console.log('Шаг 3: ÐÑбÑан ÐÐÐÐ«Ð Ð±Ð°Ð½Ð½ÐµÑ (300x250).'); 45 adSlotId = '3175302174'; 46 adFormat = 'display:inline-block;width:100%;height:250px;'; 47 } else { 48 console.log('Ðжидание: ÐедоÑÑаÑоÑно пÑÑÑого пÑоÑÑÑанÑÑва.'); 49 return; 50 } 51 52 console.log('Шаг 4: ÐенеÑиÑÑем HTML код баннеÑа...'); 53 const bannerElement = insertAdSenseWidget(widgetArea, adSlotId, adFormat); 54 isBannerInserted = true; 55 56 console.log('Шаг 5: ÐапÑÑкаем маÑемаÑиÑеÑкий алгоÑиÑм пÑилипаниÑ.'); 57 initJSSticky(bannerElement, mainContent); 58 } 59 60 // ТРÐÐÐÐÐ â1: СкÑолл до виджеÑов 61 const scrollObserver = new IntersectionObserver(function(entries) { 62 entries.forEach(function(entry) { 63 if (entry.isIntersecting) { 64 console.log('СÑабоÑал ТÑÐ¸Ð³Ð³ÐµÑ â1: ÐолÑзоваÑÐµÐ»Ñ Ð²Ð¸Ð´Ð¸Ñ ÐºÐ¾Ð½ÐµÑ ÑайдбаÑа.'); 65 tryInsertBanner(); 66 } 67 }); 68 }, { rootMargin: '200px' }); 69 70 const lastWidget = widgetArea.lastElementChild; 71 if (lastWidget) { 72 scrollObserver.observe(lastWidget); 73 } else { 74 tryInsertBanner(); 75 } 76 77 // ТРÐÐÐÐÐ â2: Ðзменение вÑÑоÑÑ Ð»ÐµÐ²Ð¾Ð¹ колонки 78 if (typeof ResizeObserver !== 'undefined') { 79 const resizeObs = new ResizeObserver(function() { 80 if (!isBannerInserted) { 81 const widgetRect = widgetArea.getBoundingClientRect(); 82 if (widgetRect.bottom <= window.innerHeight + 500) { 83 console.log('СÑабоÑал ТÑÐ¸Ð³Ð³ÐµÑ â2: ÐзменилÑÑ ÑÐ°Ð·Ð¼ÐµÑ ÐºÐ¾Ð½ÑенÑа!'); 84 tryInsertBanner(); 85 } 86 } 87 }); 88 resizeObs.observe(mainContent); 89 } 90}); 91 92/** 93 * Ð¡Ð¾Ð·Ð´Ð°ÐµÑ Ñзел DOM, наполнÑÐµÑ ÐµÐ³Ð¾ ÑазмеÑкой AdSense. 94 * ÐÐÐÐÐ: ÐÑполÑзована клаÑÑиÑеÑÐºÐ°Ñ ÐºÐ¾Ð½ÐºÐ°ÑенаÑÐ¸Ñ ÑÑÑок (Ñклеивание плÑÑами). 95 */ 96function insertAdSenseWidget(targetContainer, slotId, formatStyles) { 97 const asideWrapper = document.createElement('aside'); 98 asideWrapper.setAttribute('align', 'center'); 99 asideWrapper.style.marginTop = '5px'; 100 asideWrapper.style.width = '100%'; 101 102 // Склеиваем HTML-ÑÑÑÐ¾ÐºÑ Ð±ÐµÐ· иÑполÑÐ·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð¾Ð±ÑаÑнÑÑ ÐºÐ°Ð²ÑÑек 103 asideWrapper.innerHTML = 104 '<div class="pr-col-boottom dynamic-adsense-wrapper googleBnrs">\n' + 105 ' <span class="ad-label">Ð Ð Ð Ð Ð Ð Ð</span>\n' + 106 ' <ins class="adsbygoogle"\n' + 107 ' style="' + formatStyles + '"\n' + 108 ' data-ad-client="ca-pub-7496871329591180"\n' + 109 ' data-ad-slot="' + slotId + '"></ins>\n' + 110 ' </span>\n' + 111 '</div>'; 112 113 targetContainer.appendChild(asideWrapper); 114 115 try { 116 (window.adsbygoogle = window.adsbygoogle || []).push({}); 117 } catch (error) { 118 console.warn('Google AdSense заблокиÑован:', error); 119 } 120 121 return asideWrapper; 122} 123 124/** 125 * Ðвижок пÑÐ¸Ð»Ð¸Ð¿Ð°Ð½Ð¸Ñ Ð±Ð»Ð¾ÐºÐ°. 126 */ 127function initJSSticky(banner, mainContent) { 128 const spacer = document.createElement('div'); 129 spacer.style.display = 'none'; 130 spacer.style.clear = 'both'; 131 banner.parentNode.insertBefore(spacer, banner); 132 133 let isStuck = false; 134 let originalAbsoluteTop = 0; 135 136 window.addEventListener('scroll', function() { 137 if (!isStuck) { 138 originalAbsoluteTop = window.scrollY + banner.getBoundingClientRect().top; 139 } 140 141 const triggerPoint = originalAbsoluteTop - 20; 142 143 if (window.scrollY >= triggerPoint) { 144 if (!isStuck) { 145 spacer.style.height = banner.offsetHeight + 'px'; 146 spacer.style.display = 'block'; 147 148 banner.style.position = 'fixed';
149 banner.style.top = '20px'; 150 banner.style.width = spacer.parentNode.offsetWidth + 'px'; 151 banner.style.zIndex = '99'; 152 isStuck = true; 153 } 154 155 const mainRect = mainContent.getBoundingClientRect(); 156 const bannerHeight = banner.offsetHeight; 157 158 if (mainRect.bottom < (20 + bannerHeight)) { 159 banner.style.top = (mainRect.bottom - bannerHeight) + 'px'; 160 } else { 161 banner.style.top = '20px'; 162 } 163 } else { 164 if (isStuck) { 165 spacer.style.display = 'none'; 166 banner.style.position = 'static'; 167 banner.style.width = '100%'; 168 isStuck = false; 169 } 170 } 171 }); 172 173 window.addEventListener('resize', function() { 174 if (isStuck) { 175 banner.style.width = spacer.parentNode.offsetWidth + 'px'; 176 } 177 }); 178}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.