mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-04 20:47:54 +08:00
more code refactoring
This commit is contained in:
parent
250ae8c2bc
commit
14fd07c5b9
6 changed files with 103 additions and 70 deletions
|
@ -1654,6 +1654,7 @@
|
|||
<script src="js/chartjs-plugin-trendline.js?v=46"></script>
|
||||
<script src="js/chartjs-plugin-annotation.js"></script>
|
||||
<script src="js/html2canvas.min.js"></script>
|
||||
<script src="js/misc.js?v=46"></script>
|
||||
<script src="js/words.js?v=46"></script>
|
||||
<script src="js/layouts.js?v=46"></script>
|
||||
<script src="js/db.js?v=46"></script>
|
||||
|
|
|
@ -687,17 +687,8 @@ function updateCommandsTagsList() {
|
|||
}
|
||||
}
|
||||
|
||||
let themesList;
|
||||
|
||||
$.getJSON("themes/list.json", function (data) {
|
||||
commandsThemes.list = [];
|
||||
themesList = data.sort(function (a, b) {
|
||||
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
|
||||
if (nameA < nameB) return -1;
|
||||
if (nameA > nameB) return 1;
|
||||
return 0;
|
||||
});
|
||||
data.forEach((theme) => {
|
||||
getThemesList().then((themes) => {
|
||||
themes.forEach((theme) => {
|
||||
commandsThemes.list.push({
|
||||
id: "changeTheme" + capitalizeFirstLetter(theme.name),
|
||||
display: theme.name.replace(/_/g, " "),
|
||||
|
@ -711,32 +702,13 @@ $.getJSON("themes/list.json", function (data) {
|
|||
});
|
||||
});
|
||||
|
||||
let funboxList;
|
||||
|
||||
$.getJSON("funbox/list.json", function (data) {
|
||||
funboxList = data.sort(function (a, b) {
|
||||
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
|
||||
if (nameA < nameB) return -1;
|
||||
if (nameA > nameB) return 1;
|
||||
return 0;
|
||||
});
|
||||
});
|
||||
|
||||
let commandsFonts = {
|
||||
title: "Change font...",
|
||||
list: [],
|
||||
};
|
||||
|
||||
let fontsList;
|
||||
|
||||
$.getJSON("js/fonts.json", function (data) {
|
||||
fontsList = data.sort(function (a, b) {
|
||||
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
|
||||
if (nameA < nameB) return -1;
|
||||
if (nameA > nameB) return 1;
|
||||
return 0;
|
||||
});
|
||||
data.forEach((font) => {
|
||||
getFontsList().then((fonts) => {
|
||||
fonts.forEach((font) => {
|
||||
commandsFonts.list.push({
|
||||
id: "changeFont" + font.name.replace(/ /g, "_"),
|
||||
display: font.display !== undefined ? font.display : font.name,
|
||||
|
|
50
public/js/misc.js
Normal file
50
public/js/misc.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
let themesList = null;
|
||||
async function getThemesList() {
|
||||
if (themesList == null) {
|
||||
return $.getJSON("themes/list.json", function (data) {
|
||||
themesList = data.sort(function (a, b) {
|
||||
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
|
||||
if (nameA < nameB) return -1;
|
||||
if (nameA > nameB) return 1;
|
||||
return 0;
|
||||
});
|
||||
return themesList;
|
||||
});
|
||||
} else {
|
||||
return themesList;
|
||||
}
|
||||
}
|
||||
|
||||
let funboxList = null;
|
||||
async function getFunboxList() {
|
||||
if (funboxList == null) {
|
||||
return $.getJSON("funbox/list.json", function (data) {
|
||||
funboxList = data.sort(function (a, b) {
|
||||
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
|
||||
if (nameA < nameB) return -1;
|
||||
if (nameA > nameB) return 1;
|
||||
return 0;
|
||||
});
|
||||
return funboxList;
|
||||
});
|
||||
} else {
|
||||
return funboxList;
|
||||
}
|
||||
}
|
||||
|
||||
let fontsList = null;
|
||||
async function getFontsList() {
|
||||
if (fontsList == null) {
|
||||
return $.getJSON("js/fonts.json", function (data) {
|
||||
fontsList = data.sort(function (a, b) {
|
||||
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
|
||||
if (nameA < nameB) return -1;
|
||||
if (nameA > nameB) return 1;
|
||||
return 0;
|
||||
});
|
||||
return fontsList;
|
||||
});
|
||||
} else {
|
||||
return fontsList;
|
||||
}
|
||||
}
|
|
@ -230,19 +230,19 @@ function activateFunbox(funbox, mode) {
|
|||
}
|
||||
|
||||
if (funbox === "simon_says") {
|
||||
setActiveKeymapModeButton();
|
||||
settingsGroups.keymapMode.updateButton();
|
||||
restartTest();
|
||||
}
|
||||
} else if (mode === "script") {
|
||||
if (funbox === "tts") {
|
||||
$("#funBoxTheme").attr("href", `funbox/simon_says.css`);
|
||||
config.keymapMode = "off";
|
||||
setActiveKeymapModeButton();
|
||||
settingsGroups.keymapMode.updateButton();
|
||||
restartTest();
|
||||
} else if (funbox === "layoutfluid") {
|
||||
config.keymapMode = "on";
|
||||
changeKeymapMode("next");
|
||||
setActiveKeymapModeButton();
|
||||
settingsGroups.keymapMode.updateButton();
|
||||
changeLayout("qwerty");
|
||||
setActiveLayoutButton();
|
||||
changeKeymapLayout("qwerty");
|
||||
|
|
|
@ -161,14 +161,18 @@ settingsGroups.timerOpacity = new SettingsGroup(
|
|||
settingsGroups.timerColor = new SettingsGroup("timerColor", setTimerColor);
|
||||
settingsGroups.fontFamily = new SettingsGroup("fontFamily", setFontFamily);
|
||||
|
||||
function updateSettingsPage() {
|
||||
fillSettingsPage();
|
||||
|
||||
async function fillSettingsPage() {
|
||||
let themesEl = $(".pageSettings .section.themes .buttons").empty();
|
||||
themesList.forEach((theme) => {
|
||||
themesEl.append(
|
||||
`<div class="theme button" theme='${theme.name}' style="color:${
|
||||
theme.textColor
|
||||
};background:${theme.bgColor}">${theme.name.replace(/_/g, " ")}</div>`
|
||||
);
|
||||
getThemesList().then((themes) => {
|
||||
themes.forEach((theme) => {
|
||||
themesEl.append(
|
||||
`<div class="theme button" theme='${theme.name}' style="color:${
|
||||
theme.textColor
|
||||
};background:${theme.bgColor}">${theme.name.replace(/_/g, " ")}</div>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
let langEl = $(".pageSettings .section.language .buttons").empty();
|
||||
|
@ -211,37 +215,43 @@ function updateSettingsPage() {
|
|||
|
||||
let funboxEl = $(".pageSettings .section.funbox .buttons").empty();
|
||||
funboxEl.append(`<div class="funbox button" funbox='none'>none</div>`);
|
||||
funboxList.forEach((funbox) => {
|
||||
if (funbox.name === "mirror") {
|
||||
funboxEl.append(
|
||||
`<div class="funbox button" funbox='${funbox.name}' type="${
|
||||
funbox.type
|
||||
}" style="transform:scaleX(-1);">${funbox.name.replace(
|
||||
/_/g,
|
||||
" "
|
||||
)}</div>`
|
||||
);
|
||||
} else {
|
||||
funboxEl.append(
|
||||
`<div class="funbox button" funbox='${funbox.name}' type="${
|
||||
funbox.type
|
||||
}">${funbox.name.replace(/_/g, " ")}</div>`
|
||||
);
|
||||
}
|
||||
getFunboxList().then((funboxModes) => {
|
||||
funboxModes.forEach((funbox) => {
|
||||
if (funbox.name === "mirror") {
|
||||
funboxEl.append(
|
||||
`<div class="funbox button" funbox='${funbox.name}' type="${
|
||||
funbox.type
|
||||
}" style="transform:scaleX(-1);">${funbox.name.replace(
|
||||
/_/g,
|
||||
" "
|
||||
)}</div>`
|
||||
);
|
||||
} else {
|
||||
funboxEl.append(
|
||||
`<div class="funbox button" funbox='${funbox.name}' type="${
|
||||
funbox.type
|
||||
}">${funbox.name.replace(/_/g, " ")}</div>`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let fontsEl = $(".pageSettings .section.fontFamily .buttons").empty();
|
||||
fontsList.forEach((font) => {
|
||||
fontsEl.append(
|
||||
`<div class="button" style="font-family:${
|
||||
font.display !== undefined ? font.display : font.name
|
||||
}" fontFamily="${font.name.replace(/ /g, "_")}" tabindex="0"
|
||||
onclick="this.blur();">${
|
||||
font.display !== undefined ? font.display : font.name
|
||||
}</div>`
|
||||
);
|
||||
getFontsList().then((fonts) => {
|
||||
fonts.forEach((font) => {
|
||||
fontsEl.append(
|
||||
`<div class="button" style="font-family:${
|
||||
font.display !== undefined ? font.display : font.name
|
||||
}" fontFamily="${font.name.replace(/ /g, "_")}" tabindex="0"
|
||||
onclick="this.blur();">${
|
||||
font.display !== undefined ? font.display : font.name
|
||||
}</div>`
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function updateSettingsPage() {
|
||||
Object.keys(settingsGroups).forEach((group) => {
|
||||
settingsGroups[group].updateButton();
|
||||
});
|
||||
|
|
|
@ -52,7 +52,7 @@ let config = {
|
|||
};
|
||||
|
||||
//cookies
|
||||
function saveConfigToCookie() {
|
||||
async function saveConfigToCookie() {
|
||||
// showNotification('saving to cookie',1000);
|
||||
if (config.freedomMode === null) config.freedomMode = false;
|
||||
let d = new Date();
|
||||
|
@ -66,7 +66,7 @@ function saveConfigToCookie() {
|
|||
saveConfigToDB();
|
||||
}
|
||||
|
||||
function saveConfigToDB() {
|
||||
async function saveConfigToDB() {
|
||||
if (firebase.auth().currentUser !== null) {
|
||||
// showNotification('saving to db',1000);
|
||||
accountIconLoading(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue