reuse variable names instead of the names I had guessed

This commit is contained in:
m5r 2023-02-15 19:40:00 +01:00
parent 36fb23677a
commit 75c5fc0841
No known key found for this signature in database
GPG Key ID: 5BC847276DD5DDEA

View File

@ -29,24 +29,28 @@ const languageFontMap = {
math: "Noto+Sans+Math", math: "Noto+Sans+Math",
unknown: "Noto+Sans", unknown: "Noto+Sans",
}; };
async function loadGoogleFont(fontFamily: string | string[], segment: string) { async function loadGoogleFont(fontFamily: string | string[], text: string) {
if (!fontFamily || !segment) { if (!fontFamily || !text) {
return; return;
} }
let o = `https://fonts.googleapis.com/css2?family=${fontFamily}&text=${encodeURIComponent(segment)}`, const API = `https://fonts.googleapis.com/css2?family=${fontFamily}&text=${encodeURIComponent(text)}`;
s = ( const css = (
await ( await (
await fetch(o, { await fetch(API, {
headers: { headers: {
"User-Agent": "User-Agent":
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1",
}, },
}) })
).text() ).text()
).match(/src: url\((.+)\) format\('(opentype|truetype)'\)/); );
if (!s) throw new Error("Failed to load font"); const resource = css.match(/src: url\((.+)\) format\('(opentype|truetype)'\)/);
return fetch(s[1]).then((a) => a.arrayBuffer()); if (!resource) {
throw new Error("Failed to load font");
}
return fetch(resource[1]).then((res) => res.arrayBuffer());
} }
const assetCache = new Map(); const assetCache = new Map();
const loadDynamicAsset = (emojiType?: EmojiType) => { const loadDynamicAsset = (emojiType?: EmojiType) => {