-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_studio_code.html
More file actions
427 lines (389 loc) · 19.8 KB
/
ai_studio_code.html
File metadata and controls
427 lines (389 loc) · 19.8 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Google Fonts Downloader</title>
<style>
:root {
--bg-color: #ffffff;
--text-color: #1a1a1a;
--primary-color: #007bff;
--primary-hover: #0056b3;
--border-color: #ddd;
--input-bg: #f8f9fa;
--card-bg: #ffffff;
--shadow: 0 4px 6px rgba(0,0,0,0.1);
}
body.dark-mode {
--bg-color: #121212;
--text-color: #e0e0e0;
--primary-color: #4dabf7;
--primary-hover: #1e88e5;
--border-color: #444;
--input-bg: #2a2a2a;
--card-bg: #1e1e1e;
--shadow: 0 4px 8px rgba(0,0,0,0.25);
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
margin: 0;
background-color: var(--bg-color);
color: var(--text-color);
line-height: 1.6;
transition: background-color 0.3s, color 0.3s;
}
.container {
max-width: 800px;
margin: 2rem auto;
padding: 0 1rem;
}
.site-header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 1rem;
border-bottom: 1px solid var(--border-color);
}
.logo {
font-size: 1.5rem;
font-weight: bold;
text-decoration: none;
color: var(--text-color);
}
.dark-mode-toggle {
background: none;
border: 1px solid var(--border-color);
color: var(--text-color);
cursor: pointer;
padding: 8px 12px;
border-radius: 50%;
font-size: 1.2rem;
}
.page-header { text-align: center; margin-bottom: 2rem; }
h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
h2 { border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; margin-top: 2.5rem; }
.tool-container {
background-color: var(--card-bg);
padding: 2rem;
border-radius: 8px;
box-shadow: var(--shadow);
border: 1px solid var(--border-color);
}
.control-group { margin-bottom: 1.5rem; }
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
}
.tool-input, .tool-select {
width: 100%;
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: 4px;
background-color: var(--input-bg);
color: var(--text-color);
font-size: 1rem;
}
.tool-button {
width: 100%;
padding: 0.85rem;
font-size: 1.1rem;
font-weight: bold;
color: #fff;
background-color: var(--primary-color);
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
.tool-button:hover:not(:disabled) { background-color: var(--primary-hover); }
.tool-button:disabled { background-color: #888; cursor: not-allowed; }
.status-message {
margin-top: 1rem;
padding: 1rem;
border-radius: 4px;
text-align: center;
}
.status-message.success { background-color: #d4edda; color: #155724; }
.status-message.error { background-color: #f8d7da; color: #721c24; }
.status-message.info { background-color: #cce5ff; color: #004085; }
.content-section p { margin-bottom: 1.5rem; }
.content-section strong { color: var(--text-color); }
code { background-color: var(--input-bg); padding: 2px 5px; border-radius: 3px; }
.site-footer {
text-align: center;
margin-top: 3rem;
padding: 1.5rem;
border-top: 1px solid var(--border-color);
font-size: 0.9rem;
}
</style>
</head>
<body>
<header class="site-header">
<div class="container">
<a href="./index.html" class="logo">TinyFont</a>
<nav class="main-nav" aria-label="Main Navigation">
<ul>
<li class="nav-item">
<a href="#" class="nav-link" aria-haspopup="true">Font Discovery</a>
<div class="dropdown-menu">
<a href="./live-preview-tool.html">Live Google Font Previewer</a>
<a href="./font-comparison-tool.html">Compare Fonts Instantly</a>
<a href="./variable-font-finder.html">Discover Variable Google Fonts</a>
<a href="./language-support-finder.html">Find Fonts for Any Language</a>
</div>
</li>
<li class="nav-item">
<a href="#" class="nav-link" aria-haspopup="true">Design & Typography</a>
<div class="dropdown-menu">
<a href="./font-pairing-generator.html">Generate Beautiful Font Pairings</a>
<a href="./logo-fonts-tool.html">Find the Perfect Font for Your Logo</a>
<a href="./font-color-tester.html">Test Font Color Contrast</a>
<a href="./font-performance-checker.html">Analyze Font Performance Impact</a>
</div>
</li>
<li class="nav-item">
<a href="#" class="nav-link" aria-haspopup="true">Performance & Web</a>
<div class="dropdown-menu">
<a href="./google-fonts-css-generator.html">Generate Optimized Font CSS</a>
<a href="./css-font-stack-generator.html">Create Bulletproof CSS Font Stacks</a>
<a href="./web-safe-fonts-checker.html">Web Safe Font Reference</a>
</div>
</li>
<li class="nav-item">
<a href="#" class="nav-link" aria-haspopup="true">Guides</a>
<div class="dropdown-menu">
<a href="./font-accessibility-checker.html">Advanced Font Accessibility Checker</a>
<a href="./font-license-checker.html">Google Fonts License Checker</a>
<a href="./font-subset-optimizer.html">Google Fonts Subset Optimizer</a>
<a href="./subset-text-optimizer.html">Font Subsetting Text Generator</a>
</div>
</li>
<li class="nav-item">
<a href="#" class="nav-link" aria-haspopup="true">Developer Tools</a>
<div class="dropdown-menu">
<a href="./epoch-unix-converter/">Epoch Unix Converter</a>
<a href="./codigos-de-colores-hexadecimales/">Convertidor de Códigos de Colores Hexadecimales</a>
</div>
</li>
</ul>
</nav>
<div class="header-controls">
<button class="dark-mode-toggle" title="Toggle Dark Mode">🌙</button>
<button class="mobile-nav-toggle" aria-controls="main-nav" aria-expanded="false" aria-label="Toggle Navigation">☰</button>
</div>
</div>
</header>
<main>
<div class="container">
<header class="page-header">
<h1>Google Fonts Downloader</h1>
<p>Download any Google Font family as a single .zip file directly from your browser.</p>
</header>
<div class="tool-container">
<div class="control-group">
<label for="apiKey">1. Enter Your Google Fonts API Key</label>
<input type="text" id="apiKey" class="tool-input" placeholder="Paste your API key here">
<small>Your API key is required and used only in your browser. <a href="https://developers.google.com/fonts/docs/developer_api#APIKey" target="_blank" rel="noopener">Get an API key here</a>.</small>
</div>
<div class="control-group">
<label for="fontSelector">2. Select a Font Family</label>
<select id="fontSelector" class="tool-select" disabled>
<option>Enter API key first...</option>
</select>
</div>
<div class="control-group">
<button id="downloadBtn" class="tool-button" disabled>Download .zip</button>
</div>
<div id="status" class="status-message" style="display: none;"></div>
</div>
<section id="how-to" class="content-section">
<h2>How to Use This Tool</h2>
<p>1. <strong>Get an API Key:</strong> You must have a Google Fonts Developer API key. If you don't have one, you can get it for free from the <a href="https://developers.google.com/fonts/docs/developer_api#APIKey" target="_blank" rel="noopener">Google Cloud Console</a>. Make sure the "Web Fonts Developer API" is enabled for your project.</p>
<p>2. <strong>Paste Your Key:</strong> Enter your key into the input field above. The font list will load automatically.</p>
<p>3. <strong>Select a Font:</strong> Choose your desired font from the dropdown list.</p>
<p>4. <strong>Download:</strong> Click the "Download .zip" button to generate and save a zip file containing all `.ttf` font files for that family.</p>
</section>
<section id="faqs" class="content-section">
<h2>Frequently Asked Questions</h2>
<p><strong>Q: Is this secure?</strong><br>A: Yes. Your API key and all operations happen entirely within your browser. Nothing is sent to or stored on any server.</p>
<p><strong>Q: Why do I need an API key?</strong><br>A: Google requires an API key to access its list of fonts. This prevents abuse and helps them track usage of their service. This tool simply provides a user interface for that API.</p>
<p><strong>Q: What files are in the .zip?</strong><br>A: The zip file contains all available `.ttf` font files for the selected family (e.g., Roboto-Regular.ttf, Roboto-Bold.ttf, Roboto-Italic.ttf).</p>
</section>
</div>
</main>
<footer class="site-footer">
<div class="container">
<div class="footer-grid">
<div class="footer-column">
<h4>Font Discovery</h4>
<ul>
<li><a href="./live-preview-tool.html">Live Google Font Previewer</a></li>
<li><a href="./font-comparison-tool.html">Compare Fonts Instantly</a></li>
<li><a href="./variable-font-finder.html">Discover Variable Google Fonts</a></li>
<li><a href="./language-support-finder.html">Find Fonts for Any Language</a></li>
</ul>
</div>
<div class="footer-column">
<h4>Design & Typography</h4>
<ul>
<li><a href="./font-pairing-generator.html">Generate Beautiful Font Pairings</a></li>
<li><a href="./logo-fonts-tool.html">Find the Perfect Font for Your Logo</a></li>
<li><a href="./font-color-tester.html">Test Font Color Contrast</a></li>
<li><a href="./font-performance-checker.html">Analyze Font Performance Impact</a></li>
</ul>
</div>
<div class="footer-column">
<h4>Performance & Web</h4>
<ul>
<li><a href="./google-fonts-css-generator.html">Generate Optimized Font CSS</a></li>
<li><a href="./css-font-stack-generator.html">Create Bulletproof CSS Font Stacks</a></li>
<li><a href="./web-safe-fonts-checker.html">Web Safe Font Reference</a></li>
</ul>
</div>
<div class="footer-column">
<h4>Guides</h4>
<ul>
<li><a href="./accessibility-checker.html">Check Font Accessibility</a></li>
<li><a href="./subset-text-optimizer.html">Font Subsetting Text Generator</a></li>
</ul>
</div>
<div class="footer-column">
<h4>Developer Tools</h4>
<ul>
<li><a href="./epoch-unix-converter/">Epoch Unix Converter</a></li>
<li><a href="./codigos-de-colores-hexadecimales/">Convertidor de Códigos de Colores Hexadecimales</a></li>
</ul>
</div>
</div>
<div class="footer-bottom">
<p>© 2025 Prasoon. Built with ❤️ at TinyFont.me.</p>
<p>Last updated: August 21, 2025</p>
</div>
</div>
</footer>
<!-- JSZip Library for creating zip files in the browser -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script>
const apiKeyInput = document.getElementById('apiKey');
const fontSelector = document.getElementById('fontSelector');
const downloadBtn = document.getElementById('downloadBtn');
const statusDiv = document.getElementById('status');
const darkModeToggle = document.querySelector('.dark-mode-toggle');
let allFonts = [];
let selectedFont = null;
// --- Dark Mode Logic ---
const setDarkMode = (isDark) => {
document.body.classList.toggle('dark-mode', isDark);
darkModeToggle.textContent = isDark ? '☀️' : '🌙';
localStorage.setItem('darkMode', isDark);
};
darkModeToggle.addEventListener('click', () => {
const isDark = document.body.classList.contains('dark-mode');
setDarkMode(!isDark);
});
// Initialize dark mode from user's preference
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const savedMode = localStorage.getItem('darkMode');
setDarkMode(savedMode === null ? prefersDark : savedMode === 'true');
// --- Main Application Logic ---
function showStatus(message, type = 'info') {
statusDiv.textContent = message;
statusDiv.className = `status-message ${type}`;
statusDiv.style.display = 'block';
}
async function fetchFonts() {
const apiKey = apiKeyInput.value.trim();
if (!apiKey) {
showStatus('Please enter a valid API key.', 'error');
return;
}
showStatus('Loading fonts from Google API...', 'info');
fontSelector.disabled = true;
fontSelector.innerHTML = '<option>Loading...</option>';
try {
const response = await fetch(`https://www.googleapis.com/webfonts/v1/webfonts?key=${apiKey}&sort=alpha`);
if (response.status === 403) {
throw new Error('API request forbidden (403). Please check your API key and ensure it is valid and has no restrictions.');
}
if (!response.ok) {
throw new Error(`API request failed with status: ${response.status}`);
}
const data = await response.json();
if (!data.items || data.items.length === 0) {
throw new Error('API returned no fonts. The response may be malformed.');
}
allFonts = data.items;
fontSelector.innerHTML = allFonts.map(font => `<option value="${font.family}">${font.family}</option>`).join('');
fontSelector.disabled = false;
downloadBtn.disabled = false;
statusDiv.style.display = 'none';
} catch (error) {
showStatus(`Error: ${error.message}`, 'error');
fontSelector.innerHTML = '<option>Failed to load fonts</option>';
}
}
async function handleDownload() {
const selectedFontFamily = fontSelector.value;
if (!selectedFontFamily) return;
selectedFont = allFonts.find(f => f.family === selectedFontFamily);
if (!selectedFont) {
showStatus('Could not find the selected font details.', 'error');
return;
}
downloadBtn.disabled = true;
fontSelector.disabled = true;
showStatus(`Downloading ${Object.keys(selectedFont.files).length} font files for ${selectedFont.family}...`, 'info');
try {
const zip = new JSZip();
const filePromises = Object.entries(selectedFont.files).map(async ([variant, url]) => {
// Google's API returns http links, but they support https.
const secureUrl = url.replace('http://', 'https://');
// To get around CORS issues, we can use a proxy. For this client-side solution,
// we'll try a public CORS proxy. A more robust solution would be your own.
const proxyUrl = `https://cors-anywhere.herokuapp.com/${secureUrl}`;
const response = await fetch(proxyUrl);
if (!response.ok) {
// Fallback to trying direct fetch if proxy fails
const directResponse = await fetch(secureUrl);
if (!directResponse.ok) {
throw new Error(`Failed to fetch font variant: ${variant}`);
}
return { variant, data: await directResponse.arrayBuffer() };
}
return { variant, data: await response.arrayBuffer() };
});
const files = await Promise.all(filePromises);
files.forEach(({ variant, data }) => {
const filename = `${selectedFont.family.replace(/ /g, '-')}-${variant}.ttf`;
zip.file(filename, data);
});
const zipBlob = await zip.generateAsync({ type: 'blob' });
const link = document.createElement('a');
link.href = URL.createObjectURL(zipBlob);
link.download = `${selectedFont.family.replace(/ /g, '-')}.zip`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
showStatus(`Successfully created ${selectedFont.family}.zip!`, 'success');
} catch (error) {
showStatus(`Download failed. This is often due to browser security (CORS) preventing direct font file downloads. Error: ${error.message}`, 'error');
} finally {
downloadBtn.disabled = false;
fontSelector.disabled = false;
}
}
// Use 'input' event for real-time feedback after the user stops typing
let debounceTimer;
apiKeyInput.addEventListener('input', () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
fetchFonts();
}, 500); // Wait 500ms after user stops typing
});
downloadBtn.addEventListener('click', handleDownload);
</script>
</body>
</html>