<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>명언 생성기</title>
<link rel="icon" type="image/png" href="https://s2.googleusercontent.com/s2/favicons?domain=jacinto.design">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css"/>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="quote-container" id="quote-container">
<!-- Quote -->
<div class="quote-text">
<i class="fas fa-quote-left"></i>
<span id="quote"></span>
</div>
<!-- Author -->
<div class="quote-author">
<span id="author"></span>
</div>
<!-- Buttons -->
<div class="button-container">
<button class="twitter-button" id="twitter" title="Tweet This!">
<i class="fab fa-twitter"></i>
</button>
<button id="new-quote">새로운 명언</button>
</div>
</div>
<!-- Loader -->
<div class="loader" id="loader"></div>
<!-- Script -->
<script src="script.js"></script>
</body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Yeon+Sung&display=swap');
html{
box-sizing: border-box;
}
body{
margin: 0;
min-height: 100vh;
background-color: #fdfcff;
background-image: url("data:image/svg+xml,%3Csvg width='30' height='30' viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M15 0C6.716 0 0 6.716 0 15c8.284 0 15-6.716 15-15zM0 15c0 8.284 6.716 15 15 15 0-8.284-6.716-15-15-15zm30 0c0-8.284-6.716-15-15-15 0 8.284 6.716 15 15 15zm0 0c0 8.284-6.716 15-15 15 0-8.284 6.716-15 15-15z' fill='%23f10303' fill-opacity='0.24' fill-rule='evenodd'/%3E%3C/svg%3E");
color: black;
font-family: 'Yeon Sung', cursive;
font-weight: 700;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.quote-container {
width: auto;
max-width: 900px;
padding: 20px 30px;
border-radius: 10px;
background-color: rgba(241, 212, 136, 0.7);
box-shadow: 0 10px 10px 10px rgba(0, 0, 0, 0.2);
}
.quote-text {
font-size: 2.75rem;
}
.long-quote {
font-size: 2rem;
}
.fa-quote-left {
font-size: 4rem;
}
.quote-author {
margin-top: 15px;
font-size: 2rem;
font-weight: 400;
font-style: italic;
}
.button-container {
margin-top: 15px;
display: flex;
justify-content: space-between;
}
button {
cursor: pointer;
font-size: 1.2rem;
height: 2.5rem;
border: none;
border-radius: 10px;
color: #fff;
background: #333;
outline: none;
padding: 0.5rem 1.8rem;
box-shadow: 0 0.3rem rgba(121, 121, 121, 0.65);
}
button:hover {
filter: brightness(130%);
}
button:active {
transform: translate(0, 0.3rem);
box-shadow: 0 0.1rem rgba(255, 255, 255, 0.65);
}
.twitter-button:hover {
color: #38a1f3;
}
.fa-twitter {
font-size: 1.5rem;
}
/* Loader */
.loader {
border: 16px solid #f3f3f3;
border-top: 16px solid #333;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* Media Query: Tablet or Smaller */
@media screen and (max-width: 1000px) {
.quote-container {
margin: auto 10px;
}
.quote-text {
font-size: 2.5rem;
}
}
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 Loading
function loading() {
loader.hidden = false;
quoteContainer.hidden = true;
}
// Hide Loading
function complete() {
if (!loader.hidden) {
quoteContainer.hidden = false;
loader.hidden = true;
}
}
// Get Quote From API
async function getQuote() {
loading();
const proxyUrl = 'https://whispering-tor-04671.herokuapp.com/'
const apiUrl = 'http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json';
try {
const response = await fetch(proxyUrl + apiUrl);
const data = await response.json();
// If Author is blank, add 'Unknown'
if (data.quoteAuthor === '') {
authorText.innerText = 'Unknown';
} else {
authorText.innerText = data.quoteAuthor;
}
// Reduce font size for long quotes
if (data.quoteText.length > 120) {
quoteText.classList.add('long-quote');
} else {
quoteText.classList.remove('long-quote');
}
quoteText.innerText = data.quoteText;
// Stop Loader, Show Quote
complete();
} catch (error) {
getQuote();
}
}
// Tweet Quote
function tweetQuote() {
const quote = quoteText.innerText;
const author = authorText.innerText;
const twitterUrl = `https://twitter.com/intent/tweet?text=${quote} - ${author}`;
window.open(twitterUrl, '_blank');
}
// Event Listeners
newQuoteBtn.addEventListener('click', getQuote);
twitterBtn.addEventListener('click', tweetQuote);
// On Load
getQuote();
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.