-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
80 lines (68 loc) · 3.25 KB
/
index.html
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
75
76
77
78
79
80
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="./style.css">
<link rel="icon" type="image/x-icon" href="./favicon.ico">
<title>Quotes</title>
</head>
<body style=" background-color: #343a40;">
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6 p-5 bg-#abb3ba text-white" id = "box">
<center> <h1 style="align-items: center;">Quote</h1>
<p id="quote">Everything Is Very Nice</p>
<p id="author">--Tapan Radadiya</p>
<div class="col-sm-6">
<button type="button" class="btn btn-secondary btn-lg btn-block" id="btn_next" >Next Quote</button></br>
<button type="button" class="btn btn-secondary btn-lg btn-block" id="btn_tweet"><i class="fa-brands fa-twitter"></i> Tweet This Quote</button></center>
</div>
</div>
<div class="col-sm-3"></div>
</div>
</div>
</div>
<script>
const quote = document.getElementById('quote')
const author = document.getElementById('author')
const btn_next = document.getElementById('btn_next')
const btn_tweet = document.getElementById('btn_tweet')
let jsonData = ""
let quotesData = ""
const tweetQuote = () => {
let tweetIt = `https://twitter.com/intent/tweet?text=${quotesData.text}`
window.open(tweetIt)
}
const getNewQuote = () => {
const i = Math.trunc(Math.random()*1643);
quotesData = jsonData[i]
quote.innerText = `"${quotesData.text}"`
quotesData.author == null
?(author.innerText = "No Author found")
:(author.innerText = `-- ${quotesData.author}`)
}
const getQuote = async () =>{
const api = "https://type.fit/api/quotes";
try {
let apiData = await fetch(api)
jsonData = await apiData.json()
getNewQuote() ;
} catch (error) {
}
}
btn_next.addEventListener('click',getNewQuote)
btn_tweet.addEventListener('click',tweetQuote)
getQuote();
</script>
</body>
</html>