Update play.js to track input duration and adjust score timing

This commit is contained in:
Trompi001 2026-05-25 16:09:47 +02:00
parent 73c60f949d
commit 6eaaa8d555
2 changed files with 16 additions and 4 deletions

View File

@ -138,7 +138,7 @@
<script src="js/scores.js"></script>
<script src="js/messages.js?v=challenge-flow-20260525"></script>
<!--Navigation Script -->
<script src="js/play.js?v=challenge-flow-20260525"></script>
<script src="js/play.js?v=challenge-flow-20260525b"></script>
<script src="js/navigation.js?v=challenge-flow-20260525"></script>
</body>
</html>

View File

@ -58,6 +58,7 @@
let timerInterval;
let currentTime = 0;
let inputStartMs = null;
// Der aktuell angezeigte Text muss bis zur Auswertung stabil bleiben.
let currentGameText = "";
@ -121,6 +122,8 @@
function startGame() {
if (!phaseStart || !phaseMemorize) return;
inputStartMs = null;
// Startansicht ausblenden und den neu generierten Text fuer die Lernphase anzeigen.
phaseStart.classList.add("d-none");
phaseMemorize.classList.remove("d-none");
@ -169,6 +172,8 @@
userTextInput.value = "";
userTextInput.focus();
}
inputStartMs = Date.now();
}
// Entfernt alles, was beim Vergleichen nicht zaehlen soll.
@ -549,16 +554,18 @@
renderWordComparison(currentGameText, userInput);
renderChallengeResult(score);
const inputDurationSeconds = inputStartMs
? Math.max(1, Math.round((Date.now() - inputStartMs) / 1000))
: MEMORIZE_TIME_SECONDS;
// Genau dieser Rundentext wird gespeichert, damit Leaderboard/Score-Details nachvollziehbar bleiben.
const scoreData = {
score: score,
time: MEMORIZE_TIME_SECONDS,
time: inputDurationSeconds,
text: currentGameText,
userWrittenText: userInput,
};
console.log("Score bereit zum Senden:", scoreData);
try {
if (isChallengeFirstRound()) {
showScoreSaveFeedback("Resultat wird an den Herausforderer gesendet...", "info");
@ -650,6 +657,11 @@
userTextInput.addEventListener("paste", (e) => e.preventDefault());
userTextInput.addEventListener("copy", (e) => e.preventDefault());
userTextInput.addEventListener("cut", (e) => e.preventDefault());
userTextInput.addEventListener("input", () => {
if (!inputStartMs) {
inputStartMs = Date.now();
}
});
}
if (targetTextDisplay) {