class GBAdvert { static adv_config = { url : 'https://adv.realty.ru/', urlTest : 'https://d.cnvl.io/peon/adv/', urlDemoTest : 'https://demo.slmax.by/adv/', } static not_empty_links = []; static init(){ const options = { rootMargin: '0px', threshold: 0.0015 } const observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { const adv = entry.target GBAdvert.showAdv($(adv)[0].dataset.adv_id) observer.unobserve(adv) } }) }, options) for (let adv of $("[id^='GB_advert']")){ if (/_[\d]+(_block1)*$/.test($(adv)[0].id)) { $(adv)[0].dataset.adv_id = $(adv)[0].id.match(/(\d+)/g)[0]; } } const arr = document.querySelectorAll('[data-adv_id]:not([data-observed="1"])'); arr.forEach(i => { $(i)[0].dataset.observed = '1'; if (GBAdvert.not_empty_links.includes($(i)[0].dataset.adv_id)) { GBAdvert.showAdv($(i)[0].dataset.adv_id) } else { observer.observe(i); } }) } static showAdv(adv_block_id) { let showAll = !1; if (window.location.href.indexOf('showall=1') > 0) { showAll = !0; } if (window.location.href.indexOf('d.cnvl.io') != '-1') { let responce = this.adv_config.urlTest + 'gb.php?site=' + SITE_ID + '&reff=' + this.getReff() + '&bot_ok=&block_adv=' + adv_block_id + (showAll ? '&showall=1' : ''); console.log(responce); $.getScript(responce) } else if (window.location.href.indexOf('new3.realty.ru') != '-1') { let responce = this.adv_config.urlDemoTest + 'gb.php?site=' + SITE_ID + '&reff=' + this.getReff() + '&bot_ok=&block_adv=' + adv_block_id + (showAll ? '&showall=1' : ''); console.log(responce); $.getScript(responce) } else { let responce = this.adv_config.url + 'gb.php?site=' + SITE_ID + '&reff=' + this.getReff() + '&bot_ok=&block_adv=' + adv_block_id + (showAll ? '&showall=1' : ''); console.log(responce); $.getScript(responce) } } static getReff() { return window.location.origin + window.location.pathname; } } GBAdvert.init()