Skip to content

Commit dc1c13b

Browse files
authored
Add files via upload
1 parent 81a8673 commit dc1c13b

File tree

4 files changed

+228
-0
lines changed

4 files changed

+228
-0
lines changed

favicon.png

1.95 KB
Loading

index.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Quote Generator</title>
7+
<link rel="icon" type="image/png" href="favicon.png">
8+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css"/>
9+
<link rel="stylesheet" href="style.css">
10+
</head>
11+
<body>
12+
13+
<div class="quote-container" id="quote-container">
14+
<!--Quote-->
15+
<div class="quote-text">
16+
<i class="fas fa-quote-left"></i>
17+
<span id="quote"></span>
18+
</div>
19+
<!--Author -->
20+
<div class="quote-author">
21+
<span id="author"></span>
22+
</div>
23+
<!--Buttons-->
24+
<div class="button-container">
25+
<button class="twitter-button" id = "twitter" title="Tweet This!">
26+
<i class="fab fa-twitter"></i>
27+
</button>
28+
<button id="new-quote">New Quote</button>
29+
</div>
30+
</div>
31+
32+
<!--Loader-->
33+
<div class="loader" id="loader"></div>
34+
35+
<!-- Script -->
36+
<script src="script.js"></script>
37+
</body>
38+
</html>

script.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const quoteContainer = document.getElementById('quote-container');
2+
const quoteText = document.getElementById('quote');
3+
const authorText = document.getElementById('author');
4+
const twitterBtn = document.getElementById('twitter');
5+
const newQuoteBtn = document.getElementById('new-quote');
6+
const loader = document.getElementById('loader');
7+
8+
9+
let apiQuotes = [];
10+
11+
//Show loading
12+
function loading(){
13+
loader.hidden = false;
14+
quoteContainer.hidden = true;
15+
}
16+
17+
//Hide loading
18+
function complete(){
19+
quoteContainer.hidden = false;
20+
loader.hidden = true;
21+
}
22+
23+
//Show new quote
24+
function newQuote(){
25+
//call the loader
26+
loading();
27+
28+
//Pick a random quote
29+
const quote = apiQuotes[Math.floor(Math.random() * apiQuotes.length)];
30+
//if author field is None, then fill it with Unknown
31+
if(!quote.author){
32+
authorText.textContent = "Unknown";
33+
}else{
34+
authorText.textContent = quote.author;
35+
}
36+
37+
//check quote length to determine styling
38+
if(quote.text.length > 120){
39+
quoteText.classList.add('long-quote');
40+
}else{
41+
quoteText.classList.remove('long-quote');
42+
}
43+
44+
45+
//setting quotetext
46+
quoteText.textContent = quote.text;
47+
48+
//hide the loading
49+
complete();
50+
}
51+
52+
//Get quote from API
53+
async function getQuotes(){
54+
loading();
55+
const apiUrl = 'https://type.fit/api/quotes';
56+
try{
57+
const response = await fetch(apiUrl);
58+
apiQuotes = await response.json();
59+
newQuote();
60+
}catch(error){
61+
62+
}
63+
}
64+
65+
//Tweet Quote
66+
function tweetQuote(){
67+
const twitterUrl = `https://twitter.com/intent/tweet?text=${quoteText.textContent} - ${authorText.textContent}`;
68+
window.open(twitterUrl, '_blank');
69+
}
70+
71+
//Event Listeneres
72+
newQuoteBtn.addEventListener('click', newQuote);
73+
74+
twitterBtn.addEventListener('click', tweetQuote);
75+
76+
//On load
77+
getQuotes();

