function submitVote(winnerId, loserId) { const leftImage = document.querySelector('.image-option:first-child'); const rightImage = document.querySelector('.image-option:last-child'); const leftImageId = 7568; const rightImageId = 6999; const leftRating = 829.46608428554; const rightRating = 1081.6805143191; setTimeout(() => { document.getElementById('elo-left').classList.add('show'); document.getElementById('elo-right').classList.add('show'); }, 400); const kFactor = 50; let winnerRating, loserRating, winnerChange, loserChange; if (winnerId === leftImageId) { winnerRating = leftRating; loserRating = rightRating; leftImage.classList.add('winner'); rightImage.classList.add('loser'); } else { winnerRating = rightRating; loserRating = leftRating; rightImage.classList.add('winner'); leftImage.classList.add('loser'); } const expectedWinner = 1 / (1 + Math.pow(10, (loserRating - winnerRating) / 400)); winnerChange = kFactor * (1 - expectedWinner); loserChange = kFactor * (0 - (1 - expectedWinner)); if (winnerId === leftImageId) { animateELO('elo-left', leftRating, leftRating + winnerChange, true); animateELO('elo-right', rightRating, rightRating + loserChange, false); } else { animateELO('elo-right', rightRating, rightRating + winnerChange, true); animateELO('elo-left', leftRating, leftRating + loserChange, false); } setTimeout(() => { document.getElementById('winner').value = winnerId; document.getElementById('loser').value = loserId; document.forms[0].submit(); }, 2000); } function animateELO(elementId, startRating, endRating, isWinner) { const element = document.getElementById(elementId); const numberElement = element.querySelector('.elo-number'); const change = endRating - startRating; element.classList.add('show', isWinner ? 'elo-up' : 'elo-down'); const duration = 1500; const startTime = performance.now(); function updateNumber(currentTime) { const elapsed = currentTime - startTime; const progress = Math.min(elapsed / duration, 1); const easeOut = 1 - Math.pow(1 - progress, 3); const currentRating = startRating + (change * easeOut); numberElement.textContent = Math.round(currentRating); if (progress < 1) { requestAnimationFrame(updateNumber); } } requestAnimationFrame(updateNumber); } document.addEventListener('keydown', function(event) { const leftImageId = 7568; const rightImageId = 6999; if (event.key === 'ArrowLeft') { event.preventDefault(); submitVote(leftImageId, rightImageId); } else if (event.key === 'ArrowRight') { event.preventDefault(); submitVote(rightImageId, leftImageId); } else if (event.key === 'Escape') { closeModal(); } }); function enlargeImage(imageSrc) { document.getElementById('modalImage').src = imageSrc; document.getElementById('imageModal').style.display = 'block'; } function closeModal() { document.getElementById('imageModal').style.display = 'none'; }