-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
72 lines (68 loc) · 1.67 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const quote = document.getElementById('quote');
const author = document.getElementById('author');
const quoteUrl = 'https://api.quotable.io/random';
const twitterApi = 'https://twitter.com/intent/tweet?url=';
let getQuote = (url) => {
fetch(url)
.then((data) => data.json())
.then((item) => {
quote.innerText = item.content;
author.innerText = item.author;
});
};
window.addEventListener('load', getQuote(quoteUrl));
document.addEventListener('click', (e) => findQuote(e));
const findQuote = (e) => {
switch (e.target.id) {
case 'random':
getQuote(quoteUrl);
break;
case 'famous-quotes':
getQuote(quoteUrl + '?tags=famous-quotes');
break;
case 'technology':
getQuote(quoteUrl + '?tags=technology');
break;
case 'business':
getQuote(quoteUrl + '?tags=business');
break;
case 'wisdom':
getQuote(quoteUrl + '?tags=wisdom');
break;
case 'life':
getQuote(quoteUrl + '?tags=life');
break;
case 'love':
getQuote(quoteUrl + '?tags=love');
break;
case 'friendship':
getQuote(quoteUrl + '?tags=friendship');
break;
case 'success':
getQuote(quoteUrl + '?tags=success');
break;
case 'inspirational':
getQuote(quoteUrl + '?tags=inspirational');
break;
case 'sports':
getQuote(quoteUrl + '?tags=sports');
break;
case 'speak':
let utterance = new SpeechSynthesisUtterance(
`${quote.innerText} by ${author.innerText}`
);
speechSynthesis.speak(utterance);
break;
case 'copy':
navigator.clipboard.writeText(
`${quote.innerText} --${author.innerText}`
);
break;
case 'twitter':
window.open(
`${twitterApi}${quote.innerText} --${author.innerText}`,
'_blank'
);
break;
}
};