Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Quote-Generator-Web-App/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quote Generator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="quote-box">
<div class="quote-text" id="quoteText">Loading...</div>
<div class="quote-author" id="quoteAuthor"></div>
</div>
<div class="buttons">
<button class="generate-btn" id="generateBtn">Generate Quote</button>
<button class="share-btn" id="shareBtn">Share</button>
<button class="copy-btn" id="copyBtn">Copy</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
64 changes: 64 additions & 0 deletions Quote-Generator-Web-App/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const quoteTextElement = document.getElementById('quoteText');
const quoteAuthorElement = document.getElementById('quoteAuthor');
const generateBtn = document.getElementById('generateBtn');
const shareBtn = document.getElementById('shareBtn');
const copyBtn = document.getElementById('copyBtn');

// JavaScript code as provided in the previous responses


// Function to fetch a random quote from the "type.fit" Quote API
async function getQuote() {
try {
const response = await fetch('https://type.fit/api/quotes');
const data = await response.json();
const randomIndex = Math.floor(Math.random() * data.length);
const quote = data[randomIndex];
quoteTextElement.textContent = `"${quote.text}"`;
quoteAuthorElement.textContent = `- ${quote.author || 'Unknown'}`;
} catch (error) {
quoteTextElement.textContent = 'Failed to fetch a quote. Please try again later.';
quoteAuthorElement.textContent = '';
}
}
// Same as before...

// Function to share the quote on Twitter
function shareOnTwitter() {
const quoteText = encodeURIComponent(quoteTextElement.textContent);
const quoteAuthor = encodeURIComponent(quoteAuthorElement.textContent.replace('- ', ''));
const twitterUrl = `https://twitter.com/intent/tweet?text=${quoteText} - ${quoteAuthor}`;
window.open(twitterUrl, '_blank');
}

// Function to copy the quote to clipboard
// Function to copy the quote to clipboard
function copyToClipboard() {
const quoteToCopy = `"${quoteTextElement.textContent}" - ${quoteAuthorElement.textContent}`;
const tempTextArea = document.createElement('textarea');
tempTextArea.value = quoteToCopy;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');
document.body.removeChild(tempTextArea);

// Show success message
const successMessage = document.createElement('div');
successMessage.textContent = 'Quote copied to clipboard!';
successMessage.classList.add('success-message');
document.body.appendChild(successMessage);

// Remove the success message after a few seconds
setTimeout(() => {
document.body.removeChild(successMessage);
}, 2000);
}


// Event listeners for the "Generate Quote", "Share", and "Copy" buttons
generateBtn.addEventListener('click', getQuote);
shareBtn.addEventListener('click', shareOnTwitter);
copyBtn.addEventListener('click', copyToClipboard);

// Initial quote load on page load
getQuote();
47 changes: 47 additions & 0 deletions Quote-Generator-Web-App/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}

.container {
text-align: center;
}

.quote-box {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
max-width: 500px;
margin: 0 auto;
}

.quote-text {
font-size: 24px;
font-weight: bold;
}

.quote-author {
margin-top: 10px;
font-size: 18px;
}

.generate-btn,
.share-btn,
.copy-btn {
padding: 10px 20px;
font-size: 18px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}