-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
38 lines (33 loc) · 1.08 KB
/
script.js
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
32
33
34
35
36
37
38
const quote = document.getElementById('quote');
const nextQuoteButton = document.getElementById('next-quote');
const twitterButton = document.getElementById('twitter-button');
const loader = document.getElementById('loader');
const quoteContainer = document.getElementById('quote-container')
async function getQuotes() {
showLoader();
proxyUrl = 'https://enigmatic-meadow-78445.herokuapp.com/';
fetchUrl = 'http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json';
try {
const response = await fetch(proxyUrl + fetchUrl);
const data = await response.json();
quote.innerText = data.quoteText;
hideLoader();
} catch (error) {
getQuotes();
}
}
function goToTwitter() {
window.open(`https://twitter.com/intent/tweet?text=${quote.innerText}`, '_blank');
}
function showLoader() {
loader.hidden = false;
quoteContainer.hidden = true;
}
function hideLoader() {
loader.hidden = true;
quoteContainer.hidden = false;
}
//Initial Calls
nextQuoteButton.addEventListener('click', getQuotes)
twitterButton.addEventListener('click', goToTwitter)
getQuotes();