Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Quote generator#66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
SuhaniKaushal wants to merge1 commit intosahandghavidel:main
base:main
Choose a base branch
Loading
fromSuhaniKaushal:principle
Open
Show file tree
Hide file tree
Changes fromall 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
32 changes: 32 additions & 0 deletionsprojects/Quote generqtor/index.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Ultimate Quote Generator</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="quote-box">
<h1>💬 Daily Motivation</h1>
<p id="quote">Click the button below to get today's quote.</p>
<p id="author" class="author"></p>

<div class="buttons">
<button onclick="generateQuote()">🔁 New Quote</button>
<button onclick="copyQuote()">📋 Copy</button>
<button onclick="shareQuote()">🐦 Share</button>
<button onclick="saveFavorite()">💖 Save</button>
<button onclick="viewFavorites()">📚 View Saved</button>
<button onclick="toggleDarkMode()">🌙 Dark Mode</button>
</div>

<div id="favoritesContainer" class="hidden">
<h3>Saved Quotes</h3>
<ul id="favoritesList"></ul>
</div>
</div>

<script src="script.js"></script>
</body>
</html>
107 changes: 107 additions & 0 deletionsprojects/Quote generqtor/script.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
let currentQuote = "";
let currentAuthor = "";

document.addEventListener("DOMContentLoaded", () => {
autoDarkMode();
showDailyQuote();
});

const localQuotes = [
{ text: "Be yourself; everyone else is already taken.", author: "Oscar Wilde" },
{ text: "Success is not final, failure is not fatal: It is the courage to continue that counts.", author: "Winston Churchill" },
{ text: "Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.", author: "Buddha" },
{ text: "The only way to do great work is to love what you do.", author: "Steve Jobs" },
{ text: "Life is what happens when you're busy making other plans.", author: "John Lennon" }
];

function generateQuote() {
const randomIndex = Math.floor(Math.random() * localQuotes.length);
const quote = localQuotes[randomIndex];
currentQuote = quote.text;
currentAuthor = quote.author;
displayQuote(currentQuote, currentAuthor);
saveDailyQuote(currentQuote, currentAuthor);
}

function displayQuote(text, author) {
const quoteEl = document.getElementById("quote");
const authorEl = document.getElementById("author");
quoteEl.innerHTML = "";
authorEl.innerHTML = "";

let i = 0;
function typeWriter() {
if (i < text.length) {
quoteEl.innerHTML += text.charAt(i);
i++;
setTimeout(typeWriter, 30);
} else {
authorEl.innerText = `— ${author}`;
}
}
typeWriter();
}

function copyQuote() {
const fullQuote = `"${currentQuote}" — ${currentAuthor}`;
navigator.clipboard.writeText(fullQuote).then(() => {
alert("Quote copied to clipboard!");
});
}

function shareQuote() {
const tweetURL = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
`"${currentQuote}" — ${currentAuthor}`
)}`;
window.open(tweetURL, "_blank");
}

function saveFavorite() {
const favorites = JSON.parse(localStorage.getItem("favorites")) || [];
favorites.push({ text: currentQuote, author: currentAuthor });
localStorage.setItem("favorites", JSON.stringify(favorites));
alert("Quote saved!");
}

function viewFavorites() {
const container = document.getElementById("favoritesContainer");
const list = document.getElementById("favoritesList");
const favorites = JSON.parse(localStorage.getItem("favorites")) || [];

list.innerHTML = "";
favorites.forEach(q => {
const li = document.createElement("li");
li.textContent = `"${q.text}" — ${q.author}`;
list.appendChild(li);
});

container.classList.toggle("hidden");
}

function toggleDarkMode() {
document.body.classList.toggle("dark");
}

function autoDarkMode() {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add("dark");
}
}

function showDailyQuote() {
const stored = JSON.parse(localStorage.getItem("dailyQuote"));
const today = new Date().toDateString();

if (stored && stored.date === today) {
currentQuote = stored.text;
currentAuthor = stored.author;
displayQuote(currentQuote, currentAuthor);
} else {
generateQuote();
}
}

function saveDailyQuote(text, author) {
const today = new Date().toDateString();
localStorage.setItem("dailyQuote", JSON.stringify({ text, author, date: today }));
}
112 changes: 112 additions & 0 deletionsprojects/Quote generqtor/style.css
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
body {
font-family: 'Segoe UI', sans-serif;
background: linear-gradient(-45deg, #f0f8ff, #e1f5fe, #f3e5f5, #ede7f6);
background-size: 400% 400%;
animation: gradient 15s ease infinite;
margin: 0;
display: flex;
justify-content: center;
align-items: flex-start;
min-height: 100vh;
padding: 40px;
transition: background-color 1s ease, color 0.3s;
}

@keyframes gradient {
0% { background-position: 0% 50% }
50% { background-position: 100% 50% }
100% { background-position: 0% 50% }
}

.quote-box {
background-color: white;
padding: 30px;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
width: 100%;
max-width: 500px;
text-align: center;
}

h1 {
margin-bottom: 20px;
color: #333;
}

#quote {
font-size: 20px;
min-height: 60px;
color: #444;
}

.author {
margin-top: 10px;
font-style: italic;
color: #777;
}

.buttons {
margin-top: 20px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
}

button {
padding: 10px 14px;
background-color: #007bff;
color: white;
border: none;
border-radius: 6px;
font-size: 14px;
cursor: pointer;
transition: 0.3s ease;
}

button:hover {
background-color: #0056b3;
}

.dark {
background-color: #121212;
color: white;
}

.dark .quote-box {
background-color: #1e1e1e;
color: white;
}

.dark #quote,
.dark .author {
color: #ddd;
}

.dark button {
background-color: #444;
}

.dark button:hover {
background-color: #666;
}

.hidden {
display: none;
}

#favoritesContainer {
margin-top: 30px;
text-align: left;
}

#favoritesList {
list-style: none;
padding: 0;
}

#favoritesList li {
margin: 5px 0;
border-bottom: 1px solid #ccc;
padding-bottom: 5px;
}

[8]ページ先頭

©2009-2025 Movatter.jp