Skip to content

Commit 1c30ebd

Browse files
committed
Make Google Fonts snippet visible to visitors
Neat trick to make the actual `script` block in the page user-visible.
1 parent 193b3f9 commit 1c30ebd

1 file changed

Lines changed: 32 additions & 20 deletions

File tree

demo/index.html

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434

3535
h1, h2,
3636
p,
37-
pre {
37+
pre,
38+
.c-snippet {
3839
margin-bottom: 1.5rem;
3940
}
4041

@@ -96,7 +97,8 @@
9697
line-height: 1;
9798
}
9899

99-
code, kbd, samp, output, pre {
100+
code, kbd, samp, output, pre,
101+
.c-snippet{
100102
font-family: "Operator Mono", ui-monospace, monospace;
101103
}
102104

@@ -112,6 +114,16 @@
112114
text-decoration: underline;
113115
}
114116

117+
.c-snippet {
118+
display: block;
119+
background-color: #002a35;
120+
color: #829396;
121+
white-space: pre;
122+
border-radius: 4px;
123+
overflow: scroll;
124+
text-transform: none;
125+
}
126+
115127
.c-pill {
116128
display: inline-block;
117129
border: 1px solid #ccc;
@@ -210,6 +222,24 @@ <h1>Obs.js – context-aware web performance for everyone</h1>
210222
in the <code>&lt;h1&gt;</code> above—you’ll just see your
211223
<code>system-ui</code> font.</small></p>
212224

225+
<script class=c-snippet>
226+
(() => {
227+
// Only load Google Fonts if we can show rich media. In browsers that
228+
// don’t support the relevant APIs, we just go ahead and show it.
229+
//
230+
// Attach it to the end of the `body` rather than the `head` so it doesn’t
231+
// inadvertently block rendering.
232+
if (window.obs?.shouldAvoidRichMedia === true) {
233+
return;
234+
} else {
235+
const gf = document.createElement('link');
236+
gf.rel = 'stylesheet';
237+
gf.href = 'https://fonts.googleapis.com/css2?family=Fredoka:wght@300..700&display=swap';
238+
document.body.appendChild(gf);
239+
}
240+
})();
241+
</script>
242+
213243
<p>It is built and maintained by <a href=https://csswizardry.com>Harry
214244
Roberts</a> under the MIT license.</p>
215245

@@ -231,24 +261,6 @@ <h2><code>window.obs</code></h2>
231261
<p><small><strong>Note:</strong> API support varies by browser; Chromium has
232262
the broadest coverage.</small></p>
233263

234-
<script>
235-
(() => {
236-
// Only load Google Fonts if we can show rich media. In browsers that
237-
// don’t support the relevant APIs, we just go ahead and show it.
238-
//
239-
// Attach it to the end of the `body` rather than the `head` so it doesn’t
240-
// inadvertently block rendering.
241-
if (window.obs?.shouldAvoidRichMedia === true) {
242-
return;
243-
} else {
244-
const gf = document.createElement('link');
245-
gf.rel = 'stylesheet';
246-
gf.href = 'https://fonts.googleapis.com/css2?family=Fredoka:wght@300..700&display=swap';
247-
document.body.appendChild(gf);
248-
}
249-
})();
250-
</script>
251-
252264
<script>
253265
// Render helpers
254266
const byId = id => document.getElementById(id);

0 commit comments

Comments
 (0)