-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (28 loc) · 1.27 KB
/
Copy pathscript.js
File metadata and controls
33 lines (28 loc) · 1.27 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
async function fetchQuote() {
const response = await fetch("http://api.quotable.io/quotes/random");
const data = await response.json();
document.getElementById("quoteText").textContent = `"${data[0].content}"`;
document.getElementById("quoteAuthor").textContent = `- ${data[0].author}`;
// Random background image
document.body.style.backgroundImage = `url('https://source.unsplash.com/1600x900/?nature,abstract')`;
}
function copyQuote() {
const quote = document.getElementById("quoteText").textContent + " " + document.getElementById("quoteAuthor").textContent;
navigator.clipboard.writeText(quote);
alert("Quote copied!");
}
function shareOnTwitter() {
const quote = document.getElementById("quoteText").textContent + " " + document.getElementById("quoteAuthor").textContent;
const twitterUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(quote)}`;
window.open(twitterUrl, "_blank");
}
function exportImage() {
html2canvas(document.getElementById("quoteContainer")).then(canvas => {
let link = document.createElement("a");
link.href = canvas.toDataURL("image/png");
link.download = "quote.png";
link.click();
});
}
// Fetch first quote on load
fetchQuote();