-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
280 lines (235 loc) · 9.6 KB
/
Copy pathscript.js
File metadata and controls
280 lines (235 loc) · 9.6 KB
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
const quotes = [
"Idk why we picked this textbook",
"Go fuck off, you're nowhere near as significant as me",
"If there are any terrorists in this class, 151 Front Street W is a great place to blow up",
"I wouldn't show you porn either",
"Don't go around telling your parents you have a physical connection with your teacher",
"Inspired me to kidnap somebody and write a demand letter",
"You dumbasses always think more is better",
"WiFi is a big swimming pool and there are still people peeing in it",
"I think I'm getting some kind of senile disease",
"During class you can walk out any time. Hopefully in a dramatic fashion",
"Let's say I go crazy, that actually happened a couple years ago",
"We got a bunch of idiots, their full title is programmer",
"This network should have been taken out and shot",
"WiFi is completely useless",
"I hate you all (Oops, did I say that?)",
"Why the hell do we use this useless piece of shit",
"Anyone still listen to radio? ...You do! Ha! Loser.",
"Okay, I'm officially fucking old now",
"I will politely ignore all the emails begging for more marks",
"Aside from learning that hackers are secret vampires"
];
const emojis = ["💀", "👨🏫", "😈", "👻", "🧛", "👽"];
let currentQuoteIndex = -1;
let previousQuoteIndex = -1;
let usedQuotes = new Set(); // Track used quotes to ensure better distribution
const quoteContainer = document.getElementById('quote-container');
const quoteText = document.getElementById('quote-text');
const newQuoteBtn = document.getElementById('new-quote-btn');
const disclaimerModal = document.getElementById('disclaimer-modal');
const mainContent = document.getElementById('main-content');
const footer = document.getElementById('footer');
const acceptDisclaimerBtn = document.getElementById('accept-disclaimer');
// Handle disclaimer acceptance
acceptDisclaimerBtn.addEventListener('click', () => {
disclaimerModal.style.display = 'none';
mainContent.classList.remove('hidden');
footer.classList.remove('hidden');
displayNewQuote();
createParticles();
});
function getRandomQuote() {
// If we've used all quotes, reset the used quotes set
if (usedQuotes.size === quotes.length) {
usedQuotes.clear();
}
// Get available quotes (those not in usedQuotes)
const availableQuotes = quotes.filter((_, index) => !usedQuotes.has(index));
// Select a random quote from available quotes
const randomIndex = Math.floor(Math.random() * availableQuotes.length);
const selectedQuoteIndex = quotes.indexOf(availableQuotes[randomIndex]);
// Add the selected quote to used quotes
usedQuotes.add(selectedQuoteIndex);
return quotes[selectedQuoteIndex];
}
function getRandomEmoji() {
return emojis[Math.floor(Math.random() * emojis.length)];
}
// Share functionality
const shareBtn = document.getElementById('share-btn');
let currentQuote = '';
async function generateQuoteImage() {
// Create canvas with higher resolution
const scale = 2; // Scale factor for retina displays
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// Set canvas size with higher resolution
canvas.width = 800 * scale;
canvas.height = 400 * scale;
// Scale context to match the higher resolution
ctx.scale(scale, scale);
// Enable text antialiasing
ctx.imageSmoothingEnabled = true;
ctx.textRendering = 'geometricPrecision';
// Background gradient
const gradient = ctx.createLinearGradient(0, 0, canvas.width / scale, canvas.height / scale);
gradient.addColorStop(0, '#1a1a2e');
gradient.addColorStop(1, '#16213e');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, canvas.width / scale, canvas.height / scale);
// Add particles effect with improved rendering
for (let i = 0; i < 30; i++) {
const x = Math.random() * (canvas.width / scale);
const y = Math.random() * (canvas.height / scale);
const size = Math.random() * 2 + 1;
ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
ctx.beginPath();
ctx.arc(x, y, size, 0, Math.PI * 2);
ctx.fill();
}
// Configure text with improved rendering
ctx.textAlign = 'center';
ctx.fillStyle = 'white';
// Add title with improved font
ctx.font = 'bold 32px Inter, system-ui, -apple-system, sans-serif';
ctx.fillText('Professor Quote Machine', (canvas.width / scale) / 2, 60);
// Add quote with improved font and line height
ctx.font = '24px Inter, system-ui, -apple-system, sans-serif';
const maxWidth = (canvas.width / scale) - 100;
const words = currentQuote.split(' ');
let line = '';
let y = 150;
const lineHeight = 40;
for (let word of words) {
const testLine = line + word + ' ';
const metrics = ctx.measureText(testLine);
if (metrics.width > maxWidth && line !== '') {
ctx.fillText(line, (canvas.width / scale) / 2, y);
line = word + ' ';
y += lineHeight;
} else {
line = testLine;
}
}
ctx.fillText(line, (canvas.width / scale) / 2, y);
// Add warning text with improved font
ctx.font = '16px Inter, system-ui, -apple-system, sans-serif';
ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
const warningText = '⚠️ These quotes are made up - Not real quotes from anyone';
ctx.fillText(warningText, (canvas.width / scale) / 2, y + 60);
// Add website URL with improved font
ctx.font = '14px Inter, system-ui, -apple-system, sans-serif';
ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
ctx.fillText('professor-quote-machine.com', (canvas.width / scale) / 2, (canvas.height / scale) - 30);
// Return high-quality PNG
return canvas.toDataURL('image/png', 1.0);
}
async function shareQuote() {
try {
const imageData = await generateQuoteImage();
// Convert base64 to blob
const response = await fetch(imageData);
const blob = await response.blob();
// Create file from blob
const file = new File([blob], 'professor-quote.png', { type: 'image/png' });
if (navigator.share) {
await navigator.share({
title: 'Professor Quote Machine',
text: 'Check out this professor quote!',
files: [file]
});
} else {
// Fallback: Download the image
const link = document.createElement('a');
link.href = imageData;
link.download = 'professor-quote.png';
link.click();
}
} catch (err) {
if (err.name !== 'AbortError') {
console.error('Error sharing:', err);
}
}
}
// Initialize with first quote
window.addEventListener('load', () => {
setTimeout(() => {
displayNewQuote();
createParticles();
}, 200);
});
// Button click handler
newQuoteBtn.addEventListener('click', displayNewQuote);
// Keyboard accessibility
newQuoteBtn.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
displayNewQuote();
}
});
// Create floating particles background
function createParticles() {
const particleCount = 40;
const container = document.body;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
// Random size between 1px and 3px
const size = Math.random() * 2 + 1;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
// Random position
particle.style.left = `${Math.random() * 100}%`;
particle.style.top = `${Math.random() * 100}%`;
// Random animation
const duration = Math.random() * 20 + 10;
const delay = Math.random() * 5;
particle.style.animation = `float ${duration}s ease-in-out ${delay}s infinite`;
container.appendChild(particle);
}
// Add animation for particles
const style = document.createElement('style');
style.innerHTML = `
@keyframes float {
0% {
transform: translate(0, 0) rotate(0deg);
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
transform: translate(${Math.random() * 100 - 50}px, ${Math.random() * 100 - 50}px) rotate(${Math.random() * 360}deg);
opacity: 1;
}
}
`;
document.head.appendChild(style);
}
// Remove the window.onload event since we now handle initialization in the disclaimer acceptance
window.onload = () => {
newQuoteBtn.focus();
};
function displayNewQuote() {
// First, fade out the current quote
quoteContainer.classList.remove('show');
quoteContainer.classList.add('hide');
setTimeout(() => {
// Get new quote and update the display
const newQuote = getRandomQuote();
currentQuote = newQuote; // Store current quote for sharing
const randomEmoji = getRandomEmoji();
quoteText.innerHTML = `"${newQuote}" <span class="text-gray-400">${randomEmoji}</span>`;
// Then fade in the new quote
quoteContainer.classList.remove('hide');
quoteContainer.classList.add('show');
}, 300);
}
// Add click handler for share button
shareBtn.addEventListener('click', shareQuote);
// Add keyboard accessibility for share button
shareBtn.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
shareQuote();
}
});