Spaces:
Sleeping
Sleeping
Commit ·
ca62cc0
1
Parent(s): 47c3da9
Create js/script.js
Browse files- static/js/script.js +33 -0
static/js/script.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 2 |
+
const voiceButton = document.getElementById('voice-button');
|
| 3 |
+
if (voiceButton) {
|
| 4 |
+
voiceButton.addEventListener('click', () => {
|
| 5 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 6 |
+
recognition.onresult = (event) => {
|
| 7 |
+
const command = event.results[0][0].transcript;
|
| 8 |
+
fetch('/voice_command', {
|
| 9 |
+
method: 'POST',
|
| 10 |
+
headers: { 'Content-Type': 'application/json' },
|
| 11 |
+
body: JSON.stringify({ command })
|
| 12 |
+
})
|
| 13 |
+
.then(response => response.json())
|
| 14 |
+
.then(data => alert(data.message))
|
| 15 |
+
.catch(error => console.error('Voice command error:', error));
|
| 16 |
+
};
|
| 17 |
+
recognition.start();
|
| 18 |
+
});
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
const stars = document.querySelectorAll('.rating .star');
|
| 22 |
+
stars.forEach(star => {
|
| 23 |
+
star.addEventListener('click', () => {
|
| 24 |
+
const rating = star.dataset.value;
|
| 25 |
+
const internshipId = star.closest('form').dataset.internshipId;
|
| 26 |
+
document.querySelector(`form[data-internship-id="${internshipId}"] input[name="rating"]`).value = rating;
|
| 27 |
+
stars.forEach(s => s.classList.remove('filled'));
|
| 28 |
+
for (let i = 0; i < rating; i++) {
|
| 29 |
+
stars[i].classList.add('filled');
|
| 30 |
+
}
|
| 31 |
+
});
|
| 32 |
+
});
|
| 33 |
+
});
|