CoolFace
Apppublic

Gbadeyanka/codecove-pay-play-programming-path

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
script.js94 linesDownload Raw Back to root
1 2// Ad timer functionality3let watchTime = 0;4let adInterval;5let currentVideo = null;6 7function startAdTimer(videoUrl) {8    currentVideo = videoUrl;9    watchTime = 0;10    clearInterval(adInterval);11    12    adInterval = setInterval(() => {13        watchTime++;14        console.log(`Watching for ${watchTime} minutes`);15        16        if (watchTime >= 20) { // Show ad after 20 minutes17            showAd();18            clearInterval(adInterval);19        }20    }, 60000); // Check every minute21}22 23function showAd() {24    const adModal = document.createElement('div');25    adModal.style.position = 'fixed';26    adModal.style.top = '0';27    adModal.style.left = '0';28    adModal.style.width = '100%';29    adModal.style.height = '100%';30    adModal.style.backgroundColor = 'rgba(0,0,0,0.9)';31    adModal.style.zIndex = '2000';32    adModal.style.display = 'flex';33    adModal.style.justifyContent = 'center';34    adModal.style.alignItems = 'center';35    adModal.style.flexDirection = 'column';36    adModal.style.color = 'white';37    38    adModal.innerHTML = `39        <h2 style="font-size: 2rem; margin-bottom: 20px;">Support CodeNext</h2>40        <p style="max-width: 500px; text-align: center; margin-bottom: 30px;">41            Enjoying our content? Consider supporting us by watching this short ad.42            This helps us create more quality tutorials.43        </p>44        <div style="width: 500px; height: 300px; background: #1e293b; 45            display: flex; justify-content: center; align-items: center;46            border-radius: 8px; margin-bottom: 20px;">47            <h3>CodeNext Advertisement</h3>48        </div>49        <button id="close-ad" style="padding: 10px 20px; background: #3b82f6; 50            color: white; border: none; border-radius: 4px; cursor: pointer;">51            Continue Watching52        </button>53    `;54    55    document.body.appendChild(adModal);56    57    // Close ad after 30 seconds automatically58    const autoClose = setTimeout(() => {59        adModal.remove();60        resetVideoPlayer();61    }, 30000);62    63    // Manual close button64    adModal.querySelector('#close-ad').addEventListener('click', () => {65        clearTimeout(autoClose);66        adModal.remove();67        resetVideoPlayer();68    });69}70 71function resetVideoPlayer() {72    if (currentVideo) {73        videoPlayer.src = currentVideo;74        startAdTimer(currentVideo); // Restart timer75    }76}77 78// Modify the video player modal to track time79document.addEventListener('DOMContentLoaded', () => {80    const originalPlayer = document.getElementById('player-modal');81    const newPlayer = originalPlayer.cloneNode(true);82    originalPlayer.parentNode.replaceChild(newPlayer, originalPlayer);83    84    newPlayer.addEventListener('click', (e) => {85        if (e.target === newPlayer || e.target.classList.contains('close-btn')) {86            clearInterval(adInterval);87            watchTime = 0;88            currentVideo = null;89        }90    });91});92 93 94