const adsUtils = { isMobile() { return window.navigator.userAgent.match( /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|Symbian|Windows Phone)/i); }, loadJsAsync(src, async, attribute) { return new Promise((resolve, reject) => { const script = document.createElement("script"); script.src = src; script.async = async; if (attribute) { for (const key in attribute) { script.setAttribute(key, attribute[key]); } } const onload = () => { script.removeEventListener("load", onload); resolve(); }; script.addEventListener("load", onload); script.addEventListener("error", (err) => { script.removeEventListener("load", onload); console.error("loading js error: ", src, err); reject(new Error(`Failed to load ${src}`)); }); (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script); }); }, }; const adsObj = { googleAdSense: { ifLoadScript: false, loadScript({ adClientId, callbackFunc, propertyObj }) { if (!this.ifLoadScript) { const ADSENSE_URL = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js${adClientId ? '?client=' + adClientId : ''}`; adsUtils.loadJsAsync(ADSENSE_URL, true, { crossorigin: "anonymous", ...propertyObj }).then(() => { console.info("===> google ads sdk loaded"); this.ifLoadScript = true; callbackFunc && (callbackFunc instanceof Function) && callbackFunc(); }).catch((e) => { console.error(e); }); } }, displayAd() { (window.adsbygoogle = window.adsbygoogle || []).push({}); }, dealGoogleAdSize(ifLandscape) { const inses = document.querySelectorAll("ins.pageCtx_adsbygoogle"); if (inses && inses.length) { const insArray = Array.from(inses); if (insArray) { const size = { width: `300px`, height: `250px` } const width = window.innerWidth; if (width >= 340 || ifLandscape) { size.width = "336px"; size.height = "280px"; } insArray.forEach(insEle => { insEle.style.height = size.height; insEle.style.width = size.width; }) } } } }, adxAd: { ifLoadScript: false, loadScript({ adUnits, callbackFunc }) { if (!this.ifLoadScript) { const url = `https://securepubads.g.doubleclick.net/tag/js/gpt.js`; return adsUtils.loadJsAsync(url, true).then(() => { console.info("---> adx ads sdk loaded"); this.ifLoadScript = true; window.googletag = window.googletag || { cmd: [] }; const scriptEle = document.createElement("script"); scriptEle.text = this.defineAdUnitSlots(adUnits); document.getElementsByTagName("head")[0].appendChild(scriptEle); callbackFunc && (callbackFunc instanceof Function) && callbackFunc(); return this.ifLoadScript; }).catch((e) => { console.error(e); }); } else { return Promise.resolve(this.ifLoadScript); } }, showAd(type, ...params) { switch (type) { case 'banner2': this.showCommonAd2(...params); break; case 'ga': case 'zm': case 'cran': case 'and': case 'mmp': this.showCommonAd(...params); break; case 'an': this.showAN(...params); break; case 'ez': this.showEZ(...params); break; case 'cz_adx': this.showCZ_ADX(...params); break; case 'ge': this.showGE(...params); break; case 'ge2': this.showGE2(...params); break; case 'ex': this.showEX(...params); break; case 'uni': this.showUni(...params); break; case 'apo': this.showApo(...params); break; case 'inmob': this.showInmob(...params); break; default: console.log('Invalid Params'); break; } }, showInmob(...val) { // 'xxx.js', [{type:'banner', clsId'.banner-ad', placementId:'placementId'}] let jsName = val[0]; let adArr = val[1]; if (!adArr || adArr.length == 0) { return; } adsUtils.loadJsAsync('/prebid_js/' + jsName, true).then(() => { console.info("===> prebid_js loaded"); var bannerAdUnits = []; var nativeAdUnits = []; var videoAdUnits = []; for (var i = 0; i < adArr.length; i++) { var ad = adArr[i]; let container = `div-gpt-ad-${ad.placementId}-0`; if ('banner' === ad.type) { bannerAdUnits.push({ code: container, mediaTypes: { banner: { sizes: [ [300, 250] ], } }, bids: [{ bidder: 'inmobi', params: { plc: ad.placementId } }] }); } else if ('video' === ad.type) { videoAdUnits.push({ code: container, mediaTypes: { video: { context: 'outstream', playerSize: [300, 250], mimes: ["video/x-ms-wmv", "video/mp4"], minduration: 0, maxduration: 30, protocols: [1, 2], api: [1, 2, 4, 6], protocols: [3, 4, 7, 8, 10], placement: 1, plcmt: 1 } }, // Replace this object to test a new Adapter! bids: [{ bidder: 'inmobi', params: { plc: ad.placementId //Mandatory } }], renderer: { url: `https://cdn.jsdelivr.net/npm/in-renderer-js@1/dist/in-renderer.umd.min.js`, render: (bid) => { var inRenderer = new window.InRenderer(); inRenderer.render(container, bid); }, } }); } else if ('native' === ad.type) { nativeAdUnits.push({ code: container, // DOM ?? id mediaTypes: { native: { image: { required: true, sizes: [300, 250] }, clickUrl: { required: true } } }, bids: [{ bidder: 'inmobi', params: { plc: ad.placementId, bidfloor: 0.9 } }] }); } } var pbjs = window.pbjs = window.pbjs || {}; pbjs.que = pbjs.que || []; //??banner?? if (bannerAdUnits.length > 0) { pbjs.que.push(function() { pbjs.addAdUnits(bannerAdUnits); }); function renderAllAdUnits() { var winners = pbjs.getHighestCpmBids(); for (var i = 0; i < winners.length; i++) { renderOne(winners[i]); } } function renderOne(winningBid) { if (winningBid && winningBid.adId) { var div = document.getElementById(winningBid.adUnitCode); if (div) { const iframe = document.createElement('iframe'); iframe.scrolling = 'no'; iframe.frameBorder = '0'; iframe.marginHeight = '0'; iframe.marginHeight = '0'; iframe.name = `prebid_ads_iframe_${winningBid.adUnitCode}`; iframe.title = '3rd party ad content'; iframe.sandbox.add( 'allow-forms', 'allow-popups', 'allow-popups-to-escape-sandbox', 'allow-same-origin', 'allow-scripts', 'allow-top-navigation-by-user-activation' ); iframe.setAttribute('aria-label', 'Advertisment'); iframe.style.setProperty('border', '0'); iframe.style.setProperty('margin', '0'); iframe.style.setProperty('overflow', 'hidden'); div.appendChild(iframe); const iframeDoc = iframe.contentWindow.document; pbjs.renderAd(iframeDoc, winningBid.adId); const normalizeCss = `/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */button,hr,input{overflow:visible}progress,sub,sup{vertical-align:baseline}[type=checkbox],[type=radio],legend{box-sizing:border-box;padding:0}html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}details,main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:ButtonText dotted 1px}fieldset{padding:.35em .75em .625em}legend{color:inherit;display:table;max-width:100%;white-space:normal}textarea{overflow:auto}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}[hidden],template{display:none}`; const iframeStyle = iframeDoc.createElement('style'); iframeStyle.appendChild(iframeDoc.createTextNode(normalizeCss)); iframeDoc.head.appendChild(iframeStyle); } } } pbjs.que.push(function() { pbjs.requestBids({ timeout: 2000, bidsBackHandler: renderAllAdUnits }); }); } //??native?? if (nativeAdUnits.length > 0) { function renderNativeAd(slotId, native) { const html = ` `; document.getElementById(slotId).innerHTML = html; } pbjs.que.push(function() { pbjs.addAdUnits(nativeAdUnits); pbjs.requestBids({ bidsBackHandler: function(bidResponses) { nativeAdUnits.forEach(item => { const bid = pbjs.getHighestCpmBids(item.code)[0]; if (bid && bid.native) { renderNativeAd(item.code, bid.native); } }); } }); }); } //??video?? if (videoAdUnits.length > 0) { pbjs.que.push(function() { pbjs.addAdUnits(videoAdUnits); pbjs.requestBids({ timeout: 5000, bidsBackHandler: function () { videoAdUnits.forEach(item => { const bid = pbjs.getHighestCpmBids(item.code)[0]; if (bid) { pbjs.renderAd(item.code, bid.adId); } }); }, }); }) } }).catch((e) => { console.error(e); }); for (var i = 0; i < adArr.length; i++) { var ad = adArr[i]; let container = `div-gpt-ad-${ad.placementId}-0`; const bannerAdDiv = document.querySelector(ad.clsId); var tmp = document.createDocumentFragment(); const adv = document.createElement("div"); adv.className = "adv"; const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; adv.appendChild(p) const adIns = document.createElement('div'); adIns.setAttribute('id', container); // ??????? adIns.style.minWidth = '300px'; adIns.style.minHeight = '250px'; adIns.style.paddingBottom = '10px' adv.appendChild(adIns); tmp.appendChild(adv); bannerAdDiv.appendChild(tmp); } }, showCZ_ADX(...val) { let clsId = val[0]; let clientId = val[1]; let soltId = val[2]; let params = { adClientId: clientId, callbackFunc: adsObj.googleAdSense.displayAd } const bannerAdDiv = document.querySelector(clsId); var tmp = document.createDocumentFragment(); const adv = document.createElement("div"); adv.className = "adv"; const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; adv.appendChild(p) const adIns = document.createElement('ins'); adIns.style.display = 'block'; adIns.setAttribute('class', 'adsbygoogle'); adIns.setAttribute('data-ad-client', clientId); adIns.setAttribute('data-ad-slot', soltId); adIns.setAttribute('data-ad-format', 'auto'); adIns.setAttribute('data-full-width-responsive', 'true'); adv.appendChild(adIns); tmp.appendChild(adv); bannerAdDiv.appendChild(tmp); adsObj.googleAdSense.loadScript(params) }, showCommonAd(...params) { const gameboxHeadAdOptions = { "adUnitCode": params[0], "elementId": params[1], "size": [300, 250] }; const adUnits = [{ adUnitCode: gameboxHeadAdOptions.adUnitCode, size: gameboxHeadAdOptions.size || [300, 250], elementId: gameboxHeadAdOptions.elementId || "div-gpt-ad-1" }]; if (params.length > 2) { adUnits.push({ adUnitCode: params[2], type: "INTERSTITIAL", }); } adsObj.adxAd.loadScript({ adUnits: adUnits }).then(flag => { if (flag) { adsObj.adxAd.addAdToContainer( gameboxHeadAdOptions.elementId || "div-gpt-ad-1", ".banner-ad", false, { style: 'min-width:300px;min-height:250px;text-align:center;margin-bottom:8px;' } ); } }); }, //banner2 ???? showCommonAd2(...params) { const gameboxHeadAdOptions = { "adUnitCode": params[0], "elementId": params[1], "size": [300, 250] }; const adUnits = [{ adUnitCode: gameboxHeadAdOptions.adUnitCode, size: gameboxHeadAdOptions.size || [300, 250], elementId: gameboxHeadAdOptions.elementId || "div-gpt-ad-2" }]; adsObj.adxAd.loadScript({ adUnits: adUnits }).then(flag => { if (flag) { adsObj.adxAd.addAdToContainer( gameboxHeadAdOptions.elementId || "div-gpt-ad-2", ".banner2-ad", false, { style: 'min-width:300px;min-height:250px;text-align:center;margin-bottom:8px;' } ); } }); }, showAN(...params) { let jsArr = [{ src: params[0], type: 'application/javascript', crossorigin: "anonymous" }]; this.loadJsScript(jsArr); }, showEZ(...params) { let jsArr = [{ src: "https://the.gatekeeperconsent.com/cmp.min.js", type: 'application/javascript', "data-cfasync": false }, { src: "//www.ezojs.com/ezoic/sa.min.js", type: 'application/javascript' }]; this.loadJsScript(jsArr); let jsCode = ` window.ezstandalone = window.ezstandalone || {}; ezstandalone.cmd = ezstandalone.cmd || []; `; this.addJsCodeToHead(jsCode); const containerEle = document.querySelector('.banner-ad'); if (containerEle) { var tmp = document.createDocumentFragment(); const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; tmp.appendChild(p) const adv = document.createElement("div"); adv.setAttribute("id", "ezoic-pub-ad-placeholder-" + params[0]); // adv.className = "adv"; tmp.appendChild(adv); containerEle.appendChild(tmp); var script = document.createElement('script'); script.innerHTML = ` ezstandalone.cmd.push(function() { ezstandalone.showAds(` + params[0] + `) }); `; containerEle.appendChild(script); } }, showGE(...params) { let jsArr = [{ src: params[0], async: "true" }, { src: 'https://securepubads.g.doubleclick.net/tag/js/gpt.js', async: "true" }, ]; let jsCode = ` window.gnshbrequest = window.gnshbrequest || {cmd:[]}; window.gnshbrequest.cmd.push(function(){ window.gnshbrequest.forceInternalRequest(); }); `; this.addJsCodeToHead(jsCode); this.loadJsScript(jsArr); this.addGeContainer(params[1], '.banner-ad', true); if (params.length > 2) { this.addGeContainer(params[2], '.inner-ad', false); } }, showGE2(...params) { let jsArr = [{ src: params[0], async: "true" }, { src: 'https://securepubads.g.doubleclick.net/tag/js/gpt.js', async: "true" }, ]; let jsCode = ` window.gnshbrequest = window.gnshbrequest || {cmd:[]}; window.gnshbrequest.cmd.push(function(){ window.gnshbrequest.forceInternalRequest(); }); `; this.addJsCodeToHead(jsCode); this.loadJsScript(jsArr); this.addGeContainer(params[1], '.inner-ad', false); }, showEX(...params) { const containerEle = document.querySelector('.banner-ad'); if (containerEle) { var tmp = document.createDocumentFragment(); const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; tmp.appendChild(p) const adv = document.createElement("div"); adv.setAttribute("data-adunitid", params[0]); adv.className = "adv gptslot"; tmp.appendChild(adv); containerEle.appendChild(tmp); } var linkTags = [{ rel: 'dns-prefetch', href: '//exmarketplace.com' }, { rel: 'preconnect', href: '//cdn.exmarketplace.com' }, { rel: 'preconnect', href: '//securepubads.g.doubleclick.net' } ]; var fragment = document.createDocumentFragment(); linkTags.forEach(function(tag) { var link = document.createElement('link'); Object.keys(tag).forEach(function(key) { link.setAttribute(key, tag[key]); }); fragment.appendChild(link); }); document.head.appendChild(fragment); let jsArr = [{ src: params[1], async: true, defer: true }]; this.loadJsScript(jsArr); }, showUni(...params) { const containerEle = document.querySelector('.banner2-ad'); if (containerEle) { var tmp = document.createDocumentFragment(); const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; tmp.appendChild(p) const adv = document.createElement("div"); adv.setAttribute("id", params[0]); adv.className = "adv"; tmp.appendChild(adv); containerEle.appendChild(tmp); } var script = document.createElement('script'); script.innerHTML = ` window.unibotshb = window.unibotshb || { cmd: [] }; unibotshb.cmd.push(()=>{ ubHB("` + params[1] + `"); }); `; document.body.appendChild(script); let jsArr = [{ src: params[2], async: true, defer: true }]; this.loadJsScript(jsArr); }, showApo(...params) { const containerEle = document.querySelector('.banner-ad'); if (containerEle) { var tmp = document.createDocumentFragment(); const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; tmp.appendChild(p) const adv = document.createElement("div"); adv.setAttribute("id", params[0]); adv.className = "adv"; tmp.appendChild(adv); containerEle.appendChild(tmp); } let jsArr = [{ src: params[1], async: true, defer: true }]; this.loadJsScript(jsArr); }, loadJsScript(jsObjArr) { if (jsObjArr && jsObjArr.length > 0) { for (let js of jsObjArr) { adsUtils.loadJsAsync(js.src, true, js) } } }, addGeContainer(id, containerId, isBannerAd, propertyObj) { const adEle = document.createElement("div"); adEle.setAttribute("data-cptid", id); adEle.style.display = 'block'; if (propertyObj) { for (const key in propertyObj) { if (Object.hasOwnProperty.call(propertyObj, key)) { const value = propertyObj[key]; adEle.setAttribute(key, value); } } } const scriptEle = document.createElement("script"); scriptEle.text = ` window.gnshbrequest.cmd.push(function() { window.gnshbrequest.applyPassback("${id}", "[data-cptid='${id}']"); }); ` adEle.appendChild(scriptEle); const containerEle = document.querySelector(`${containerId}`); if (containerEle) { if (isBannerAd) { const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; containerEle.appendChild(p) const adv = document.createElement("div"); adv.className = "adv"; adv.appendChild(adEle); containerEle.appendChild(adv); } else { containerEle.appendChild(adEle); } } return Promise.resolve(adEle); }, addJsCodeToHead(jsCode) { const scriptEle = document.createElement("script"); scriptEle.text = jsCode; document.getElementsByTagName("head")[0].appendChild(scriptEle); }, addAdToContainer(id, containerId, propertyObj) { const adEle = document.createElement("div"); adEle.setAttribute("id", id); if (propertyObj) { for (const key in propertyObj) { if (Object.hasOwnProperty.call(propertyObj, key)) { const value = propertyObj[key]; adEle.setAttribute(key, value); } } } const scriptEle = document.createElement("script"); scriptEle.text = `googletag.cmd.push(function() { googletag.display('${id}'); });` adEle.appendChild(scriptEle); const containerEle = document.querySelector(`${containerId}`); if (containerEle) { const p = document.createElement("p"); p.className = "ad-tips-top"; p.innerText = "Advertisement"; containerEle.appendChild(p) const adv = document.createElement("div"); adv.className = "adv"; adv.appendChild(adEle); containerEle.appendChild(adv); } return Promise.resolve(adEle); }, defineAdUnitSlots(adUnits = []) { const notDislayTypes = ['INTERSTITIAL', 'TOP_ANCHOR', 'BOTTOM_ANCHOR']; const outOfPageAdUnits = adUnits.filter(adUnit => notDislayTypes.includes(adUnit.type)); const displayAdUnits = adUnits.filter(adUnit => !notDislayTypes.includes(adUnit.type)); const outOfPageSlotStr = outOfPageAdUnits.map((adUnit, index) => { return ` const outOfPageSlot_${index} = googletag.defineOutOfPageSlot( '${adUnit.adUnitCode}', googletag.enums.OutOfPageFormat['${adUnit.type}']); if (outOfPageSlot_${index}) { outOfPageSlot_${index}.addService(googletag.pubads()); } ` }).join('\n') const slotStr = displayAdUnits.map(adUnit => { if (!(adUnit.adUnitCode && adUnit.size && adUnit.elementId)) { return ''; } return `googletag.defineSlot( "${adUnit.adUnitCode}", ${JSON.stringify(adUnit.size)}, "${adUnit.elementId}").addService(googletag.pubads());`; }).join('\n') return `googletag.cmd.push(function() { ${outOfPageSlotStr} ${slotStr} googletag.pubads().enableSingleRequest(); googletag.pubads().collapseEmptyDivs(); googletag.enableServices(); })` }, } } jQuery(document).ready(function() {});