'; // 👈 cambia "3" con l'ID del campo "Codice"
// funzione inizializzazione API
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '606',
width: '1078',
videoId: 'AzEAZS5cWTo', // tuo video
playerVars: {
'playsinline': 1,
'controls': 0,
'modestbranding': 1,
'rel': 0,
'disablekb': 1
},
events: {
'onStateChange': onPlayerStateChange
}
});
}
document.getElementById('btnPlay').addEventListener('click', () => {
player.playVideo();
document.getElementById('btnPlay').style.display = 'none';
});
// blocco anti-skip
setInterval(() => {
if (player && player.getPlayerState() === YT.PlayerState.PLAYING) {
const current = player.getCurrentTime();
if (current > maxTime) maxTime = current;
if (current - maxTime > 1.0) player.seekTo(maxTime, true);
}
}, 500);
// evento fine video
function onPlayerStateChange(event) {
if (event.data === YT.PlayerState.ENDED) {
mostraForm();
}
}
// mostra il form e genera codice
function mostraForm() {
const formWrapper = document.querySelector('.wpforms-container');
if (formWrapper) formWrapper.style.display = 'block';
const campoCodice = document.querySelector(campoCodiceSelector);
if (campoCodice) {
const now = new Date();
const pad = n => n.toString().padStart(2, '0');
const dataOra = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
const codiceRand = Math.random().toString(36).substr(2, 6).toUpperCase();
campoCodice.value = `VID-${dataOra}-${codiceRand}`;
}
}