style.css

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@1,300&display=swap');
2+
3+
html {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
margin: 0;
9+
min-height: 100vh;
10+
background-color: #ffffff;
11+
color: black;
12+
font-family: Montserrat, sans-serif;
13+
font-weight: 700;
14+
text-align: center;
15+
display: flex;
16+
align-items: center;
17+
justify-content: center;
18+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 304 304' width='304' height='304'%3E%3Cpath fill='%23000000' fill-opacity='0.08' d='M44.1 224a5 5 0 1 1 0 2H0v-2h44.1zm160 48a5 5 0 1 1 0 2H82v-2h122.1zm57.8-46a5 5 0 1 1 0-2H304v2h-42.1zm0 16a5 5 0 1 1 0-2H304v2h-42.1zm6.2-114a5 5 0 1 1 0 2h-86.2a5 5 0 1 1 0-2h86.2zm-256-48a5 5 0 1 1 0 2H0v-2h12.1zm185.8 34a5 5 0 1 1 0-2h86.2a5 5 0 1 1 0 2h-86.2zM258 12.1a5 5 0 1 1-2 0V0h2v12.1zm-64 208a5 5 0 1 1-2 0v-54.2a5 5 0 1 1 2 0v54.2zm48-198.2V80h62v2h-64V21.9a5 5 0 1 1 2 0zm16 16V64h46v2h-48V37.9a5 5 0 1 1 2 0zm-128 96V208h16v12.1a5 5 0 1 1-2 0V210h-16v-76.1a5 5 0 1 1 2 0zm-5.9-21.9a5 5 0 1 1 0 2H114v48H85.9a5 5 0 1 1 0-2H112v-48h12.1zm-6.2 130a5 5 0 1 1 0-2H176v-74.1a5 5 0 1 1 2 0V242h-60.1zm-16-64a5 5 0 1 1 0-2H114v48h10.1a5 5 0 1 1 0 2H112v-48h-10.1zM66 284.1a5 5 0 1 1-2 0V274H50v30h-2v-32h18v12.1zM236.1 176a5 5 0 1 1 0 2H226v94h48v32h-2v-30h-48v-98h12.1zm25.8-30a5 5 0 1 1 0-2H274v44.1a5 5 0 1 1-2 0V146h-10.1zm-64 96a5 5 0 1 1 0-2H208v-80h16v-14h-42.1a5 5 0 1 1 0-2H226v18h-16v80h-12.1zm86.2-210a5 5 0 1 1 0 2H272V0h2v32h10.1zM98 101.9V146H53.9a5 5 0 1 1 0-2H96v-42.1a5 5 0 1 1 2 0zM53.9 34a5 5 0 1 1 0-2H80V0h2v34H53.9zm60.1 3.9V66H82v64H69.9a5 5 0 1 1 0-2H80V64h32V37.9a5 5 0 1 1 2 0zM101.9 82a5 5 0 1 1 0-2H128V37.9a5 5 0 1 1 2 0V82h-28.1zm16-64a5 5 0 1 1 0-2H146v44.1a5 5 0 1 1-2 0V18h-26.1zm102.2 270a5 5 0 1 1 0 2H98v14h-2v-16h124.1zM242 149.9V160h16v34h-16v62h48v48h-2v-46h-48v-66h16v-30h-16v-12.1a5 5 0 1 1 2 0zM53.9 18a5 5 0 1 1 0-2H64V2H48V0h18v18H53.9zm112 32a5 5 0 1 1 0-2H192V0h50v2h-48v48h-28.1zm-48-48a5 5 0 0 1-9.8-2h2.07a3 3 0 1 0 5.66 0H178v34h-18V21.9a5 5 0 1 1 2 0V32h14V2h-58.1zm0 96a5 5 0 1 1 0-2H137l32-32h39V21.9a5 5 0 1 1 2 0V66h-40.17l-32 32H117.9zm28.1 90.1a5 5 0 1 1-2 0v-76.51L175.59 80H224V21.9a5 5 0 1 1 2 0V82h-49.59L146 112.41v75.69zm16 32a5 5 0 1 1-2 0v-99.51L184.59 96H300.1a5 5 0 0 1 3.9-3.9v2.07a3 3 0 0 0 0 5.66v2.07a5 5 0 0 1-3.9-3.9H185.41L162 121.41v98.69zm-144-64a5 5 0 1 1-2 0v-3.51l48-48V48h32V0h2v50H66v55.41l-48 48v2.69zM50 53.9v43.51l-48 48V208h26.1a5 5 0 1 1 0 2H0v-65.41l48-48V53.9a5 5 0 1 1 2 0zm-16 16V89.41l-34 34v-2.82l32-32V69.9a5 5 0 1 1 2 0zM12.1 32a5 5 0 1 1 0 2H9.41L0 43.41V40.6L8.59 32h3.51zm265.8 18a5 5 0 1 1 0-2h18.69l7.41-7.41v2.82L297.41 50H277.9zm-16 160a5 5 0 1 1 0-2H288v-71.41l16-16v2.82l-14 14V210h-28.1zm-208 32a5 5 0 1 1 0-2H64v-22.59L40.59 194H21.9a5 5 0 1 1 0-2H41.41L66 216.59V242H53.9zm150.2 14a5 5 0 1 1 0 2H96v-56.6L56.6 162H37.9a5 5 0 1 1 0-2h19.5L98 200.6V256h106.1zm-150.2 2a5 5 0 1 1 0-2H80v-46.59L48.59 178H21.9a5 5 0 1 1 0-2H49.41L82 208.59V258H53.9zM34 39.8v1.61L9.41 66H0v-2h8.59L32 40.59V0h2v39.8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0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm112 176a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm-16 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM17 180a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0 16a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm0-32a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16 0a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM17 84a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm32 64a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm16-16a3 3 0 1 0 0-6 3 3 0 0 0 0 6z'%3E%3C/path%3E%3C/svg%3E");
19+
}
20+
21+
.quote-container{
22+
width: auto;
23+
max-width: 900px;
24+
padding: 20px 30px;
25+
border-radius: 10px;
26+
background-color: rgba(255, 255, 255, 0.4);
27+
box-shadow: 0 10px 10px 10px rgba(0, 0, 0, 0.2);
28+
}
29+
30+
.quote-text{
31+
font-size: 2.75rem;
32+
/* rem = 16px, it helps in maintaining the responsiveness of the text size in mobile and windows devices*/
33+
}
34+
35+
.long-quote{
36+
font-size: 2rem;
37+
}
38+
39+
.fa-quote-left{
40+
font-size: 4rem;
41+
}
42+
43+
.quote-author{
44+
margin-top: 15px;
45+
font-size: 2rem;
46+
font-weight: 400;
47+
font-style: italic;
48+
}
49+
50+
.button-container{
51+
margin-top: 15px;
52+
display: flex;
53+
justify-content: space-between;
54+
}
55+
56+
button{
57+
cursor: pointer;
58+
font-size: 1.2rem;
59+
height: 2.5rem;
60+
border: none;
61+
border-radius: 10px;
62+
color: #fff;
63+
background: #333;
64+
outline: none;
65+
padding: 0.5rem 1.8rem;
66+
box-shadow: 0 0.3rem rgba(121, 121, 121, 0.65);
67+
}
68+
69+
button:hover{
70+
filter: brightness(110%);
71+
}
72+
73+
button:active{
74+
transform: translate(0, 0.3rem);
75+
box-shadow: 0 0.1rem rgba(255, 255, 255, 0.65);
76+
}
77+
78+
.twitter-button:hover{
79+
color: #38a1f3;
80+
}
81+
82+
.fa-twitter{
83+
font-size: 1.5rem;
84+
}
85+
86+
/*Loader*/
87+
.loader {
88+
border: 16px solid #f3f3f3;
89+
border-top: 16px solid #333;
90+
border-radius: 50%;
91+
width: 120px;
92+
height: 120px;
93+
animation: spin 2s linear infinite;
94+
}
95+
96+
@keyframes spin {
97+
0% { transform: rotate(0deg); }
98+
100% { transform: rotate(360deg); }
99+
}
100+
101+
/*Media Query*/
102+
@media screen and (max-width: 1000px){
103+
.quote-container{
104+
margin: auto 10px;
105+
}
106+
107+
.quote-text{
108+
font-size: 2.5rem;
109+
}
110+
}
111+
112+
113+

0 commit comments

Comments
 (0)