-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathpreview.html
More file actions
256 lines (218 loc) · 6.98 KB
/
preview.html
File metadata and controls
256 lines (218 loc) · 6.98 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
<html>
<head>
<meta charset="utf-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
@font-face {
font-family: xkcd-script;
src: url('xkcd-script/font/xkcd-script.woff') format('woff');
}
#font-url-row {
display: none;
}
.xkcd-script {
font-family: xkcd-script;
color: black;
line-height: 150%;
}
.container {
margins: 0px;
padding: 0px;
}
h3, .summary {
padding: 15px 0 0 15;
margin: 0;
font-size: 2em;
font-weight: bold;
}
.summary {
padding: 0 0 0 15;
font-size: 1.5em;
max-width: calc(100% - 150px);
}
.header {
width: 100%;
min-height: 10%;
background-color: #96A8C8;
display: inline-block;
padding-bottom: 1em;
overflow: hidden;
}
.font-input-container {
text-align: center;
width: 100%;
display: block;
flex-direction: column;
display: flex;
background-color: yellow;
}
.font-input-container > #font-input {
resize: none;
white-space: pre;
font-size: 1.25em;
min-height: 65vh;
padding: 15px;
width: 100%;
}
.footer {
padding-top: 1em;
}
</style>
</head>
<body>
<div id="container" class="container">
<div>
<div class="header">
<h3 class="xkcd-script">The xkcd font</h3>
<p class="summary xkcd-script">brought to you by the <a href="https://github.com/ipython/xkcd-font">ipython/xkcd-font</a> team</p>
</div>
<div class="font-input-container">
<textarea id="font-input" class="xkcd-script" oninput="UpdateQuerystringFromInput();" spellcheck="false" autofocus>
a b c d e f g h i j k l m n o p q r s t u v w x y z
unauthoritativeness leatherbark intracolic microcheilia offsider
glassweed rottolo albertite hermatorrhachis organometallic
segregationist unevangelic campstool
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z I-pronoun
UNAUTHORITATIVENESS LEATHERBARK INTRACOLIC MICROCHELIA
OFFSIDER GLASSWEED ROTTOLO ALBERTITE HERMATORRHACHIS
ORGANOMETALLIC SEGREGATIONIST UNEVANGELIC CAMPSTOOL
+ - x * ! ? # @ $ % ¦ & ^ _ — – - ( ) [ ] { } / \ < > ÷ ± √ Σ
1 2 3 4 5 6 7 8 9 0 ∫ = ≈ ≠ ~ ≤ ≥ |> <| 🎂 . , ; : “HI” ’ ‘ CAN'T ' "
É Ò Å Ü ≪ ≫ ‽ Ē Ő “ ”
This is a live preview of xkcd-script - type whatever you like!
</textarea>
</div>
<div class="footer">
<form action="javascript: null">
<div class="form-group row">
<label for="share-url-input" class="col-xs-3 col-sm-2 col-form-label" style="padding-top: 5px;"><a href="#">Share URL:</a></label>
<div class="col-xs-9 col-sm-10">
<input type="text" class="form-control" id="share-url-input" readonly>
</div>
</div>
<div class="form-group row" id="font-url-row">
<label for="font-url-input" class="col-xs-3 col-sm-2 col-form-label" style="padding-top: 5px;">Font URL:</label>
<div class="col-xs-9 col-sm-10">
<input type="text" class="form-control" id="font-url-input" placeholder="https://…/xkcd-script.woff">
</div>
</div>
</form>
</div>
</div>
</div>
<script>
var urlParams;
function fetchUrlParams() {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
};
function UpdateQueryString(key, value, url) {
if (!url) url = window.location.href;
var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
hash;
if (re.test(url)) {
if (typeof value !== 'undefined' && value !== null)
return url.replace(re, '$1' + key + "=" + value + '$2$3');
else {
hash = url.split('#');
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
}
else {
if (typeof value !== 'undefined' && value !== null) {
var separator = url.indexOf('?') !== -1 ? '&' : '?';
hash = url.split('#');
url = hash[0] + separator + key + '=' + value;
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
else
return url;
}
}
function UpdateQuerystringFromInput() {
url = UpdateQueryString("text", encodeURIComponent(document.getElementById("font-input").value));
history.pushState({}, null, url);
document.getElementById("share-url-input").value = url
}
document.getElementById("share-url-input").value = window.location.href
function renderText(content) {
if (typeof content !== "undefined" && content != "")
{
document.getElementById("font-input").value = content;
};
}
(window.onpopstate = function () {
fetchUrlParams();
renderText(urlParams["text"]);
move_ribbon();
})();
function move_ribbon () {
var ribbon = document.getElementById("forkme-ribbon");
if (!ribbon) return;
var rect = document.getElementById("container").getBoundingClientRect();
ribbon.style.left = rect.right - 149;
ribbon.style.right = null;
};
window.onresize = move_ribbon;
var loadedFontUrl = null;
function mimeForUrl(url) {
if (url.endsWith('.woff2')) return 'font/woff2';
if (url.endsWith('.ttf')) return 'font/ttf';
if (url.endsWith('.otf')) return 'font/otf';
return 'font/woff';
}
function normalizeGithubUrl(url) {
// github.com/.../raw/... redirects via a broken CORS header; go direct
var m = url.match(/^https?:\/\/github\.com\/([^/]+\/[^/]+)\/raw\/(.+)$/);
if (m) return 'https://raw.githubusercontent.com/' + m[1] + '/' + m[2];
return url;
}
async function loadFontFromUrl(url) {
if (!url || url === loadedFontUrl) return;
try {
var resp = await fetch(normalizeGithubUrl(url));
if (!resp.ok) throw new Error('HTTP ' + resp.status);
var buf = await resp.arrayBuffer();
var blobUrl = URL.createObjectURL(new Blob([buf], {type: mimeForUrl(url)}));
var face = new FontFace('xkcd-script', 'url(' + blobUrl + ')');
await face.load();
document.fonts.add(face);
loadedFontUrl = url;
} catch (e) {
console.error('Failed to load font from URL:', url, e);
}
}
function updateFontUrlQuerystring(url) {
var newHref = UpdateQueryString('font', encodeURIComponent(url), window.location.href);
history.replaceState({}, null, newHref);
document.getElementById('share-url-input').value = newHref;
}
document.getElementById('font-url-input').addEventListener('change', function () {
var url = this.value.trim();
loadFontFromUrl(url);
updateFontUrlQuerystring(url);
});
// Show font URL row and load font if ?font= param is present
(function initFontUrl() {
fetchUrlParams();
var fontUrl = urlParams['font'];
if (fontUrl) {
document.getElementById('font-url-row').style.display = '';
document.getElementById('font-url-input').value = fontUrl;
loadFontFromUrl(fontUrl);
}
})();
</script>
</body>
</html>