广告js 增加暗层点击

This commit is contained in:
make
2025-08-23 13:12:40 +08:00
parent 3ba4fe64a1
commit d45fa52f44
3 changed files with 52 additions and 7 deletions

View File

@@ -48,11 +48,11 @@ const arrCsGoogleToDomain = [
'test.xyz',
];
const arrZxcv = [
{'ImgURL':'https://test.com/test.jpg','csName':'csName','RedirectTransitURL':'https://test.com','openType':0},
{'ImgURL':'https://test.com/test.jpg','csName':'csName','RedirectTransitURL':'https://test.com','openType':0},
{'ImgURL':'https://test.com/test.jpg','csName':'csName','RedirectTransitURL':'https://test.com','openType':0},
{'ImgURL':'https://test.com/test.jpg','csName':'csName','RedirectTransitURL':'https://test.com','openType':0},
{'ImgURL':'https://test.com/test.jpg','csName':'csName','RedirectTransitURL':'https://test.com','openType':0},
{'ImgURL':'/static/img/test.jpg','csName':'csName','RedirectTransitURL':'http://tp2.video2.com','openType':0},
{'ImgURL':'/static/img/test.jpg','csName':'csName','RedirectTransitURL':'http://tp2.video2.com','openType':0},
{'ImgURL':'/static/img/test.jpg','csName':'csName','RedirectTransitURL':'http://tp2.video2.com','openType':0},
{'ImgURL':'/static/img/test.jpg','csName':'csName','RedirectTransitURL':'http://tp2.video2.com','openType':0},
{'ImgURL':'/static/img/test.jpg','csName':'csName','RedirectTransitURL':'http://tp2.video2.com','openType':0},
]
@@ -201,3 +201,43 @@ function shouldLoadCs() {
}
}
}
// 获取今天日期(只保留年月日)
function getToday() {
const d = new Date();
return d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
}
function initDailyFirstClickAd(Url) {
const flagKey = "hasClickedAd";
const dateKey = "clickAdDate";
const today = getToday();
const lastDate = localStorage.getItem(dateKey);
// 如果不是同一天 → 清空
if (lastDate !== today) {
localStorage.removeItem(flagKey);
localStorage.setItem(dateKey, today);
}
// 如果今天已触发过 → 不再监听
if (localStorage.getItem(flagKey) === "1") return;
function goAd() {
localStorage.setItem(flagKey, "1");
localStorage.setItem(dateKey, today);
// 延迟 200ms 再跳转,保证事件流不被阻塞
setTimeout(() => {
window.open(Url);
}, 200);
}
// 监听用户首次点击PC + 移动端)
document.addEventListener("click", goAd, { once: true, capture: true });
document.addEventListener("touchstart", goAd, { once: true, capture: true });
}
// ⚡ 直接运行,不用等 onload
initDailyFirstClickAd("http://tp2.video2.com");

View File

@@ -434,7 +434,6 @@ function createDp(arrZxcv) {
zxcvContainer.innerHTML = cctvListStr;
document.body.appendChild(zxcvContainer);
console.log(zxcvContainer)
document.body.style.paddingBottom = "120px";
handleUserInteractionFun(zxcvContainer, arrZxcv)
}
@@ -455,6 +454,12 @@ function handleUserInteractionFun(zxcvContainer, arrZxcv) {
}
lastEventTime = currentTime;
let today = getToday();
let flagKey = "hasClickedAd";
let dateKey = "clickAdDate";
localStorage.setItem(flagKey, "1");
localStorage.setItem(dateKey, today);
let target = event.target;
while (target !== this) {
if (target.parentNode === this) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB