function initPopupAd(config){
const {adUrl, downloadUrl, waitTime} = config;
// Tạo popup HTML tự động
const popupHTML = `
`;
document.body.insertAdjacentHTML('beforeend', popupHTML);
const popup = document.getElementById("popupAd");
const btn = document.getElementById("downloadBtn");
const openAd = document.getElementById("openAd");
const closePopup = document.getElementById("closePopup");
const progress = document.getElementById("progress");
const bar = document.getElementById("bar");
btn.addEventListener("click",()=> popup.classList.add("active"));
closePopup.addEventListener("click",()=> popup.classList.remove("active"));
openAd.addEventListener("click",()=>{
window.open(adUrl,"_blank");
popup.classList.remove("active");
btn.disabled = true;
progress.style.display="block";
bar.style.width="0%";
let secs = waitTime || 15;
const totalSteps = secs * 10;
let step = 0;
const timer = setInterval(()=>{
step++;
const percent = (step / totalSteps) * 100;
bar.style.width = percent + "%";
if(step >= totalSteps){
clearInterval(timer);
btn.disabled = false;
progress.style.display="none";
window.open(downloadUrl,"_blank");
}
},100);
});
}
×
🎯 Quảng Cáo
Hãy ủng hộ bằng cách xem quảng cáo trước khi tải file. Quảng cáo sẽ mở trong tab mới.