-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (32 loc) · 1.22 KB
/
script.js
File metadata and controls
39 lines (32 loc) · 1.22 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
32
33
34
35
36
37
38
39
const quoteText = document.querySelector(".quote"),
authorName = document.querySelector(".author .name"),
quoteBtn = document.querySelector("button"),
soundBtn = document.querySelector(".sound"),
copyBtn = document.querySelector(".copy"),
twitterBtn = document.querySelector(".twitter");
function randomQuote(){
quoteBtn.classList.add("loading");
quoteBtn.innerText = "Loading quote..."
fetch("https://api.quotable.io/random").then(res => res.json()).then(result =>{
console.log(result);
quoteText.innerText = result.content;
authorName.innerText = result.author;
quoteBtn.innerText = "New quote..."
quoteBtn.classList.remove("loading");
})
}
window.onload = ()=>{
randomQuote();
}
soundBtn.addEventListener("click", ()=>{
let utterance = new SpeechSynthesisUtterance(`${quoteText.innerText} by ${authorName.innerText}`);
speechSynthesis.speak(utterance);
});
copyBtn.addEventListener("click", ()=>{
navigator.clipboard.writeText(quoteText.innerText);
});
twitterBtn.addEventListener("click", ()=>{
let tweetUrl = `https://twitter.com/intent/tweet?url=${quoteText.innerText}`;
window.open(tweetUrl, "_blank")
});
quoteBtn.addEventListener("click", randomQuote);