-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (64 loc) · 2 KB
/
Copy pathscript.js
File metadata and controls
74 lines (64 loc) · 2 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
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
73
74
const quoteContainer = document.getElementById('quote-container');
const quoteText = document.getElementById("quote");
const authorText = document.getElementById("author");
const twitterBtn = document.getElementById("twitter");
const newQuoteBtn = document.getElementById("new-quote");
const loader = document.getElementById("loader");
//Show Loader
function loading() {
loader.hidden = false;
quoteContainer.hidden = true;
}
//Hide Loading
function complete() {
if (!loading.hidden) {
quoteContainer.hidden = false;
loader.hidden = true
}
}
// Get Quote From API
async function getQuote() {
loading();
// const proxyUrl = "http://cors-anywhere.herokuapp.com/";
try {
const response = await fetch("https://quotes-api-self.vercel.app/quote")
.then((response) => response.json())
.then((data) => {
// Handle the retrieved quote
if (data.author === "") {
authorText.innerText = "Unknown";
} else {
authorText.innerText = data.author;
}
// Reduce font size for long quotes
if (data.quote.length > 120) {
quoteText.classList.add("long-quote");
} else {
quoteText.classList.remove("long-quote");
quoteText.innerText = data.quote;
}
complete();
})
.catch((error) => {
// Handle any errors
console.error(error);
});
const data = await response.json();
// If Author is blank, add 'Unknown'
//Stop Louder, show the quote
complete();
} catch (error) {}
}
function tweetQuote() {
// Função para redirecionar para Bluesky com texto pré-preenchido
const quote = quoteText.innerText;
const author = authorText.innerText;
const url = `https://bsky.app/create?text=${quote} - ${author}`;
// Redirecionar para o link do Bluesky
window.open(url, '_blank');
}
//Event Listeners
newQuoteBtn.addEventListener('click', getQuote)
twitterBtn.addEventListener('click', tweetQuote)
// On load
getQuote();