-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavascript
More file actions
51 lines (46 loc) · 1.43 KB
/
Javascript
File metadata and controls
51 lines (46 loc) · 1.43 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
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");
const api_url = "https://api.quotable.io/random";
async function getquote(url) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
quoteElement.innerHTML = data.content;
authorElement.innerHTML = data.author;
} catch (error) {
console.error("Error fetching quote:", error);
}
}
document.addEventListener("DOMContentLoaded", function () {
getquote(api_url);
});
function tweet() {
window.open(
(href =
"https://twitter.com/intent/tweet?text=" + quoteElement.innerHTML)
);
}
function fb() {
window.open(
"http://www.facebook.com/sharer/sharer.php?u=" +
encodeURIComponent(window.location.href) +
""e=" +
encodeURIComponent(quoteElement.innerText)
);
}
// Instagram doesn't provide direct sharing via API
function insta() {
// You can provide a link to your Instagram page/profile instead
window.open("https://www.instagram.com");
}
function li() {
window.open(
"https://www.linkedin.com/sharing/share-offsite/?url=" +
encodeURIComponent(window.location.href) +
"&summary=" +
encodeURIComponent(quoteElement.innerText)
);
}