mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 21:33:40 +08:00
Fixed font names that are not valid CSS identifiers not working.
Prevented invalid font names. Added notification messages when something unusual happens while changing font family.
This commit is contained in:
parent
c789a6e097
commit
06255a72e5
1 changed files with 29 additions and 2 deletions
|
@ -106,6 +106,12 @@ function hideTestConfig() {
|
|||
$("#top .config").css("opacity", 0).addClass("hidden");
|
||||
}
|
||||
|
||||
function isConfigKeyValid(name) {
|
||||
if (name === null || name === undefined || name === "") return false;
|
||||
if (name.length > 30) return false;
|
||||
return /^[0-9a-zA-Z_.\-#+]+$/.test(name);
|
||||
}
|
||||
|
||||
function setPlaySoundOnError(val, nosave) {
|
||||
if (val == undefined) {
|
||||
val = false;
|
||||
|
@ -943,16 +949,37 @@ function previewFontFamily(font) {
|
|||
if (font == undefined) {
|
||||
font = "Roboto_Mono";
|
||||
}
|
||||
document.documentElement.style.setProperty("--font", font.replace(/_/g, " "));
|
||||
document.documentElement.style.setProperty(
|
||||
"--font",
|
||||
'"' + font.replace(/_/g, " ") + '"'
|
||||
);
|
||||
}
|
||||
|
||||
//font family
|
||||
function setFontFamily(font, nosave) {
|
||||
if (font == undefined || font === "") {
|
||||
font = "Roboto_Mono";
|
||||
Notifications.add(
|
||||
"Empty input received, reverted to the default font.",
|
||||
0,
|
||||
3,
|
||||
"Custom font"
|
||||
);
|
||||
}
|
||||
if (!isConfigKeyValid(font)) {
|
||||
Notifications.add(
|
||||
`Invalid font name value: "${font}".`,
|
||||
-1,
|
||||
3,
|
||||
"Custom font"
|
||||
);
|
||||
return;
|
||||
}
|
||||
ConfigSet.fontFamily(font);
|
||||
document.documentElement.style.setProperty("--font", font.replace(/_/g, " "));
|
||||
document.documentElement.style.setProperty(
|
||||
"--font",
|
||||
'"' + font.replace(/_/g, " ") + '"'
|
||||
);
|
||||
Chart.defaults.global.defaultFontFamily = font.replace(/_/g, " ");
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue