 {
return /iPhone|iPad|iPod|Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
const appScheme = )
{
const now = Date.now();
const iframe = document.createElement("iframe");
iframe.style.display = "none";
iframe.src = appScheme;
document.body.appendChild(iframe);
setTimeout(() => {
const elapsed = Date.now() - now;
document.body.removeChild(iframe);
// Nếu trình duyệt không rời trang => không có app
//alert("khong ap");
const ads = document.getElementById("popupAds");
ads.style.display = "none";
isapp=0;
if (elapsed < 200) resolve(false);
else resolve(true);
}, 500);
});
}
document.addEventListener("DOMContentLoaded", function () {
if (!isMobile()) return; // chỉ chạy trên mobile
const video = document.getElementById("mainVideo");
const ads = document.getElementById("popupAds");
const adLink = document.getElementById("adImageLink");
const hasVideo = "https://hongnhanh.com/medias/110326phutho.mp4" !== "";
const videoId = "5";
const affiliateLink = "";
const hasSeenAd = localStorage.getItem("seenAd_" + videoId);
// --- Nếu có video ---
if (hasVideo) {
if (!hasSeenAd) {
// alert(isapp);
video.addEventListener("loadeddata", function () {
});
// checkShopeeApp() ;
adLink.addEventListener("click", function (e) {
e.preventDefault();
// Đánh dấu đã xem quảng cáo
localStorage.setItem("seenAd_" + videoId, "true");
// Ẩn quảng cáo
ads.style.display = "none";
// Tiếp tục phát video (nếu được)
setTimeout(() => {
video.muted = true;
video.play().catch(() => {});
}, 500);
// Mở link aff (chỉ khi cần)
window.location.href = affiliateLink;
});
} else {
// Nếu đã xem quảng cáo
video.play().catch(()=>{});
}
}
// --- Nếu KHÔNG có video ---
else {
if (!hasSeenAd) {
setTimeout(() => {
const popup = document.createElement("div");
popup.id = "adPopup";
Object.assign(popup.style, {
position: "fixed",
top: "0",
left: "0",
width: "100%",
height: "100%",
background: "#000000d1",
display: "flex",
alignItems: "center",
justifyContent: "center",
zIndex: "9999",
});
const link = document.createElement("a");
link.href = affiliateLink;
link.target = "_blank";
const img = document.createElement("img");
img.src = "/flash-sale.jpg";
img.alt = "Quảng cáo";
img.style.maxWidth = "90%";
img.style.height = "auto";
link.appendChild(img);
popup.appendChild(link);
document.body.appendChild(popup);
link.addEventListener("click", function (e) {
e.preventDefault();
localStorage.setItem("seenAd_" + videoId, "true");
popup.remove();
window.location.href = affiliateLink;
});
}, 5000);
}
}
});