-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (38 loc) · 1.41 KB
/
Copy pathscript.js
File metadata and controls
42 lines (38 loc) · 1.41 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
function applyFont() {
const url = convertGitHubBlobToRaw(document.getElementById('fontUrl').value.trim());
const styleTag = document.getElementById('dynamic-font-style');
const status = document.getElementById('status');
const footerStatus = document.getElementById('footer-status');
if (!url) return;
styleTag.innerHTML = `
@font-face {
font-family: 'TestFont';
src: url('${url}');
font-display: block;
}
`;
status.innerHTML = "⌛ Loading...";
// Use the FontFaceSet API to detect when it's actually ready
document.fonts.ready.then(() => {
// Check if our specific 'TestFont' is loaded
if (document.fonts.check("1em TestFont")) {
status.innerHTML = "✅ Font loaded: <strong>" + url.split('/').pop() + "</strong>";
status.classList.remove('text-danger');
status.classList.add('text-success');
} else {
status.innerHTML = "❌ Font could not be matched. Check URL/CORS.";
status.classList.remove('text-success');
status.classList.add('text-danger');
}
}).catch(err => {
status.innerHTML = "❌ Error: " + err.message;
status.classList.remove('text-success');
status.classList.add('text-danger');
});
}
function convertGitHubBlobToRaw(blobUrl) {
return blobUrl.replace(
/https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\//,
'https://raw.githubusercontent.com/$1/$2/$3/'
);
}