forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfonts.html
More file actions
562 lines (501 loc) · 22.8 KB
/
fonts.html
File metadata and controls
562 lines (501 loc) · 22.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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Installed Font Detector — Preview installed fonts and generate ?font links</title>
<meta name="description" content="Detect installed fonts in your browser, preview live samples, and copy URL parameter links (?font=) compatible with VDO.Ninja, SocialStream.Ninja, and Caption.Ninja." />
<meta name="robots" content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" />
<meta name="author" content="Installed Font Detector" />
<meta name="keywords" content="fonts, installed fonts, detect fonts, browser fonts, font preview, url parameter, vdo.ninja, socialstream.ninja, caption.ninja" />
<meta name="theme-color" content="#0f1221" />
<!-- Open Graph -->
<meta property="og:type" content="website" />
<meta property="og:title" content="Installed Font Detector" />
<meta property="og:description" content="Preview your system fonts and generate ?font= links compatible with VDO.Ninja, SocialStream.Ninja, and Caption.Ninja." />
<meta property="og:locale" content="en_US" />
<!-- Twitter Cards -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Installed Font Detector" />
<meta name="twitter:description" content="Preview installed fonts and copy ?font= links for Ninja apps." />
<!-- Structured data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebApplication",
"name": "Installed Font Detector",
"applicationCategory": "Utility",
"operatingSystem": "Windows, macOS, Linux, ChromeOS",
"isAccessibleForFree": true,
"inLanguage": "en",
"description": "Detects installed fonts in your browser, previews them, and generates ?font= URL parameters compatible with VDO.Ninja, SocialStream.Ninja, and Caption.Ninja.",
"featureList": [
"Detect installed fonts via text-metric comparison",
"Optional Local Fonts API for precise enumeration",
"Generate ?font=<family> links",
"Compatibility with VDO.Ninja, SocialStream.Ninja, Caption.Ninja"
],
"softwareRequirements": "Optional Local Fonts API requires Chromium-based browser on HTTPS/localhost and user permission.",
"sameAs": [
"https://vdo.ninja",
"https://socialstream.ninja",
"https://caption.ninja"
]
}
</script>
<style>
:root {
--font-family: Avenir Next, Sora, Roboto, Helvetica, Geneva, Verdana, Arial, sans-serif;
--bg: #0f1221;
--panel: #171a2b;
--text: #e7e9f4;
--muted: #a8aec9;
--accent: #7ab6ff;
--ok: #47d16a;
--warn: #ffb020;
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
--radius: 10px;
}
html, body {
height: 100%;
}
body {
margin: 0;
background: var(--bg);
color: var(--text);
font-family: var(--font-family);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.wrap {
max-width: 1100px;
margin: 24px auto 80px;
padding: 0 16px;
}
header h1 {
margin: 0 0 6px 0;
font-size: 28px;
}
header p {
margin: 0 0 16px 0;
color: var(--muted);
}
.controls {
display: grid;
grid-template-columns: 1fr auto auto auto;
gap: 10px;
align-items: center;
background: var(--panel);
border-radius: var(--radius);
padding: 12px;
position: sticky;
top: 0;
z-index: 1;
}
.controls input[type="text"] {
width: 100%;
padding: 10px 12px;
border-radius: 8px;
border: 1px solid #2a2e44;
background: #0f1221;
color: var(--text);
}
.controls button, .controls a.button {
padding: 10px 12px;
border-radius: 8px;
border: 1px solid #2a2e44;
background: #0f1221;
color: var(--text);
cursor: pointer;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 8px;
}
.controls .count {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.results {
margin-top: 16px;
display: grid;
grid-template-columns: 1fr;
gap: 8px;
}
.row {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
align-items: center;
background: var(--panel);
border-radius: var(--radius);
padding: 12px;
border: 1px solid #20243a;
}
.sample {
font-size: 18px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.meta {
display: grid;
gap: 6px;
justify-items: end;
}
.fontname {
font-weight: 600;
}
.link {
font-family: var(--mono);
font-size: 12px;
color: var(--muted);
user-select: all;
}
.link a {
color: var(--accent);
text-decoration: none;
}
.badge {
font-size: 11px;
padding: 2px 6px;
border-radius: 999px;
border: 1px solid #2a2e44;
color: var(--muted);
}
.footer {
margin-top: 40px;
background: var(--panel);
border-radius: var(--radius);
padding: 24px 28px;
border: 1px solid #20243a;
line-height: 1.6;
}
.footer h2 {
margin: 0 0 12px 0;
font-size: 18px;
}
.footer ul {
margin: 12px 0 0 24px;
padding: 0;
color: var(--muted);
}
.footer li { margin: 6px 0; }
.footer code {
font-family: var(--mono);
background: #0f1221;
padding: 2px 6px;
border-radius: 6px;
border: 1px solid #2a2e44;
color: #cfe2ff;
}
.note {
color: var(--muted);
font-size: 13px;
margin-top: 14px;
}
@media (min-width: 900px) {
.results {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>Installed Font Detector</h1>
<p>Lists fonts your browser can use, shows a live sample, and provides a URL parameter to apply the font site‑wide.</p>
</header>
<div class="controls">
<input id="filter" type="text" placeholder="Filter fonts (e.g. Segoe, Mono, Arabic)" />
<button id="tryLocalFonts" title="Requests permission (if supported) to list local fonts via the Local Fonts API">Try Local Fonts API</button>
<label class="count" style="display:flex;align-items:center;gap:6px;white-space:nowrap;">
<input id="facesToggle" type="checkbox" /> Show faces
</label>
<div class="count" id="count">Detecting…</div>
</div>
<div class="results" id="results" role="list"></div>
<div class="footer">
<h2>Using a specific font via URL</h2>
<ul>
<li><b>Param:</b> Append <code>?font=<Font%20Family%20Name></code> to the URL. Spaces and symbols must be URL‑encoded.</li>
<li><b>Applies to CSS var:</b> Your site uses <code>--font-family</code>; this page also respects it. Example: <code>?font=Segoe%20UI</code>.</li>
<li><b>Quotes not needed:</b> Do not include quotes in the parameter; they are not required in the CSS variable.</li>
<li><b>Installed only:</b> The parameter only works for fonts already installed on your system. It does not download webfonts.</li>
</ul>
<h2>Compatibility (Ninja apps)</h2>
<ul>
<li><b>VDO.Ninja:</b> Generated <code>?font=</code> links work with overlays/scenes that honor the <code>--font-family</code> variable.</li>
<li><b>SocialStream.Ninja:</b> Use the same <code>?font=</code> parameter to override the default font in supported widgets.</li>
<li><b>Caption.Ninja:</b> Apply <code>?font=</code> to caption overlays that support custom font families.</li>
</ul>
<p class="note">These apps accept a font-family override when the <code>?font=</code> parameter is supported in their URLs or embed links. This tool generates properly encoded values for drop‑in use.</p>
<h2>Troubleshooting (Windows)</h2>
<ul>
<li><b>Exact family name:</b> Use the font’s <i>family</i> name (not file name). Check Settings → Personalization → Fonts for the proper family label.</li>
<li><b>Right install scope:</b> If you installed a font for a different Windows user or via an admin account only, your browser session may not see it. Install “for all users” if needed.</li>
<li><b>Supported formats:</b> Browsers use TrueType/OpenType/WOFF. Legacy Type 1 and some bitmap fonts won’t work.</li>
<li><b>Weight/style availability:</b> If only Bold is installed, Normal text may fall back. Try a bold sample or install Regular as well.</li>
<li><b>Privacy limits:</b> Browsers don’t allow full font enumeration without permission. This page detects from a large known list and optional Local Fonts API.</li>
<li><b>Local Fonts API:</b> In Chromium on secure origins (https/localhost), clicking “Try Local Fonts API” can list your exact installed families after permission.</li>
</ul>
<h2>Manual usage tips</h2>
<ul>
<li><b>Force a font:</b> In your CSS: <code>font-family: "Your Family", Avenir Next, Sora, Roboto, Helvetica, Arial, sans-serif;</code></li>
<li><b>Test an arbitrary name:</b> Use the search box to try any family; if found, it appears in results with a sample.</li>
<li><b>Encoding:</b> Build links like: <code>?font=<span id="egFont">Segoe%20UI</span></code> (generated links below use proper encoding).</li>
<li><b>CJK and script fonts:</b> The sample includes Latin, numerals, and symbols. Replace with script‑specific text to verify shaping.</li>
</ul>
<p class="note">Note: This page does not install or download fonts; it only detects and previews families already available to your browser.</p>
</div>
</div>
<script>
// Respect the provided code for applying a font from URL params
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get("font")) {
const rawFont = urlParams.get("font").trim();
// Strip any surrounding quotes from the param and quote the family in CSS
const cleanFont = rawFont.replace(/^['"]|['"]$/g, "");
document.documentElement.style.setProperty(
"--font-family",
`"${cleanFont}", Sora, Roboto, Helvetica, Geneva, Verdana, Arial, sans-serif`
);
}
const resultsEl = document.getElementById('results');
const countEl = document.getElementById('count');
const filterEl = document.getElementById('filter');
const facesToggleEl = document.getElementById('facesToggle');
// A broad list of common fonts across Windows/macOS/Linux + popular developer/Google fonts.
// Detection works by comparing text metrics against generic base families.
const CANDIDATE_FONTS = Array.from(new Set([
// Windows core UI/text
'Segoe UI','Segoe UI Variable','Segoe UI Emoji','Segoe UI Historic','Segoe UI Symbol','Bahnschrift','Ebrima','Gadugi','Javanese Text','Leelawadee UI','Lucida Sans Unicode','Malgun Gothic','Meiryo','Microsoft Himalaya','Microsoft JhengHei','Microsoft New Tai Lue','Microsoft PhagsPa','Microsoft Sans Serif','Microsoft Tai Le','Microsoft Uighur','Microsoft YaHei','Microsoft Yi Baiti','MingLiU-ExtB','Mongolian Baiti','MS Gothic','MS PGothic','MS UI Gothic','NSimSun','PMingLiU-ExtB','SimSun','SimSun-ExtB','Yu Gothic','Yu Gothic UI',
// Windows Latin staples
'Arial','Arial Black','Calibri','Cambria','Candara','Comic Sans MS','Consolas','Constantia','Corbel','Courier New','Franklin Gothic Medium','Gabriola','Georgia','Impact','Palatino Linotype','Tahoma','Times New Roman','Trebuchet MS','Verdana','Symbol','Webdings','Wingdings','Wingdings 2','Wingdings 3','Sitka Banner','Sitka Display','Sitka Heading','Sitka Small','Sitka Subheading','Sitka Text','Lucida Console',
// Developer favorites / code
'Cascadia Code','Cascadia Mono','Fira Code','Fira Mono','JetBrains Mono','Source Code Pro','IBM Plex Mono','Ubuntu Mono','Inconsolata','Monaspace Neon','Monaspace Argon',
// Popular sans/serif families
'Inter','Roboto','Open Sans','Noto Sans','Noto Serif','Noto Sans JP','Noto Sans KR','Noto Sans SC','Noto Serif JP','Noto Naskh Arabic','Lato','Montserrat','Poppins','Oswald','Raleway','Nunito','Merriweather','Playfair Display','PT Sans','PT Serif','Source Sans 3','Source Serif 4','Source Sans Pro','Source Serif Pro','IBM Plex Sans','IBM Plex Serif','Ubuntu','Work Sans','Sora','Avenir','Avenir Next','SF Pro Text','SF Pro Display','Helvetica Neue','Helvetica','Gill Sans',
// Other common
'Book Antiqua','Century Gothic','Garamond','Didot','Bodoni MT','Perpetua','Rockwell','Goudy Old Style','Copperplate','Brush Script MT','Candara',
].sort((a,b)=>a.localeCompare(b))))
// Base families used for measuring vs installed font.
const BASES = ['serif','sans-serif','monospace'];
// Measurement string chosen to amplify dimension differences
const TEST_STRING = 'mmmmmmmmmmlliWWQy #@ 0123456789 The quick brown fox';
const TEST_SIZE = '72px';
function createMeasureSpan(base) {
const s = document.createElement('span');
s.textContent = TEST_STRING;
s.style.position = 'absolute';
s.style.left = '-9999px';
s.style.top = '-9999px';
s.style.fontSize = TEST_SIZE;
s.style.fontVariantLigatures = 'none';
s.style.whiteSpace = 'nowrap';
s.style.fontFamily = base;
document.body.appendChild(s);
return s;
}
function metricsFor(base) {
const el = createMeasureSpan(base);
const w = el.offsetWidth;
const h = el.offsetHeight;
el.remove();
return { w, h };
}
// Detect if a font is available by comparing width/height against all base families.
function isFontAvailable(fontName) {
try {
const baseline = BASES.map(b => metricsFor(b));
// If any base differs once we prepend the font, it's likely installed
return BASES.some((b, i) => {
const el = createMeasureSpan(`"${fontName}", ${b}`);
const different = el.offsetWidth !== baseline[i].w || el.offsetHeight !== baseline[i].h;
el.remove();
return different;
});
} catch (e) {
return false;
}
}
function applyFilter(filter, items) {
if (!filter) return items;
const q = filter.trim().toLowerCase();
if (!q) return items;
return items.filter(item => {
if (typeof item === 'string') return item.toLowerCase().includes(q);
const hay = [item.family, item.fullName, item.style, item.weight, item.postscriptName].filter(Boolean).join(' ').toLowerCase();
return hay.includes(q);
});
}
function makeRow(item) {
const isFace = typeof item === 'object' && item && 'family' in item;
const name = isFace ? item.family : item;
const row = document.createElement('div');
row.className = 'row';
const sample = document.createElement('div');
sample.className = 'sample';
sample.style.fontFamily = `"${name}", Avenir Next, Sora, Roboto, Helvetica, Geneva, Verdana, Arial, sans-serif`;
if (isFace) {
if (item.weight) sample.style.fontWeight = String(item.weight);
if (item.style) sample.style.fontStyle = item.style;
if (item.stretch) sample.style.fontStretch = item.stretch;
}
const faceSuffix = isFace ? ` (${[item.style||'normal', item.weight||'400'].filter(Boolean).join(', ')})` : '';
sample.textContent = `${name}${faceSuffix} — The quick brown fox jumps over the lazy dog 0123456789`;
row.appendChild(sample);
const meta = document.createElement('div');
meta.className = 'meta';
const fontname = document.createElement('div');
fontname.className = 'fontname';
fontname.textContent = name + (isFace && item.fullName ? ` — ${item.fullName}` : '');
const link = document.createElement('div');
link.className = 'link';
const enc = encodeURIComponent(name);
const param = `?font=${enc}`;
const url = `${location.origin}${location.pathname}${param}`;
link.innerHTML = `<span class="badge">Param</span> <a href="${param}">${param}</a>`;
const copyBtn = document.createElement('button');
copyBtn.className = 'button';
copyBtn.textContent = 'Copy param';
copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(param);
copyBtn.textContent = 'Copied!';
setTimeout(() => (copyBtn.textContent = 'Copy param'), 1200);
} catch {
window.prompt('Copy param:', param);
}
});
meta.appendChild(fontname);
meta.appendChild(link);
meta.appendChild(copyBtn);
row.appendChild(meta);
return row;
}
function render(list) {
resultsEl.innerHTML = '';
const frag = document.createDocumentFragment();
list.forEach(item => frag.appendChild(makeRow(item)));
resultsEl.appendChild(frag);
countEl.textContent = `${list.length} item(s)`;
}
async function detectFromCandidates(candidates) {
const seen = new Set();
const found = [];
for (const name of candidates) {
if (seen.has(name)) continue;
seen.add(name);
if (isFontAvailable(name)) found.push(name);
}
found.sort((a,b)=>a.localeCompare(b));
return found;
}
// Optional: Use Local Fonts API if supported + permitted
async function tryLocalFontsAPI() {
if (!('queryLocalFonts' in window)) {
alert('Local Fonts API not supported in this browser. Use recent Chromium on HTTPS/localhost.');
return [];
}
try {
const families = new Set();
const fonts = await window.queryLocalFonts();
// Keep faces for optional detailed listing
window.__FACES__ = fonts.map(f => ({
family: f.family,
fullName: f.fullName,
postscriptName: f.postscriptName,
style: f.style,
weight: f.weight,
stretch: f.stretch,
}));
for (const f of fonts) {
if (f.family) families.add(f.family);
}
return Array.from(families).sort((a,b)=>a.localeCompare(b));
} catch (err) {
console.warn('Local Fonts API error:', err);
alert('Could not access local fonts. The browser may require HTTPS/localhost and user approval.');
return [];
}
}
async function getLocalFontsIfGranted() {
if (!('queryLocalFonts' in window) || !('permissions' in navigator)) return [];
try {
const status = await navigator.permissions.query({ name: 'local-fonts' });
if (status.state === 'granted') {
const families = await tryLocalFontsAPI();
return families;
}
} catch (e) {
// Ignore if permissions API doesn't recognize 'local-fonts'
}
return [];
}
// Initial detection
(async function init() {
// If a font is set via URL param, reflect it in example in the “Manual usage tips”
const eg = document.getElementById('egFont');
if (eg) eg.textContent = encodeURIComponent(urlParams.get('font') || 'Segoe UI');
countEl.textContent = 'Detecting…';
const detected = await detectFromCandidates(CANDIDATE_FONTS);
window.__ALL_DETECTED__ = detected; // families
// If permission already granted, auto-merge Local Fonts API
const grantedFamilies = await getLocalFontsIfGranted();
if (grantedFamilies.length) {
const merged = Array.from(new Set([...(window.__ALL_DETECTED__||[]), ...grantedFamilies]));
merged.sort((a,b)=>a.localeCompare(b));
window.__ALL_DETECTED__ = merged;
}
const initialList = (facesToggleEl && facesToggleEl.checked && window.__FACES__) ? window.__FACES__ : window.__ALL_DETECTED__;
render(initialList);
// Filter UI
filterEl.addEventListener('input', () => {
const facesOn = facesToggleEl && facesToggleEl.checked && window.__FACES__;
const base = facesOn ? window.__FACES__ : (window.__ALL_DETECTED__ || []);
const list = applyFilter(filterEl.value, base);
render(list);
});
// Allow trying arbitrary names by typing and pressing Enter
filterEl.addEventListener('keydown', async (e) => {
if (e.key === 'Enter') {
const name = filterEl.value.trim();
if (!name) return;
if (!window.__ALL_DETECTED__.includes(name) && isFontAvailable(name)) {
window.__ALL_DETECTED__ = [...window.__ALL_DETECTED__, name].sort((a,b)=>a.localeCompare(b));
}
const facesOn = facesToggleEl && facesToggleEl.checked && window.__FACES__;
const base = facesOn ? window.__FACES__ : window.__ALL_DETECTED__;
const list = applyFilter(filterEl.value, base);
render(list);
}
});
// Local Fonts API button
document.getElementById('tryLocalFonts').addEventListener('click', async () => {
const families = await tryLocalFontsAPI();
if (families.length) {
// Merge Local Fonts API results with detected list
const merged = Array.from(new Set([...(window.__ALL_DETECTED__||[]), ...families]));
merged.sort((a,b)=>a.localeCompare(b));
window.__ALL_DETECTED__ = merged;
const facesOn = facesToggleEl && facesToggleEl.checked && window.__FACES__;
const base = facesOn ? window.__FACES__ : merged;
const list = applyFilter(filterEl.value, base);
render(list);
}
});
// Faces toggle
if (facesToggleEl) {
facesToggleEl.addEventListener('change', () => {
const facesOn = facesToggleEl.checked && window.__FACES__;
const base = facesOn ? window.__FACES__ : (window.__ALL_DETECTED__ || []);
const list = applyFilter(filterEl.value, base);
render(list);
});
}
})();
</script>
</body>
</html>