// 资源预加载
const imageUrls = [
'./img/logo.svg',
'./img/pgOct.png',
'./img/coupon.png',
'./img/money.png',
'./img/play.png',
'./img/exquisite.png',
'./img/bg.png',
'./img/roleta.gif'
];
// 预加载所有图片
function preloadImages(urls,callback) {
let loadedCount = 0;
const total = urls.length;
if (total === 0) {
callback();
return;
}
urls.forEach(url => {
const img = new Image();
img.onload = img.onerror = () => {
loadedCount++;
if (loadedCount === total) {
callback();
}
};
img.src = url;
});
}
// 初始化函数
function initApp() {
// 初始化背景粒子
initParticleBackground();
// 初始化主应用逻辑
initMainApp();
}
// 初始化粒子背景
function initParticleBackground() {
const canvas = document.getElementById('particle-background');
const ctx = canvas.getContext('2d');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
window.addEventListener('resize',resizeCanvas);
resizeCanvas();
// 生成粒子数组
const particlesArr = [];
const particleCount = 100;
for (let i = 0; i < particleCount; i++) {
particlesArr.push({
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
radius: Math.random() * 2 + 1,
vx: (Math.random() - 0.5) * 0.7,
vy: (Math.random() - 0.5) * 0.7
});
}
function animateParticles() {
ctx.clearRect(0,0,canvas.width,canvas.height);
// 绘制粒子
particlesArr.forEach(p => {
p.x += p.vx;
p.y += p.vy;
// 边界反弹
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
ctx.beginPath();
ctx.arc(p.x,p.y,p.radius,0,Math.PI * 2);
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
ctx.fill();
});
// 绘制连线
for (let i = 0; i < particlesArr.length; i++) {
for (let j = i + 1; j < particlesArr.length; j++) {
const p1 = particlesArr[i];
const p2 = particlesArr[j];
const dx = p1.x - p2.x;
const dy = p1.y - p2.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 100) {
ctx.strokeStyle = `rgba(255, 255, 255, ${(100 - dist) / 100 * 0.2})`;
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(p1.x,p1.y);
ctx.lineTo(p2.x,p2.y);
ctx.stroke();
}
}
}
requestAnimationFrame(animateParticles);
}
animateParticles();
}
// 主应用逻辑
function initMainApp() {
const particlesContainer = document.getElementById('particles');
const tensDigit = document.getElementById('tens-digit');
const onesDigit = document.getElementById('ones-digit');
const treasureBox = document.getElementById('treasureBox');
const prize = document.getElementById('prize');
const prizeModal = document.getElementById('prizeModal');
const modalPrize = document.getElementById('modalPrize');
const countdown = document.getElementById('countdown');
const winnersList = document.getElementById('winnersList');
// 配置跳转链接
const urlArr = [
'https://img.blessx.com/static/apk/Probet_adx01.apk',
'https://offer.alibaba.com/cps/14i5a7rj?bm=cps&src=saf',
'https://s.click.aliexpress.com/e/_c3m8K90X?bz=300*250',
'https://app.appsflyer.com/com.alibaba.wireless?pid=feeltapmedia&af_siteid=dsp_01&c=dsp_br_01&af_sub_siteid={sub4}&af_c_id=202510231517001&af_ad=1688_banner_01&af_ad_id=uu112&af_adset={bundle}&af_adset_id=3453453&af_ad_type=banner&af_channel=901&af_cost_currency=USD&af_cost_model=cpi&af_cost_value=0.1&af_click_lookback=7d&af_prt=feeltapmedia&af_media_type=banner&is_retargeting=true&af_reengagement_window=30d'
];
// 奖品列表
const prizes = [
{ type: "coupon",name: "💰 Cupom de R $30",value: "💰 Cupom de R $30" },
{ type: "coupon",name: "💰 Cupom de R $50元",value: "💰 Cupom de R $50" },
{ type: "coupon",name: "💰 Cupom de R $100",value: "💰 Cupom de R $100" },
{ type: "coupon",name: "💰 Cupom de R $500",value: "💰 Cupom de R $500" },
{ type: "coupon",name: "💰 Cupom de R 1000",value: "💰 Cupom de R $1000" },
{ type: "discount",name: "🎟️ 20% OFF",value: "🎟️ 20% OFF" },
{ type: "discount",name: "🎟️ 30% OFF",value: "🎟️ 30% OFF" },
{ type: "discount",name: "🎟️ 40% OFF",value: "🎟️ 40% OFF" },
{ type: "discount",name: "🎟️ 50% OFF",value: "🎟️ 50% OFF" },
{ type: "discount",name: "🧰 Tesouro do amigo!",value: "🧰 Tesouro do amigo!" },
{ type: "gift",name: "🎁 Surpresa especial!",value: "🎁 Surpresa especial!" }
];
let isOpened = false;
let countdowns = 30;
let countdownInterval;
let isRunning = false;
let isOneClick = 0
// 从localStorage恢复倒计时状态
if (localStorage.getItem('downsTime') && localStorage.getItem('downsTime') > 0) {
countdowns = parseInt(localStorage.getItem('downsTime'));
document.querySelector(".countdown-container").style.display = 'flex';
startCountdown();
isOpened = true;
isRunning = true;
treasureBox.classList.add('disabled');
} else {
document.querySelector(".countdown-container").style.display = 'none';
countdowns = 30;
}
// 宝箱点击事件
treasureBox.addEventListener('click',function() {
if (isOpened) return;
isOneClick++
countdowns = 30;
tensDigit.style.animation = '';
onesDigit.style.animation = '';
document.querySelector(".countdown-container").style.display = 'flex';
isOpened = true;
treasureBox.classList.add('disabled');
startCountdown();
// 随机选择一个奖品
const randomPrize = prizes[Math.floor(Math.random() * prizes.length)];
document.querySelector('.treasure-base').classList.add('open');
// 更新奖品显示
prize.textContent = randomPrize.value;
prize.className = `prize ${randomPrize.type}`;
// 显示奖品弹出动画
setTimeout(() => {
prize.classList.add('show');
document.querySelector('.treasure-container').style.zIndex = 1
createConfetti();
setTimeout(() => {
document.querySelector(".pointerImg").style.display = "block";
},500);
},800);
// 显示弹窗
setTimeout(() => {
modalPrize.textContent = randomPrize.name;
prizeModal.style.display = 'flex';
// 开始倒计时
let seconds = 2;
countdown.textContent = `Página redirecionará em ${seconds} segundos...`;
const modalCountdownInterval = setInterval(() => {
seconds--;
if (seconds > 0) {
countdown.textContent = `Página redirecionará em ${seconds} segundos...`;
} else {
clearInterval(modalCountdownInterval);
prizeModal.style.display = 'none';
document.querySelector(".pointerImg").style.display = "none";
// 跳转到指定链接
const randomHref = urlArr[Math.floor(Math.random() * urlArr.length)];
// 跳转到指定链接
window.location.href = isOneClick == 1 ? urlArr[0] : randomHref;
}
},1000);
},1500);
});
// 中奖名单数据
const winners = [
{ name: "Lucas**",prize: "🎁",time: "recebeu um presente incrível há 1 minuto!" },
{ name: "Mariana**",prize: "💸",time: "ganhou um bônus de 50 reais há 5 minutos!" },
{ name: "Rafael**",prize: "📱",time: "ganhou um iPhone 14 há 10 minutos!" },
{ name: "Camila**",prize: "🕹️",time: "recebeu itens de jogo incríveis há 23 minutos!" },
{ name: "Gustavo**",prize: "🏆",time: "ganhou um prêmio de 1000 dólares há 38 minutos!" },
{ name: "Gabriel**",prize: "💸",time: "ganhou um bônus de 100 reais há 44 minutos!" },
{ name: "Marco**",prize: "🕹️",time: "recebeu itens de jogo incríveis há 56 minutos!" },
{ name: "João**",prize: "🎁",time: "recebeu um presente incrível há 1 hora!" }
];
initWinnersList();
// 初始化中奖名单
function initWinnersList() {
winnersList.innerHTML = '';
const container = document.createElement('div');
container.className = 'winner-items-container';
// 复制一份中奖名单,以实现更平滑的循环
const extendedWinners = [...winners,...winners];
extendedWinners.forEach(winner => {
const winnerItem = document.createElement('div');
winnerItem.className = 'winner-item';
winnerItem.innerHTML = `
<div class="winner-prize">${winner.prize}</div>
<div class="winner-name">${winner.name}</div>
<div class="winner-time">${winner.time}</div>
`;
container.appendChild(winnerItem);
});
winnersList.appendChild(container);
}
// 创建五彩纸屑效果
function createConfetti() {
const colors = ['#ff0000','#00ff00','#0000ff','#ffff00','#ff00ff','#00ffff'];
const container = document.querySelector('.treasure-container');
for (let i = 0; i < 100; i++) {
const confetti = document.createElement('div');
confetti.className = 'confetti';
// 随机颜色
const color = colors[Math.floor(Math.random() * colors.length)];
confetti.style.backgroundColor = color;
// 随机位置
const startX = Math.random() * 200 - 100 + treasureBox.offsetLeft + treasureBox.offsetWidth / 2;
const startY = treasureBox.offsetTop + 200;
confetti.style.left = startX + 'px';
confetti.style.top = startY + 'px';
container.appendChild(confetti);
// 随机动画参数
const angle = Math.random() * Math.PI * 2;
const velocity = 2 + Math.random() * 3;
const rotation = Math.random() * 720 - 360;
const size = 5 + Math.random() * 10;
confetti.style.width = size + 'px';
confetti.style.height = size + 'px';
// 动画
const animation = confetti.animate([
{
transform: `translate(0, 0) rotate(0deg)`,
opacity: 1
},
{
transform: `translate(${Math.cos(angle) * 100}px, -${150 + Math.random() * 200}px) rotate(${rotation}deg)`,
opacity: 0
}
],{
duration: 1000 + Math.random() * 1000,
easing: 'cubic-bezier(0.1, 0.8, 0.2, 1)'
});
// 动画结束后移除元素
animation.onfinish = () => {
confetti.remove();
};
}
}
// 创建粒子效果
function createParticles(x,y,count = 10) {
for (let i = 0; i < count; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
// 随机位置
const offsetX = (Math.random() - 0.5) * 100;
const offsetY = (Math.random() - 0.5) * 100;
particle.style.left = `${x + offsetX}px`;
particle.style.top = `${y + offsetY}px`;
// 随机动画参数
const size = Math.random() * 3 + 1;
const duration = Math.random() * 1 + 0.5;
const delay = Math.random() * 0.5;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
particle.style.animation = `particleFloat ${duration}s ease-out ${delay}s forwards`;
// 添加到容器
particlesContainer.appendChild(particle);
// 移除粒子
setTimeout(() => {
particle.remove();
},(duration + delay) * 1000);
}
}
// 添加粒子浮动动画
const styleSheet = document.styleSheets[0];
styleSheet.insertRule(`
@keyframes particleFloat {
0% {
transform: translate(0, 0);
opacity: 1;
}
100% {
transform: translate(${Math.random() * 100 - 50}px, ${Math.random() * -100 - 50}px);
opacity: 0;
}
}
`,styleSheet.cssRules.length);
// 更新数字显示
function updateDisplay() {
const tens = Math.floor(countdowns / 10);
const ones = countdowns % 10;
// 添加翻转动画
if (tensDigit.textContent !== tens.toString()) {
tensDigit.classList.remove('flip');
void tensDigit.offsetWidth; // 触发重排
tensDigit.classList.add('flip');
tensDigit.textContent = tens;
// 在十位数变化时添加粒子效果
const rect = tensDigit.getBoundingClientRect();
createParticles(rect.left + rect.width / 2,rect.top + rect.height / 2,15);
}
if (onesDigit.textContent !== ones.toString()) {
onesDigit.classList.remove('flip');
void onesDigit.offsetWidth; // 触发重排
onesDigit.classList.add('flip');
onesDigit.textContent = ones;
// 在个位数变化时添加粒子效果
const rect = onesDigit.getBoundingClientRect();
createParticles(rect.left + rect.width / 2,rect.top + rect.height / 2,15);
}
}
// 开始倒计时
function startCountdown() {
if (isRunning) return;
isRunning = true;
countdownInterval = setInterval(() => {
countdowns--;
localStorage.setItem('downsTime',countdowns);
updateDisplay();
isOpened = true;
if (countdowns <= 1) {
clearInterval(countdownInterval);
isOpened = false;
isRunning = false;
// 倒计时结束效果
tensDigit.style.animation = 'pulse 0.5s infinite';
onesDigit.style.animation = 'pulse 0.5s infinite';
// 创建大量粒子
for (let i = 0; i < 50; i++) {
setTimeout(() => {
const rect1 = tensDigit.getBoundingClientRect();
const rect2 = onesDigit.getBoundingClientRect();
createParticles(rect1.left + rect1.width / 2,rect1.top + rect1.height / 2,5);
createParticles(rect2.left + rect2.width / 2,rect2.top + rect2.height / 2,5);
},i * 50);
}
setTimeout(() => {
prize.classList.remove('show');
document.querySelector('.treasure-container').style.zIndex = 0
document.querySelector('.treasure-base').classList.remove('open');
isOpened = false;
isRunning = false;
treasureBox.classList.remove('disabled');
document.querySelector(".countdown-container").style.display = 'none';
localStorage.setItem('downsTime',0);
tensDigit.innerHTML = '3';
onesDigit.innerHTML = '0';
},1000);
}
},1000);
}
}
// 预加载图片后初始化应用
preloadImages(imageUrls,initApp);将这段代码中的巴西语翻译成繁体字