Spaces:
Running
Running
Download script.js from ffcc9393/data-delight-dash: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/spaces/ffcc9393/data-delight-dash/resolve/main/script.js
- Command line
-
hf download hf://spaces/ffcc9393/data-delight-dash/script.js
-
curl -L -o script.js https://huggingface.co/spaces/ffcc9393/data-delight-dash/resolve/main/script.js
2.25 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| // Fetch Random User | |
| document.getElementById('fetchUserBtn').addEventListener('click', async function() { | |
| try { | |
| const response = await fetch('https://randomuser.me/api/'); | |
| const data = await response.json(); | |
| const user = data.results[0]; | |
| const userResult = document.getElementById('userResult'); | |
| document.getElementById('userName').textContent = `${user.name.first} ${user.name.last}`; | |
| document.getElementById('userEmail').textContent = user.email; | |
| document.getElementById('userLocation').textContent = `${user.location.city}, ${user.location.country}`; | |
| document.getElementById('userPhone').textContent = user.phone; | |
| userResult.classList.remove('hidden'); | |
| feather.replace(); | |
| } catch (error) { | |
| console.error('Error fetching user:', error); | |
| } | |
| }); | |
| // Fetch Random Joke | |
| document.getElementById('fetchJokeBtn').addEventListener('click', async function() { | |
| try { | |
| const response = await fetch('https://official-joke-api.appspot.com/random_joke'); | |
| const joke = await response.json(); | |
| const jokeResult = document.getElementById('jokeResult'); | |
| document.getElementById('jokeText').textContent = `${joke.setup} ... ${joke.punchline}`; | |
| jokeResult.classList.remove('hidden'); | |
| } catch (error) { | |
| console.error('Error fetching joke:', error); | |
| } | |
| }); | |
| // Fetch Random Activity | |
| document.getElementById('fetchActivityBtn').addEventListener('click', async function() { | |
| try { | |
| const response = await fetch('https://www.boredapi.com/api/activity'); | |
| const activity = await response.json(); | |
| const activityResult = document.getElementById('activityResult'); | |
| document.getElementById('activityText').textContent = activity.activity; | |
| activityResult.classList.remove('hidden'); | |
| } catch (error) { | |
| console.error('Error fetching activity:', error); | |
| } | |
| }); | |
| }); |