(function () {
window.googletag = window.googletag || { cmd: [] };
var wave_gpt = document.createElement("script");
wave_gpt.src = "https://securepubads.g.doubleclick.net/tag/js/gpt.js";
wave_gpt.async = true;
document.head.appendChild(wave_gpt);
var wave_gpt2 = document.createElement("script");
wave_gpt2.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6327508837875273";
wave_gpt2.async = true;
wave_gpt2.crossOrigin = "anonymous";
document.head.appendChild(wave_gpt2);
googletag.cmd.push(function () {
googletag.setConfig({
lazyLoad: {
fetchMarginPercent: 100,
renderMarginPercent: 50,
mobileScaling: 2.0
}
});
googletag.enableServices();
});
})();
function waitForElement(className, callback, timeout = 10000) {
const interval = 100;
let elapsed = 0;
const checkExist = setInterval(function () {
const el = document.getElementsByClassName(className)[0];
if (el) {
clearInterval(checkExist);
callback(el);
} else if (elapsed >= timeout) {
clearInterval(checkExist);
}
elapsed += interval;
}, interval);
}
function waitForDivAndDisplay(divId, callback) {
if (document.getElementById(divId)) {
callback();
return;
}
const observer = new MutationObserver(function () {
if (document.getElementById(divId)) {
observer.disconnect();
callback();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
function prepareAd(adunit, adcode, slotID, defineSlotFn) {
waitForElement(adunit, function (el) {
if (adcode) {
el.insertAdjacentHTML("afterend", adcode);
}
waitForDivAndDisplay(slotID, function () {
defineSlotFn(slotID);
});
});
}
function defineSlotAndDisplay(slotID, slotPath, sizes) {
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(function () {
const slot = googletag.defineSlot(
slotPath,
sizes,
slotID
);
if (!slot) {
console.warn("GPT defineSlot failed:", slotID);
return;
}
slot
.setTargeting("website", location.hostname)
.setTargeting("url", location.pathname)
.addService(googletag.pubads());
googletag.display(slotID);
});
}
function defineMobileBottomSlot(slotID) {
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(function () {
const slot = googletag.defineSlot(
"/22675675822/ddroom_mobile_bottom",
[
[320, 100],
[1, 1]
],
slotID
);
if (!slot) {
console.warn("GPT defineSlot failed:", slotID);
return;
}
slot
.setTargeting("website", location.hostname)
.setTargeting("url", location.pathname)
.addService(googletag.pubads());
const renderListener = function (event) {
if (event.slot !== slot) {
return;
}
if (event.isEmpty) {
return;
}
const adContainer = document.querySelector(".ad");
if (!adContainer) {
return;
}
if (adContainer.querySelector(".wave-ad-close")) {
return;
}
const closeButton = document.createElement("button");
closeButton.className = "wave-ad-close";
closeButton.innerHTML =
'';
closeButton.setAttribute(
"style",
[
"position:absolute",
"top:0px",
"left:5px",
"background-color:rgba(0,0,0,0)",
"border:none",
"padding:0",
"height:30px",
"width:30px",
"z-index:10000",
"cursor:pointer"
].join(";")
);
closeButton.addEventListener("click", function () {
adContainer.remove();
});
adContainer.appendChild(closeButton);
};
googletag.pubads().addEventListener(
"slotRenderEnded",
renderListener
);
googletag.display(slotID);
});
}
function runAds() {
const isMobile =
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
.test(navigator.userAgent);
if (
!isMobile &&
/search|object/.test(location.href)
) {
prepareAd(
"ddroom_sb_1",
'