-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (112 loc) · 3.48 KB
/
Copy pathscript.js
File metadata and controls
132 lines (112 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
let words = [];
let usedWords = [];
let currentWord = null;
async function loadWords() {
try {
const response = await fetch('dataset.json');
if (!response.ok) {
throw new Error('Errore nel caricamento del dataset.');
}
words = await response.json();
} catch (error) {
console.error('Errore:', error);
alert('Impossibile caricare il dataset delle parole. Controlla il file dataset.json.');
}
}
function generateWord() {
if (words.length === 0) {
alert('Tutte le parole sono state estratte!');
currentWord = null;
document.getElementById('word-display').textContent = 'Nessuna parola disponibile.';
return;
}
const randomIndex = Math.floor(Math.random() * words.length);
currentWord = words.splice(randomIndex, 1)[0]; // Rimuovi parola selezionata
usedWords.push(currentWord);
// Mostra la parola
const wordDisplay = document.getElementById('word-display');
wordDisplay.textContent = currentWord;
wordDisplay.classList.add('active');
setTimeout(() => wordDisplay.classList.remove('active'), 300);
}
function handleCorrect() {
if (!currentWord) {
alert('Nessuna parola da classificare!');
return;
}
addToTable('correct-body', currentWord);
generateWord(); // Genera una nuova parola
}
function handleWrong() {
if (!currentWord) {
alert('Nessuna parola da classificare!');
return;
}
addToTable('wrong-body', currentWord);
generateWord(); // Genera una nuova parola
}
function addToTable(tableId, word) {
const tableBody = document.getElementById(tableId);
const newRow = document.createElement('tr');
const newCell = document.createElement('td');
newCell.textContent = word;
newRow.appendChild(newCell);
tableBody.appendChild(newRow);
}
let timer = 120;
let timerInterval = null;
let isRunning = false;
// Aggiorna il display del timer
function updateTimerDisplay() {
document.getElementById('timer-display').textContent = timer;
}
// Gestisci avvio/pausa del timer
function toggleTimer() {
if (isRunning) {
clearInterval(timerInterval);
timerInterval = null;
isRunning = false;
document.getElementById('start-pause-btn').textContent = 'Avvia';
} else {
timerInterval = setInterval(() => {
if (timer > 0) {
timer--;
updateTimerDisplay();
} else {
clearInterval(timerInterval);
timerInterval = null;
isRunning = false;
document.getElementById('start-pause-btn').textContent = 'Avvia';
alert('Tempo scaduto!');
}
}, 1000);
isRunning = true;
document.getElementById('start-pause-btn').textContent = 'Pausa';
}
}
// Aggiungi 5 secondi
function addTime() {
timer += 5;
updateTimerDisplay();
}
// Rimuovi 5 secondi
function removeTime() {
if (timer > 5) {
timer -= 5;
} else {
timer = 0;
}
updateTimerDisplay();
}
// Event listeners per i pulsanti del timer
document.getElementById('start-pause-btn').addEventListener('click', toggleTimer);
document.getElementById('add-time-btn').addEventListener('click', addTime);
document.getElementById('remove-time-btn').addEventListener('click', removeTime);
// Inizializza il display del timer
updateTimerDisplay();
// Event listeners
document.getElementById('generate-btn').addEventListener('click', generateWord);
document.getElementById('correct-btn').addEventListener('click', handleCorrect);
document.getElementById('wrong-btn').addEventListener('click', handleWrong);
// Carica parole al caricamento della pagina
window.addEventListener('load', loadWords);