let isHB = false;

function loadScript(src) {
    return new Promise((resolve, reject) => {
        const script = document.createElement('script');
        script.src = src;
        script.type = 'text/javascript';
        script.onload = () => resolve(script);
        script.onerror = () => reject(new Error(`Failed to load script: ${src}`));
        document.getElementsByTagName('head')[0].append(script);
    });
}
loadScript('https://adncdn.net/CHp5tRpJ')
    .then(() => loadScript('https://securepubads.g.doubleclick.net/tag/js/gpt.js'))
    .then(() => loadScript('https://c.amazon-adsystem.com/aax2/apstag.js'))
    .then(() => {
        apstag.init({
            pubID: '5dff1804-8b85-4514-bcc6-4b8fb563a913',
            adServer: 'googletag'
        });
        if (document.readyState !== 'loading') {
            console.log('!== loading ');
            console.log(document.readyState);
            if (validUrl) setTimeout(onDocumentReadyFunction, 0);
        } else {
            console.log('=== loading');
            console.log(document.readyState);
            if (validUrl) document.addEventListener('DOMContentLoaded', onDocumentReadyFunction);
        }
    })
    .catch(error => console.error(error));
var styleElement = document.createElement('style');
css = '@media only screen and (max-width: 480px) {.ob-grid-layout.ob-read-next-layout { width: 245px !important; }.ob-grid-layout.ob-read-next-layout .ob-dynamic-rec-container, .ob-grid-layout.ob-read-next-layout .ob-widget-items-container { position: relative !important; height: 84px !important; }".ob-grid-layout.ob-read-next-layout .ob-unit.ob-rec-image-container{ flex: 0 0 83px !important; }".CRMB_75.ob-read-next-layout .ob-rec-text{ font-size: 14px !important; }".CRMB_75.ob-read-next-layout .ob-rec-source{ font-size: 10px !important; }" .ob-grid-layout.ob-read-next-layout .ob-unit.ob-rec-button{ font-size: 9px !important; }".CRMB_75.ob-widget .ob_what a{ font-size: 8px !important; }".CRMB_75.ob-widget { bottom: 68px !important;}".CRMB_75.ob-widget .ob_what a{font-size: 0;}}"div[data-widget-id=`AR_39`],div[data-widget-id=`MB_13`]{margin-top: 40px; margin-bottom: 40px; text-align: -webkit-center !important;}';
styleElement.append(css);
document.getElementsByTagName('head')[0].append(styleElement);
let refreshIntervalCount = 0;
let validUrl = true;
var enablesSlotIDs = [];
var myAds = new Map([
    ['/21644743307/GRafa/ATF', {
        size: [
            [320, 100],
            [728, 90],
            [970, 90],
        ],
        id: '/21644743307/GRafa/ATF',
        SizeMapping: {
            desktop: [
                [728, 90],
                [970, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [320, 100],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `ATF`,
    }],
    ['/21644743307/GRafa/Top', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Top',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `ATF`,
    }],
    ['/21644743307/GRafa/In-Content_1', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/In-Content_1',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Other`,
    }],
    ['/21644743307/GRafa/In-Content_2', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/In-Content_2',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Other`,
    }],
    ['/21644743307/GRafa/Middle2', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Middle2',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
    ['/21644743307/GRafa/Right', {
        size: [
            [300, 250],
            [336, 280],
        ],
        id: '/21644743307/GRafa/Right',
        SizeMapping: {
            desktop: [
                [300, 250],
                [336, 280],
            ],
            tablet: [
                [300, 250],
                [336, 280],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Other`,
    }],
    ['/21644743307/GRafa/Left1', {
        size: [
            [300, 250],
        ],
        id: '/21644743307/GRafa/Left1',
        SizeMapping: {
            desktop: [
                [300, 250],
            ],
            tablet: [
                [300, 250],
            ],
            mobile: [
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Other`,
    }],
    ['/21644743307/GRafa/Left2', {
        size: [
            [300, 250],
        ],
        id: '/21644743307/GRafa/Left2',
        SizeMapping: {
            desktop: [
                [300, 250],
            ],
            tablet: [
                [300, 250],
            ],
            mobile: [
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Other`,
    }],
    ['/21644743307/GRafa/Middle1', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Middle1',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
	['/21644743307/GRafa/Middle_0', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Middle_0',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
	['/21644743307/GRafa/Middle_1', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Middle_1',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
	['/21644743307/GRafa/Middle_2', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Middle_2',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
	['/21644743307/GRafa/Middle_3', {
        size: [
            [300, 250],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Middle_3',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
    ['/21644743307/GRafa/SideBar_Left_1', {
        size: [
            [160, 600],
            [300, 600],
            [300, 1050],
            [336, 280],
            [300, 250],
            [360, 360]
        ],
        id: '/21644743307/GRafa/SideBar_Left_1',
        SizeMapping: {
            desktop: [
                [300, 1050],
                [160, 600],
                [336, 280],
                [300, 250],
                [360, 360]
            ],
            tablet: [
                [300, 1050],
                [160, 600],
                [336, 280],
                [300, 250],
                [360, 360]
            ],
            mobile: [],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Side`,
    }],
    ['/21644743307/GRafa/Sticky', {
        size: [
            [320, 50],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Sticky',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [320, 50],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Other`,
    }],
    ['/21644743307/GRafa/Category_Section', {
        size: [
            [300, 250],
            [336, 280],
            [728, 90],
            [970, 90],
        ],
        id: '/21644743307/GRafa/Category_Section',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
    ['/21644743307/GRafa/Section', {
        size: [
            [300, 250],
            [336, 280],
            [728, 90],
        ],
        id: '/21644743307/GRafa/Section',
        SizeMapping: {
            desktop: [
                [728, 90],
            ],
            tablet: [
                [728, 90],
            ],
            mobile: [
                [300, 250],
            ],
        },
        refreshIteration: 0,
        lazyLoad: {
            fetchMarginPercent: 50,
            renderMarginPercent: 150,
            mobileScaling: 2
        },
        position: `Content`,
    }],
]);
let isPageLoaded = false;
var enablesSlotIDs = [];
const slotsMap = new Map();
var PREBID_TIMEOUT = 1300;
var adUnits = [];
var enablesSlotIDs = [];
var deviceCategory = window.screen.width > 980 ? 'desktop' : window.screen.width > 730 ? 'tablet' : 'mobile';
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

function addAds(e, t) {
    let adpath = t;
    let prebidDone = false;
    let apstagDone = false;
    if (myAds.get(t)) {
        var i = myAds.get(t);
        googletag.cmd.push((() => {
            myAds.get(e.dataset.adpath).refreshIteration++
            var t = googletag.sizeMapping().addSize([980, 200], i.SizeMapping.desktop).addSize([730, 200], i.SizeMapping.tablet).addSize([0, 0], i.SizeMapping.mobile).build(),
                a = googletag.defineSlot(i.id, i.size).setTargeting(`refreshIteration`, myAds.get(e.dataset.adpath).refreshIteration.toString()).defineSizeMapping(t).addService(googletag.pubads()),
                o = e;
            for (let index = 0; index < newpbjsadUnits.length; index++) {
                if (newpbjsadUnits[index].code === adpath) {
                    newpbjsadUnits[index].code = a.getSlotElementId();
                    adnpbjs.addAdUnits(newpbjsadUnits[index]);
                    window.pbjs = adnpbjs;
                    break;
                }
            }
            o.id = a.getSlotElementId();
            slotsMap.set(o.id, a);
            enablesSlotIDs.push(a.getSlotElementId());
            googletag.enableServices();
            if(isHB){
                apstag.fetchBids({
                    slots: [{
                        slotID: o.id,
                        slotName: myAds.get(e.dataset.adpath).id,
                        sizes: myAds.get(e.dataset.adpath).SizeMapping[deviceCategory]
                    }],
                    timeout: 2e3
                }, (function (t) {
                    googletag.cmd.push((function () {
                        console.log('amazon returned');
                        apstag.setDisplayBids();
                        apstagDone = true;
                        sendRequestToPrebid(o.id, prebidDone, apstagDone)
                    }))
                })), window.pbjs.que.push((function () {
                    window.pbjs.requestBids({
                        timeout: PREBID_TIMEOUT,
                        adUnitCodes: [o.id],
                        bidsBackHandler: function () {
                            googletag.cmd.push((function () {
                                prebidDone = true;
                                console.log('prebid backhandler');
                                sendRequestToPrebid(o.id, prebidDone, apstagDone)
                            }))
                        }
                    })
                }))
            }else{
                sendRequestToPrebid(o.id,true,true);
            }
        }))
    }
}(window.googletag = window.googletag || {
    'cmd': []
}).cmd.push(function () {
    googletag.pubads().addEventListener('impressionViewable', function (event) {
        if (refreshIntervalCount <= 10) {
            console.log(event);
            if (myAds.get(event.slot.getAdUnitPath().replace(``, ``)).position == 'Content') {
                refreshInterval = 30000;
            } else if (myAds.get(event.slot.getAdUnitPath().replace(``, ``)).position == 'Sticky') {
                refreshInterval = 45000;
            } else {
                refreshInterval = 30000;
            }
            console.log('Adunit ' + event.slot.getSlotElementId() + ' is viewable');
            if (enablesSlotIDs.indexOf(event.slot.getSlotElementId()) >= 0) {
                console.log('Schedule refresh for ' + event.slot.getSlotElementId() + ' in ' + refreshInterval + 'ms');
                setTimeout(function () {
                    try {
                        let adunitToRefresh = googletag.pubads().getSlots().filter(function (adunit) {
                            return (adunit.getSlotElementId() == event.slot.getSlotElementId())
                        })[0];
                        console.log('AD UNIT TO REFRESH');
                        let dynamicPart = event.slot.getAdUnitPath();
                        let selector = `div[data-adpath='${dynamicPart}']`;
                        let element = document.querySelector(selector);
                        myAds.get(event.slot.getAdUnitPath().replace(``, ``)).refreshIteration++;
                        event.slot.setTargeting(`refreshIteration`, myAds.get(event.slot.getAdUnitPath().replace(``, ``)).refreshIteration.toString());
                        refreshBid(element);
                        console.log('Refreshing ' + event.slot.getSlotElementId());
                    } catch (e) {
                        console.log('Error refreshing!')
                    }
                }, refreshInterval);
            }
        }
    });
});
let refreshBid = (adElement) => {
    apstag.fetchBids({
        slots: [{
            slotID: adElement.id,
            slotName: myAds.get(adElement.dataset.adpath).id,
            sizes: myAds.get(adElement.dataset.adpath).SizeMapping[deviceCategory]
        }],
        timeout: 2e3
    }, function (bids) {
        console.log(`refreshBid`);
        console.log(`adUnitCodes.id`);
        console.log(myAds.get(adElement.dataset.adpath).id);
        console.log(`adUnitCodes`);
        console.log(myAds.get(adElement.dataset.adpath));
        console.log(`slotsMap.get(adElement.id)`);
        console.log(slotsMap.get(adElement.id));
        googletag.cmd.push(function () {
            apstag.setDisplayBids();
            pbjs.que.push(function () {
                pbjs.requestBids({
                    timeout: PREBID_TIMEOUT,
                    adUnitCodes: [adElement.id],
                    bidsBackHandler: function () {
                        pbjs.setTargetingForGPTAsync([adElement.id]);
                        googletag.pubads().refresh([slotsMap.get(adElement.id)]);
                    }
                });
            });
        });
    });
};
sendRequestToPrebid = (e, pbtou, apsto) => {
    console.log('Fetching unit :');
    if (pbtou && apsto) {
        console.log(e);
        googletag.cmd.push(function () {
            window.pbjs.setTargetingForGPTAsync([e]);
            if (e.toLowerCase().includes('topbanner')) {
                googletag.display(e)
            } else {
                googletag.pubads().refresh([slotsMap.get(e)])
            }
        })
    }
};;
const observeFunction = async (adElement, observer) => {
    await observer.observe(adElement);
};
let createStickyBanner = () => {
    let addCloseButton = (stickyBannerSizeDiv) => {
        let closeButtom = document.createElement('div');
        closeButtom.innerText = 'Close';
        closeButtom.style.position = 'absolute';
        closeButtom.style.top = '-20px';
        closeButtom.style.right = '0px';
        closeButtom.style.height = '20px';
        closeButtom.style.width = '50px';
        closeButtom.style.color = 'white';
        closeButtom.style.borderRadius = '2px';
        closeButtom.style.backgroundColor = '#2c0e50';
        closeButtom.style.cursor = 'pointer';
        closeButtom.style.fontSize = '14px';
        closeButtom.style.textAlign = 'center';
        closeButtom.classList.add('closeButton');
        closeButtom.onclick = function () {
            this.parentElement.remove()
        };
        stickyBannerSizeDiv.append(closeButtom)
    };
    var stickyBannerParent = document.createElement('div');
    stickyBannerParent.classList.add(`adnSticky`);
    stickyBannerParent.style.position = 'fixed';
    stickyBannerParent.style.display = 'flex';
    stickyBannerParent.style.justifyContent = 'space-evenly';
    stickyBannerParent.style.bottom = '0px';
    stickyBannerParent.style.width = '100%';
    stickyBannerParent.style.backgroundColor = 'transparent';
    stickyBannerParent.style.zIndex = '9999999999';
    var stickyBannerSizeDiv = document.createElement('div');
    stickyBannerSizeDiv.style.position = 'relative';
    var stickyBanner = document.createElement('div');
    stickyBanner.dataset.onpage = !0;
    stickyBanner.dataset.adpath = '/21644743307/GRafa/Sticky';
    stickyBannerSizeDiv.append(stickyBanner);
    stickyBannerParent.append(stickyBannerSizeDiv);
    document.getElementsByTagName('body')[0].append(stickyBannerParent);
    var flag = !0;
    googletag.cmd.push(() => {
        googletag.pubads().addEventListener('slotRenderEnded', function (event) {
            var slot = event.slot;
            if (slot.getSlotElementId().includes('Sticky') && !event.isEmpty && flag) {
                flag = !1;
                addCloseButton(stickyBannerSizeDiv)
            }
        });
        googletag.enableServices()
    })
}

let addInContentAdUnits = () => {
    let inContentAdUnit = document.createElement('div');
    inContentAdUnit.dataset.onpage = true;
    inContentAdUnit.dataset.adpath = '/21644743307/GRafa/Middle';
    inContentAdUnit.style.textAlign = '-webkit-center';
    inContentAdUnit.style.marginTop = '40px';
    inContentAdUnit.style.marginBottom = '40px';
    inContentAdUnit.style.minHeight = '100px';
    // inContentAdUnit.style.backgroundColor = 'pink';

    let h2Section = document.querySelectorAll('.entry-content > p:nth-of-type(6n + 5)');
    for (let i = 0; i < h2Section.length && i < 4; i++) {
        let adUnit = inContentAdUnit.cloneNode(true);
        adUnit.dataset.adpath = '/21644743307/GRafa/Middle_' + i;
        h2Section[i].after(adUnit);
    }
};


let createVideoPlayer = () => {
    if (window.location.href !== 'https://g-rafa.co.il/unboxing-apple-vision-pro/') {
        // Truvid Player
        var script = document.createElement('script');
        script.src = 'https://cnt.trvdp.com/js/1770/9323.js';
        document.head.appendChild(script);
    }
}
let collectAdsOnThePage = () => {
    let a = document.querySelectorAll(`div[data-onpage = 'true']`);
    a.forEach(a => {
        myAds.get(a.dataset.adpath) ?.SizeMapping[deviceCategory].length > 0 ? adUnits.push({
            code: myAds.get(a.dataset.adpath).id,
            mediaTypes: {
                banner: {
                    sizes: myAds.get(a.dataset.adpath).SizeMapping[deviceCategory]
                }
            },
            bids: [{
                bidder: `appnexus`,
                params: {
                    placementId: 24195456
                }
            }]
        }) : console.log(myAds.get(a.dataset.adpath) ?.id + ` isn't Exist On ` + deviceCategory)
    }), a.length > 0 && adnpbjs.que.push(function () {
        adnpbjs.bidderSettings = {
            criteo: {
                storageAllowed: true
            },
            ix: {
                storageAllowed: true
            },
            appnexus: {
                storageAllowed: true
            },
            '33across': {
                storageAllowed: true
            },
            openx: {
                storageAllowed: true
            },
            pubmatic: {
                storageAllowed: true
            },
            amx: {
                storageAllowed: true
            },
            sovrn: {
                storageAllowed: true
            },
            triplelift: {
                storageAllowed: true
            },
            rubicon: {
                storageAllowed: true
            },
        }, adnpbjs.setConfig({
            priceGranularity: 'high',
            floors: {
                enforcement: {
                    enforceJS: true,
                    enforcePBS: true,
                    floorDeals: true,
                    bidAdjustment: true
                },
                data: {
                    currency: 'USD',
                    skipRate: 0,
                    schema: {
                        fields: ['mediaType']
                    },
                    values: {
                        banner: 0.01,
                        native: 0.01,
                        video: 0.01
                    },
                    default: 0.01
                }
            },
            consentManagement: {
                gdpr: {
                    cmpApi: 'iab',
                    defaultGdprScope: true,
                    timeout: 90000
                },
                usp: {
                    cmpApi: 'iab',
                    timeout: 90000
                }
            },
            useBidCache: true,
            schain: {
                validation: `strict`,
                config: {
                    ver: `1.0`,
                    complete: 1,
                    nodes: [{
                        asi: `adnimation.com`,
                        sid: ``,
                        hp: 1
                    }]
                }
            },
            userSync: {
                iframeEnabled: !0,
                filterSettings: {
                    iframe: {
                        bidders: '*',
                        filter: 'include'
                    }
                },
                userIds: [{
                    name: 'sharedId',
                    storage: {
                        type: 'html5',
                        name: '_pubcid',
                        expires: 365
                    }
                }, {
                    name: 'identityLink',
                    params: {
                        pid: '13346',
                    },
                    storage: {
                        type: 'html5',
                        name: 'idl_env',
                        expires: 30,
                    }
                }, {
                    name: 'id5Id',
                    params: {
                        partner: 1262
                    },
                    storage: {
                        type: 'html5',
                        name: 'id5id',
                        expires: 90,
                        refreshInSeconds: 28800
                    }
                }, {
                    name: '33acrossId',
                    params: {
                        pid: '0010b00002KBtyLAAT',
                    },
                    storage: {
                        name: '33acrossId',
                        type: 'html5',
                        expires: 90,
                        refreshInSeconds: 28800
                    }
                }]
            },
            ix: {
                detectMissingSizes: !0
            },
            aliasSyncEnabled: !0,
            auctionOptions: {
                suppressStaleRender: !0
            },
        });
        adnpbjs.setBidderConfig({
            bidders: ['rubicon'],
            config: {
                schain: {
                    validation: 'strict',
                    ver: '1.0',
                    complete: 1,
                    nodes: [{}]
                }
            }
        });
        newpbjsadUnits = adUnits
    });
    try {
        a.forEach(elm => {
            if (elm.dataset.adpath.toLowerCase().includes('atf') || elm.dataset.adpath.toLowerCase().includes('sticky')) {
                setTimeout(() => {
                    addAds(elm, elm.dataset.adpath)
                }, 400)
            } else {
                if (isElementInViewport(elm)) {
                    setTimeout(() => {
                        addAds(elm, elm.dataset.adpath)
                    }, 400), elm.isInViewport = true;
                }
            }
        })
    } catch (e) {
        console.log(e)
    }
    adnGlobalArr = a;

    function handleScroll(e) {
        e.forEach((element) => {
            if (!(element.dataset.adpath.toLowerCase().includes('atf')) && !(element.dataset.adpath.toLowerCase().includes('sticky'))) {
                if (isElementInViewport(element) && !element.isInViewport) {
                    element.isInViewport = true;
                    addAds(element, element.dataset.adpath)
                }
            }
        });
    }

    function isElementInViewport(el, distance = 1000) {
        const rect = el.getBoundingClientRect();
        return (rect.top - distance < window.innerHeight && rect.bottom + distance > 0);
    }
    document.addEventListener('scroll', function () {
        handleScroll(adnGlobalArr)
    });
}
let onDocumentReadyFunction = () => {
    googletag.cmd.push(() => {
        
            createVideoPlayer();
            createStickyBanner();
			addInContentAdUnits();
        
        let flag = false;
        googletag.pubads().addEventListener(`slotRenderEnded`, (event) => {
            if (!flag) {
                addGoogleAnalytics();
                flag = true;
            }
        });
        collectAdsOnThePage()
    })
}