class TapADNManager { constructor() { this.bannerAd = null; this.interstitialAd = null; this.rewardedVideoAd = null; this.isSdkReady = false; this.config = { appId: 'your_taptap_app_id_here', bannerAdUnitId: 'banner_ad_unit_id', interstitialAdUnitId: 'interstitial_ad_unit_id', rewardedVideoAdUnitId: 'rewarded_video_ad_unit_id' }; this.init(); } init() { if (window.TapADN) { this.isSdkReady = true; console.log('TapADN SDK loaded successfully'); } else { console.log('TapADN SDK not loaded, using fallback mode'); } } showBannerAd(containerId = 'bannerAdContainer') { const container = document.getElementById(containerId); if (!container) { console.error('Banner ad container not found'); return; } if (this.isSdkReady && window.TapADN.BannerAd) { try { this.bannerAd = window.TapADN.createBannerAd({ adUnitId: this.config.bannerAdUnitId, style: { x: 0.5, y: 1, width: 1 }, onLoad: () => { console.log('TapADN banner ad loaded'); this.bannerAd.show(); }, onError: (err) => { console.error('TapADN banner ad error:', err); this.showFallbackBanner(container); }, onClick: () => { console.log('TapADN banner ad clicked'); }, onClose: () => { console.log('TapADN banner ad closed'); } }); this.bannerAd.load(); } catch (e) { console.error('Banner ad creation error:', e); this.showFallbackBanner(container); } } else { this.showFallbackBanner(container); } } showFallbackBanner(container) { container.innerHTML = `
🎮
精彩游戏推荐
点击查看更多
`; } onFallbackBannerClick() { console.log('Fallback banner clicked'); } hideBannerAd() { if (this.bannerAd) { try { this.bannerAd.destroy(); this.bannerAd = null; } catch (e) { console.error('Error hiding banner:', e); } } const container = document.getElementById('bannerAdContainer'); if (container) { container.innerHTML = '
广告已关闭
'; } } showInterstitialAd(onCloseCallback = null, onErrorCallback = null) { if (this.isSdkReady && window.TapADN.InterstitialAd) { try { this.interstitialAd = window.TapADN.createInterstitialAd({ adUnitId: this.config.interstitialAdUnitId, onLoad: () => { console.log('TapADN interstitial ad loaded'); this.interstitialAd.show(); }, onError: (err) => { console.error('TapADN interstitial ad error:', err); this.showFallbackInterstitial(onCloseCallback); if (onErrorCallback) onErrorCallback(err); }, onShow: () => { console.log('TapADN interstitial ad showed'); }, onClick: () => { console.log('TapADN interstitial ad clicked'); }, onClose: () => { console.log('TapADN interstitial ad closed'); this.interstitialAd = null; if (onCloseCallback) onCloseCallback(); } }); this.interstitialAd.load(); } catch (e) { console.error('Interstitial ad creation error:', e); this.showFallbackInterstitial(onCloseCallback); } } else { this.showFallbackInterstitial(onCloseCallback); } } showFallbackInterstitial(onCloseCallback) { const overlay = document.createElement('div'); overlay.id = 'fallbackInterstitial'; overlay.style.cssText = ` position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(13, 17, 23, 0.95); display: flex; justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(5px); `; const adBox = document.createElement('div'); adBox.style.cssText = ` width: 320px; height: 420px; background: linear-gradient(135deg, rgba(20, 30, 50, 0.98) 0%, rgba(10, 20, 40, 0.98) 100%); border-radius: 20px; display: flex; flex-direction: column; justify-content: center; align-items: center; position: relative; border: 1px solid rgba(100, 200, 255, 0.3); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: slideUp 0.4s ease-out; `; const style = document.createElement('style'); style.textContent = ` @keyframes slideUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } } `; document.head.appendChild(style); const closeBtn = document.createElement('button'); closeBtn.textContent = '×'; closeBtn.style.cssText = ` position: absolute; top: 15px; right: 15px; width: 32px; height: 32px; background: rgba(255, 255, 255, 0.1); border: none; border-radius: 50%; color: rgba(255, 255, 255, 0.6); font-size: 20px; cursor: pointer; transition: all 0.2s; `; closeBtn.onmouseenter = () => { closeBtn.style.background = 'rgba(255, 255, 255, 0.2)'; closeBtn.style.color = 'white'; }; closeBtn.onmouseleave = () => { closeBtn.style.background = 'rgba(255, 255, 255, 0.1)'; closeBtn.style.color = 'rgba(255, 255, 255, 0.6)'; }; closeBtn.onclick = () => { overlay.remove(); style.remove(); if (onCloseCallback) onCloseCallback(); }; const icon = document.createElement('div'); icon.innerHTML = '📱'; icon.style.marginBottom = '20px'; const title = document.createElement('div'); title.textContent = '精彩内容推荐'; title.style.cssText = 'color: white; font-size: 22px; font-weight: 700; margin-bottom: 10px; letter-spacing: 2px;'; const desc = document.createElement('div'); desc.textContent = '探索更多有趣的游戏'; desc.style.cssText = 'color: rgba(255, 255, 255, 0.6); font-size: 14px; text-align: center; margin-bottom: 30px;'; const adContent = document.createElement('div'); adContent.style.cssText = ` width: 260px; height: 160px; background: linear-gradient(135deg, #00ffcc 0%, #00aaff 50%, #ff00ff 100%); border-radius: 12px; display: flex; justify-content: center; align-items: center; margin-bottom: 25px; `; adContent.innerHTML = '🎮'; const actionBtn = document.createElement('button'); actionBtn.textContent = '立即体验'; actionBtn.style.cssText = ` padding: 12px 40px; background: linear-gradient(135deg, #00ffcc 0%, #00aaff 100%); border: none; border-radius: 25px; color: #0d1117; font-size: 16px; font-weight: 700; cursor: pointer; transition: all 0.3s; text-transform: uppercase; letter-spacing: 2px; box-shadow: 0 4px 15px rgba(0, 255, 200, 0.4); `; actionBtn.onmouseenter = () => { actionBtn.style.transform = 'translateY(-2px)'; actionBtn.style.boxShadow = '0 6px 20px rgba(0, 255, 200, 0.5)'; }; actionBtn.onmouseleave = () => { actionBtn.style.transform = 'translateY(0)'; actionBtn.style.boxShadow = '0 4px 15px rgba(0, 255, 200, 0.4)'; }; actionBtn.onclick = () => { overlay.remove(); style.remove(); if (onCloseCallback) onCloseCallback(); }; adBox.appendChild(closeBtn); adBox.appendChild(icon); adBox.appendChild(title); adBox.appendChild(desc); adBox.appendChild(adContent); adBox.appendChild(actionBtn); overlay.appendChild(adBox); document.body.appendChild(overlay); } showRewardVideoAd(onRewardedCallback = null, onCloseCallback = null, onErrorCallback = null) { if (this.isSdkReady && window.TapADN.RewardedVideoAd) { try { this.rewardedVideoAd = window.TapADN.createRewardedVideoAd({ adUnitId: this.config.rewardedVideoAdUnitId, onLoad: () => { console.log('TapADN rewarded video ad loaded'); this.rewardedVideoAd.show(); }, onError: (err) => { console.error('TapADN rewarded video ad error:', err); this.showFallbackRewardVideo(onRewardedCallback, onCloseCallback); if (onErrorCallback) onErrorCallback(err); }, onShow: () => { console.log('TapADN rewarded video ad showed'); }, onClick: () => { console.log('TapADN rewarded video ad clicked'); }, onClose: () => { console.log('TapADN rewarded video ad closed'); this.rewardedVideoAd = null; if (onCloseCallback) onCloseCallback(); }, onRewarded: () => { console.log('TapADN rewarded video ad rewarded'); if (onRewardedCallback) onRewardedCallback(); } }); this.rewardedVideoAd.load(); } catch (e) { console.error('Rewarded video ad creation error:', e); this.showFallbackRewardVideo(onRewardedCallback, onCloseCallback); } } else { this.showFallbackRewardVideo(onRewardedCallback, onCloseCallback); } } showFallbackRewardVideo(onRewardedCallback, onCloseCallback) { const overlay = document.createElement('div'); overlay.id = 'fallbackRewardVideo'; overlay.style.cssText = ` position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(13, 17, 23, 0.98); display: flex; justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(8px); `; const adBox = document.createElement('div'); adBox.style.cssText = ` width: 340px; height: 450px; background: linear-gradient(135deg, rgba(244, 63, 94, 0.95) 0%, rgba(167, 139, 250, 0.95) 100%); border-radius: 24px; display: flex; flex-direction: column; justify-content: center; align-items: center; position: relative; box-shadow: 0 20px 80px rgba(244, 63, 94, 0.3); animation: fadeInScale 0.3s ease-out; `; const style = document.createElement('style'); style.textContent = ` @keyframes fadeInScale { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } } `; document.head.appendChild(style); const closeBtn = document.createElement('button'); closeBtn.textContent = '跳过'; closeBtn.style.cssText = ` position: absolute; top: 20px; right: 20px; padding: 8px 20px; background: rgba(255, 255, 255, 0.2); border: none; border-radius: 20px; color: white; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s; `; let timeLeft = 12; let rewarded = false; const timer = document.createElement('div'); timer.id = 'rewardTimer'; timer.textContent = timeLeft.toString(); timer.style.cssText = ` color: white; font-size: 96px; font-weight: 900; margin: 20px 0; text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); `; const countdown = setInterval(() => { timeLeft--; timer.textContent = timeLeft.toString(); if (timeLeft <= 5) { closeBtn.textContent = `跳过 ${timeLeft}s`; closeBtn.style.background = 'rgba(255, 255, 255, 0.3)'; } if (timeLeft <= 0) { clearInterval(countdown); closeBtn.textContent = '领取奖励'; closeBtn.style.background = 'rgba(255, 255, 255, 0.9)'; closeBtn.style.color = '#f43f5e'; rewarded = true; } }, 1000); closeBtn.onclick = () => { clearInterval(countdown); overlay.remove(); style.remove(); if (rewarded && onRewardedCallback) { onRewardedCallback(); } if (onCloseCallback) onCloseCallback(); }; const giftIcon = document.createElement('div'); giftIcon.innerHTML = '🎁'; giftIcon.style.marginBottom = '10px'; const title = document.createElement('div'); title.textContent = '观看视频获取奖励'; title.style.cssText = 'color: white; font-size: 20px; font-weight: 700; margin-bottom: 15px; letter-spacing: 1px;'; const rewardInfo = document.createElement('div'); rewardInfo.innerHTML = '+100 金币'; rewardInfo.style.cssText = 'margin-bottom: 30px;'; const progressBar = document.createElement('div'); progressBar.style.cssText = ` width: 280px; height: 6px; background: rgba(255, 255, 255, 0.3); border-radius: 3px; overflow: hidden; `; const progressFill = document.createElement('div'); progressFill.style.cssText = ` width: ${((12 - timeLeft) / 12 * 100)}%; height: 100%; background: linear-gradient(90deg, #00ffcc 0%, #ffd700 100%); border-radius: 3px; transition: width 1s linear; `; progressBar.appendChild(progressFill); const updateProgress = () => { progressFill.style.width = `${((12 - timeLeft) / 12 * 100)}%`; }; setInterval(updateProgress, 1000); adBox.appendChild(closeBtn); adBox.appendChild(giftIcon); adBox.appendChild(title); adBox.appendChild(timer); adBox.appendChild(rewardInfo); adBox.appendChild(progressBar); overlay.appendChild(adBox); document.body.appendChild(overlay); } setAdUnitIds(bannerId, interstitialId, rewardedId) { this.config.bannerAdUnitId = bannerId || this.config.bannerAdUnitId; this.config.interstitialAdUnitId = interstitialId || this.config.interstitialAdUnitId; this.config.rewardedVideoAdUnitId = rewardedId || this.config.rewardedVideoAdUnitId; } } const tapadnManager = new TapADNManager(); function watchRewardAd() { tapadnManager.showRewardVideoAd( () => { console.log('Reward received!'); if (window.game && window.game.addCoins) { window.game.addCoins(1); } }, () => { console.log('Reward ad closed'); } ); } function checkDailyReset() { const today = new Date().toDateString(); const lastDate = localStorage.getItem('lastRewardDate'); const savedCoins = localStorage.getItem('dailyCoins'); if (lastDate !== today) { localStorage.setItem('dailyCoins', '0'); localStorage.setItem('lastRewardDate', today); if (window.game) { window.game.coins = 0; window.game.updateUI(); } } else if (savedCoins !== null && window.game) { window.game.coins = parseInt(savedCoins) || 0; window.game.updateUI(); } } function saveDailyCoins() { if (window.game) { localStorage.setItem('dailyCoins', window.game.coins.toString()); } } function showInterstitial() { tapadnManager.showInterstitialAd(); }