-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
132 lines (112 loc) · 5.03 KB
/
js.js
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
// Function to change language
function changeLanguage(lang) {
const storedColors = localStorage.getItem('backgroundColors');
if (lang === 'es') {
// Spanish language selected
if (storedColors) {
const { red, green } = JSON.parse(storedColors);
// Translate content and apply stored colors for Spanish language
translateContentToSpanish();
changeRedAndGreenColors(red, green); // Apply stored colors for Spanish
} else {
translateContentToSpanish();
changeRedAndGreenColors('red', 'green'); // Reset colors to default for Spanish
}
} else {
// Default to English or other languages
if (storedColors) {
const { red, green } = JSON.parse(storedColors);
changeRedAndGreenColors(red, green); // Apply stored colors for default language
} else {
changeRedAndGreenColors('red', 'green'); // Reset colors to default for other languages
}
// Translate content for other languages if needed
// translateContentToOtherLanguage();
}
}
// Function to translate content to Spanish
function translateContentToSpanish() {
// Change text content, classes, or other elements to Spanish here
document.getElementById('title').textContent = 'Bienvenido a la Aplicación de Preguntas';
document.getElementById('start-button').textContent = 'Comenzar';
document.querySelector('.content h2').textContent = 'Inicio'; // Translate 'Home' title within .content
// Translate other elements to Spanish as needed
}
// Apply language on page load
document.addEventListener('DOMContentLoaded', function() {
// Fetch the selected language from local storage
const selectedLanguage = localStorage.getItem('selectedLanguage');
if (selectedLanguage) {
changeLanguage(selectedLanguage);
// Set the selected language in the dropdown
document.getElementById('language-select').value = selectedLanguage;
}
});
// Event listener for language change in dropdown
document.getElementById('language-select').addEventListener('change', function(event) {
const selectedLanguage = event.target.value;
localStorage.setItem('selectedLanguage', selectedLanguage);
changeLanguage(selectedLanguage);
});
// New code for changing content based on language selection
function changeLanguage(lang) {
if (lang === 'es') {
document.getElementById('title-en').style.display = 'none';
document.getElementById('title-es').style.display = 'block';
document.getElementById('start-button-en').style.display = 'none';
document.getElementById('start-button-es').style.display = 'block';
document.getElementById('high-scores-button-en').style.display = 'none';
document.getElementById('high-scores-button-es').style.display = 'block';
document.querySelector('.content h2').textContent = 'Inicio'; // Translate 'Home' title to Spanish
} else {
document.getElementById('title-en').style.display = 'block';
document.getElementById('title-es').style.display = 'none';
document.getElementById('start-button-en').style.display = 'block';
document.getElementById('start-button-es').style.display = 'none';
document.getElementById('high-scores-button-en').style.display = 'block';
document.getElementById('high-scores-button-es').style.display = 'none';
document.querySelector('.content h2').textContent = 'Home'; // Translate 'Home' title to English
}
}
// Apply language change on page load if selected
document.addEventListener('DOMContentLoaded', function() {
const selectedLanguage = localStorage.getItem('selectedLanguage');
if (selectedLanguage) {
changeLanguage(selectedLanguage);
document.getElementById('language-select').value = selectedLanguage;
}
});
document.addEventListener('DOMContentLoaded', function() {
const selectedLanguage = localStorage.getItem('selectedLanguage');
const languageSelect = document.getElementById('language-select');
if (selectedLanguage) {
languageSelect.value = selectedLanguage;
changeLanguage(selectedLanguage);
}
languageSelect.addEventListener('change', function(event) {
const selectedLanguage = event.target.value;
localStorage.setItem('selectedLanguage', selectedLanguage);
changeLanguage(selectedLanguage);
});
});
// Event listener for language change
document.getElementById('language-select').addEventListener('change', function(event) {
const selectedLanguage = event.target.value;
localStorage.setItem('selectedLanguage', selectedLanguage);
changeLanguage(selectedLanguage);
});
// Get the particle container element
const particleContainer = document.getElementById("particle-container");
const background = document.getElementById("background");
// Function to toggle particle effects
function toggleParticleEffects() {
particleContainer.classList.toggle("hide-particles");
}
// Event listener for clicking the background
background.addEventListener("click", function(event) {
toggleParticleEffects();
});
// Get the high scores button by its ID
const highScoresButton = document.getElementById('high-scores-button-en');
// Hide the high scores button
highScoresButton.style.display = 'none';