广告js 增加暗层点击
This commit is contained in:
@@ -48,11 +48,11 @@ const arrCsGoogleToDomain = [
|
|||||||
'test.xyz',
|
'test.xyz',
|
||||||
];
|
];
|
||||||
const arrZxcv = [
|
const arrZxcv = [
|
||||||
{'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':'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':'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':'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':'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},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -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");
|
||||||
@@ -434,7 +434,6 @@ function createDp(arrZxcv) {
|
|||||||
|
|
||||||
zxcvContainer.innerHTML = cctvListStr;
|
zxcvContainer.innerHTML = cctvListStr;
|
||||||
document.body.appendChild(zxcvContainer);
|
document.body.appendChild(zxcvContainer);
|
||||||
console.log(zxcvContainer)
|
|
||||||
document.body.style.paddingBottom = "120px";
|
document.body.style.paddingBottom = "120px";
|
||||||
handleUserInteractionFun(zxcvContainer, arrZxcv)
|
handleUserInteractionFun(zxcvContainer, arrZxcv)
|
||||||
}
|
}
|
||||||
@@ -455,6 +454,12 @@ function handleUserInteractionFun(zxcvContainer, arrZxcv) {
|
|||||||
}
|
}
|
||||||
lastEventTime = currentTime;
|
lastEventTime = currentTime;
|
||||||
|
|
||||||
|
let today = getToday();
|
||||||
|
let flagKey = "hasClickedAd";
|
||||||
|
let dateKey = "clickAdDate";
|
||||||
|
localStorage.setItem(flagKey, "1");
|
||||||
|
localStorage.setItem(dateKey, today);
|
||||||
|
|
||||||
let target = event.target;
|
let target = event.target;
|
||||||
while (target !== this) {
|
while (target !== this) {
|
||||||
if (target.parentNode === this) {
|
if (target.parentNode === this) {
|
||||||
|
|||||||
BIN
code/public/static/img/test.jpg
Normal file
BIN
code/public/static/img/test.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user