-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
31 lines (27 loc) · 1.06 KB
/
Copy pathscripts.js
File metadata and controls
31 lines (27 loc) · 1.06 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
31
document.addEventListener('DOMContentLoaded', () => {
const quoteBody = document.getElementById('quote-body');
const quoteFooter = document.getElementById('quote-footer');
const twitterBtn = document.getElementById('twitter');
const newQuoteBtn = document.getElementById('new-quote');
newQuoteBtn.addEventListener("click", getQuote);
function getQuote() {
let spinner = newQuoteBtn.childNodes[1];
spinner.classList.toggle('fa-spin');
newQuoteBtn.disabled = true;
fetch("https://talaikis.com/api/quotes/random/")
.then((json) => json.json())
.then((data) => {
let quote = data.quote;
let author = data.author;
quoteBody.innerHTML = quote;
quoteFooter.innerHTML = author;
spinner.classList.toggle('fa-spin');
newQuoteBtn.disabled = false;
twitterBtn.setAttribute('href', 'https://twitter.com/intent/tweet?text="' + quote + '" -- ' + author);
})
.catch(err => {
quoteBody.innerHTML = "There was an error, please try again!";
});
}
getQuote();
}, false);