-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
301 lines (275 loc) · 15.4 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Daily Inspiration</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.2/html2canvas.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Roboto:wght@300;400&display=swap');
body {
font-family: 'Roboto', sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
}
.quote-container {
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
position: relative;
transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
.quote-mark {
font-family: 'Playfair Display', serif;
font-size: 12rem;
line-height: 1;
opacity: 0.2;
transition: color 0.3s ease;
position: absolute;
top: -0.1em;
left: -0.1em;
z-index: 0;
}
#quote {
font-family: 'Playfair Display', serif;
font-size: 1.5rem;
line-height: 1.6;
transition: opacity 0.3s ease;
position: relative;
z-index: 1;
}
.button {
transition: all 0.3s ease;
}
.button:hover {
transform: scale(1.1);
}
#quoteImage {
display: none;
}
.share-button {
color: #718096; /* Default grey color */
}
.share-button:hover {
color: #2d3748; /* Darker grey on hover */
}
.flag-button img {
filter: grayscale(100%);
transition: filter 0.3s ease;
width: 30px;
height: 30px;
}
.flag-button img:hover {
filter: none;
}
.flag-container {
position: absolute;
margin-top: 15px;
bottom: 50px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 10px;
padding: 1rem;
}
.dark-mode {
@apply bg-gray-900 text-white;
}
.dark-mode .quote-container {
@apply bg-gray-800 text-white;
}
.dark-mode .quote-mark {
@apply text-gray-600 text-white;
}
.dark-mode #quote {
@apply text-gray-300 text-white;
}
.loading {
opacity: 0.5;
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center px-4 bg-gray-100 dark:bg-gray-900">
<div class="quote-container max-w-4xl w-full p-8 md:p-12 rounded-lg relative overflow-hidden bg-white dark:bg-gray-800">
<div class="flex justify-between items-center mb-6">
<h1 id="header-title" class="text-3xl md:text-4xl font-bold text-gray-800 dark:text-white">Daily Inspiration</h1>
<button id="darkModeToggle" class="button text-gray-600 dark:text-gray-400" aria-label="Toggle dark mode">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path>
</svg>
</button>
</div>
<div id="quoteWrapper" class="relative mb-8">
<span class="quote-mark absolute top-0 left-0 transform -translate-y-1/2 -translate-x-1/4 text-gray-400 dark:text-gray-600">"</span>
<p id="quote" class="text-gray-700 dark:text-gray-300 z-10 relative"></p>
</div>
<div class="flex justify-between items-center">
<div class="flex space-x-4">
<button id="prevButton" class="button text-blue-500 dark:text-blue-400" aria-label="Previous quote">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 19l-7-7 7-7"></path>
</svg>
</button>
<button id="playButton" class="button text-blue-500 dark:text-blue-400" aria-label="Read quote">
<!-- <svg class="w-8 h-8" fill="currentColor" viewBox="0 0 20 20">
<path fillRule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clipRule="evenodd" />
</svg> -->
<svg class="w-10 h-10 text-blue-500" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z" clip-rule="evenodd" />
</svg>
</button>
<button id="nextButton" class="button text-blue-500 dark:text-blue-400" aria-label="Next quote">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 5l7 7-7 7"></path>
</svg>
</button>
</div>
<div class="flex space-x-4">
<button onclick="shareOnX()" class="share-button text-black hover:text-gray-700" aria-label="Share on X">
<svg class="w-6 h-6" viewBox="0 0 24 24" fill="currentColor">
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/>
</svg>
</button>
<button onclick="shareOnFacebook()" class="share-button text-blue-600 hover:text-blue-800" aria-label="Share on Facebook">
<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
<path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
</svg>
</button>
<button onclick="shareOnLinkedIn()" class="share-button text-blue-700 hover:text-blue-900" aria-label="Share on LinkedIn">
<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
<path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
</svg>
</button>
<button onclick="shareOnInstagram()" class="share-button text-pink-600 hover:text-pink-800" aria-label="Share on Instagram">
<svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"/>
</svg>
</button>
</div>
</div>
</div>
<div class="fixed bottom-4 left-1/2 transform -translate-x-1/2 flex space-x-4">
<button class="flag-button" onclick="loadQuotes('quotes.txt', 'Daily Inspiration')" aria-label="English">
<img src="https://flagicons.lipis.dev/flags/4x3/us.svg" alt="English">
</button>
<button class="flag-button" onclick="loadQuotes('quotes_es.txt', 'Inspiración Diaria')" aria-label="Español">
<img src="https://flagicons.lipis.dev/flags/4x3/es.svg" alt="Español">
</button>
<button class="flag-button" onclick="loadQuotes('quotes_pt.txt', 'Inspiração Diária')" aria-label="Português">
<img src="https://flagicons.lipis.dev/flags/4x3/br.svg" alt="Português">
</button>
<button class="flag-button" onclick="loadQuotes('quotes_it.txt', 'Ispirazione Quotidiana')" aria-label="Italiano">
<img src="https://flagicons.lipis.dev/flags/4x3/it.svg" alt="Italiano">
</button>
</div>
<canvas id="quoteImage" width="1080" height="1080"></canvas>
<script>
let currentQuotes = [];
let currentIndex = 0;
async function loadQuotes(file, headerTitle) {
document.getElementById("header-title").textContent = headerTitle;
document.getElementById("quote").classList.add("loading");
try {
const response = await fetch(`https://raw.githubusercontent.com/hipnologo/daily_quote/main/${file}`);
if (!response.ok) {
throw new Error("Failed to fetch quotes");
}
const quotesText = await response.text();
currentQuotes = quotesText.trim().split("\n");
if (currentQuotes.length === 0) {
throw new Error("No quotes found");
}
currentIndex = Math.floor(Math.random() * currentQuotes.length);
displayQuote();
} catch (error) {
console.error("Error:", error.message);
document.getElementById("quote").textContent = "Error: Failed to retrieve quotes. Please try again.";
} finally {
document.getElementById("quote").classList.remove("loading");
}
}
function refreshPage() {
setTimeout(function() {
location.reload();
}, 5 * 60 * 1000); // Refresh the page every 5 minutes
}
function displayQuote() {
const quoteElement = document.getElementById("quote");
quoteElement.style.opacity = "0";
setTimeout(() => {
quoteElement.textContent = currentQuotes[currentIndex];
quoteElement.style.opacity = "1";
}, 300);
}
function nextQuote() {
currentIndex = (currentIndex + 1) % currentQuotes.length;
displayQuote();
}
function prevQuote() {
currentIndex = (currentIndex - 1 + currentQuotes.length) % currentQuotes.length;
displayQuote();
}
function readQuote() {
const quote = document.getElementById("quote").textContent;
const utterance = new SpeechSynthesisUtterance(quote);
window.speechSynthesis.speak(utterance);
}
function shareOnX() {
const quote = document.getElementById("quote").textContent;
const xUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(quote + " - Daily Inspiration")}`;
window.open(xUrl, '_blank');
}
function shareOnFacebook() {
const quote = document.getElementById("quote").textContent;
const facebookUrl = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(window.location.href)}"e=${encodeURIComponent(quote)}`;
window.open(facebookUrl, '_blank');
}
function shareOnLinkedIn() {
const quote = document.getElementById("quote").textContent;
const linkedInUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${encodeURIComponent(window.location.href)}&title=${encodeURIComponent("Daily Inspiration")}&summary=${encodeURIComponent(quote)}`;
window.open(linkedInUrl, '_blank');
}
async function shareOnInstagram() {
const quoteWrapper = document.getElementById('quoteWrapper');
const canvas = document.getElementById('quoteImage');
const ctx = canvas.getContext('2d');
ctx.fillStyle = document.body.classList.contains('dark-mode') ? '#1a202c' : '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
const quoteImage = await html2canvas(quoteWrapper);
const scale = Math.min(canvas.width / quoteImage.width, canvas.height / quoteImage.height) * 0.8;
const x = (canvas.width / 2) - (quoteImage.width / 2) * scale;
const y = (canvas.height / 2) - (quoteImage.height / 2) * scale;
ctx.drawImage(quoteImage, x, y, quoteImage.width * scale, quoteImage.height * scale);
canvas.toBlob(function(blob) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'daily_inspiration_quote.png';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 'image/png');
alert("Image downloaded! You can now share it on Instagram.");
}
function toggleDarkMode() {
document.body.classList.toggle('dark-mode');
const quoteContainer = document.querySelector('.quote-container');
quoteContainer.classList.toggle('bg-white');
quoteContainer.classList.toggle('bg-gray-800');
}
// Event listeners
document.getElementById("darkModeToggle").addEventListener("click", toggleDarkMode);
document.getElementById("playButton").addEventListener("click", readQuote);
document.getElementById("nextButton").addEventListener("click", nextQuote);
document.getElementById("prevButton").addEventListener("click", prevQuote);
// Load the default quotes (English) when the page first loads
loadQuotes('quotes_pt.txt', 'Inspiração Diária');
// PWA support
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js')
.then((reg) => console.log('Service worker registered', reg))
.catch((err) => console.log('Service worker not registered', err));
}
refreshPage();
</script>
</body>
</html>