-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
30 lines (26 loc) · 1.09 KB
/
popup.js
File metadata and controls
30 lines (26 loc) · 1.09 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
const quoteElement = document.getElementById("quote");
const contentElement = document.getElementById("content");
const authorElement = document.getElementById("author");
const loaderElement = document.getElementById("loader");
const moreButton = document.getElementById("more");
// Fetch a new quote on every page load
window.addEventListener("load", fetchQuote);
// Fetch a new quote when the "More" button is clicked
moreButton.addEventListener("click", fetchQuote);
function fetchQuote() {
// Show loader while fetching
loaderElement.classList.remove("hidden");
contentElement.classList.add("hidden");
fetch("https://api.quotable.io/random")
.then(response => response.json())
.then(data => {
quoteElement.textContent = `${data.content}`;
authorElement.textContent = `by- ${data.author}`;
})
.catch(error => console.error("Error fetching :", error))
.finally(() => {
// Hide loader after fetching
loaderElement.classList.add("hidden");
contentElement.classList.remove("hidden");
});
}