const ADS_HIDE_DURATION = 120000;
document.addEventListener('DOMContentLoaded', () => {
if (localStorage.getItem('country')) {
if (localStorage.getItem('country') == 'hk') {
if (timeShouldShowAds()) {
showAdsBlock('#sticky-top-ads');
}
showAdsBlock('#under-player-ads');
// Vipads
addAdsScript('https://www.vipads.live/vn/10870D5E-77C8-1001-33-BD09A1721818.blpha');
}
} else {
fetch('https://api.country.is')
.then((response) => response.json())
.then((data) => {
const country = data.country.toLowerCase();
localStorage.setItem('country', country);
if (country == 'hk') {
if (timeShouldShowAds()) {
showAdsBlock('#sticky-top-ads');
}
showAdsBlock('#under-player-ads');
// Vipads
addAdsScript('https://www.vipads.live/vn/10870D5E-77C8-1001-33-BD09A1721818.blpha');
}
})
}
const closeAdsBtn = document.querySelector('.close-ads-btn');
if (closeAdsBtn) {
closeAdsBtn.addEventListener('click', () => {
document.querySelector('#sticky-top-ads').style.display = 'none';
localStorage.setItem('adsClosedTime', Date.now());
});
}
});
function showAdsBlock(selector, display = 'block') {
const element = document.querySelector(selector);
if (element) {
element.style.display = display;
}
}
function addAdsScript(scriptUrl, dataCfasync = null, type = null) {
var script = document.createElement('script');
script.src = scriptUrl;
script.async = true;
if (type) {
script.type = type;
}
if (dataCfasync) {
script.setAttribute('data-cfasync', dataCfasync);
}
document.body.appendChild(script);
}
function timeShouldShowAds() {
const adsClosedTime = localStorage.getItem('adsClosedTime');
if (!adsClosedTime) {
return true;
}
const currentTime = Date.now();
return (currentTime - adsClosedTime) > ADS_HIDE_DURATION;
}