Download script.js from Joey889/Rabbit: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/Joey889/Rabbit/resolve/main/script.js
- Command line
-
hf download hf://spaces/Joey889/Rabbit/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Joey889/Rabbit/resolve/main/script.js
1.03 kB
| const rabbits = document.querySelectorAll('.rabbit'); | |
| let activeTimer = null; | |
| function speakGreeting(text) { | |
| if (!('speechSynthesis' in window)) return; | |
| window.speechSynthesis.cancel(); | |
| const utterance = new SpeechSynthesisUtterance(text); | |
| utterance.lang = 'zh-TW'; | |
| utterance.rate = 0.96; | |
| utterance.pitch = 1.15; | |
| window.speechSynthesis.speak(utterance); | |
| } | |
| function showGreeting(rabbit) { | |
| rabbits.forEach(item => item.classList.remove('talking')); | |
| rabbit.classList.add('talking'); | |
| const message = rabbit.dataset.message || `早安!我的名字叫 ${rabbit.dataset.name || 'rabbit'}!`; | |
| speakGreeting(message); | |
| clearTimeout(activeTimer); | |
| activeTimer = setTimeout(() => { | |
| rabbit.classList.remove('talking'); | |
| }, 2800); | |
| } | |
| rabbits.forEach((rabbit) => { | |
| rabbit.addEventListener('click', () => showGreeting(rabbit)); | |
| rabbit.addEventListener('keydown', (event) => { | |
| if (event.key === 'Enter' || event.key === ' ') { | |
| event.preventDefault(); | |
| showGreeting(rabbit); | |
| } | |
| }); | |
| }); | |