mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 23:36:37 +08:00
more refactoring
This commit is contained in:
parent
36d6398316
commit
d8b7ac2b76
|
@ -244,6 +244,18 @@ function signOut() {
|
|||
});
|
||||
}
|
||||
|
||||
function accountIconLoading(truefalse) {
|
||||
if (truefalse) {
|
||||
$("#top #menu .account .icon").html(
|
||||
'<i class="fas fa-fw fa-spin fa-circle-notch"></i>'
|
||||
);
|
||||
$("#top #menu .account").css("opacity", 1).css("pointer-events", "none");
|
||||
} else {
|
||||
$("#top #menu .account .icon").html('<i class="fas fa-fw fa-user"></i>');
|
||||
$("#top #menu .account").css("opacity", 1).css("pointer-events", "auto");
|
||||
}
|
||||
}
|
||||
|
||||
firebase.auth().onAuthStateChanged(function (user) {
|
||||
if (user) {
|
||||
// User is signed in.
|
||||
|
|
|
@ -1,83 +1,4 @@
|
|||
function canBailOut() {
|
||||
return (
|
||||
(config.mode === "custom" &&
|
||||
CustomText.isWordRandom &&
|
||||
CustomText.word >= 5000) ||
|
||||
(config.mode === "custom" &&
|
||||
!CustomText.isWordRandom &&
|
||||
!CustomText.isTimeRandom &&
|
||||
CustomText.text.length >= 5000) ||
|
||||
(config.mode === "custom" &&
|
||||
CustomText.isTimeRandom &&
|
||||
CustomText.time >= 3600) ||
|
||||
(config.mode === "words" && config.words >= 5000) ||
|
||||
config.words === 0 ||
|
||||
(config.mode === "time" && (config.time >= 3600 || config.time === 0)) ||
|
||||
config.mode == "zen"
|
||||
);
|
||||
}
|
||||
|
||||
function addChildCommands(
|
||||
unifiedCommands,
|
||||
commandItem,
|
||||
parentCommandDisplay = ""
|
||||
) {
|
||||
let commandItemDisplay = commandItem.display.replace(/\s?\.\.\.$/g, "");
|
||||
if (parentCommandDisplay)
|
||||
commandItemDisplay = parentCommandDisplay + " > " + commandItemDisplay;
|
||||
if (commandItem.subgroup) {
|
||||
try {
|
||||
commandItem.exec();
|
||||
const currentCommandsIndex = currentCommands.length - 1;
|
||||
currentCommands[currentCommandsIndex].list.forEach((cmd) => {
|
||||
if (cmd.alias === undefined) cmd.alias = commandItem.alias;
|
||||
addChildCommands(unifiedCommands, cmd, commandItemDisplay);
|
||||
});
|
||||
currentCommands.pop();
|
||||
} catch (e) {}
|
||||
} else {
|
||||
let tempCommandItem = { ...commandItem };
|
||||
if (parentCommandDisplay) tempCommandItem.display = commandItemDisplay;
|
||||
unifiedCommands.push(tempCommandItem);
|
||||
}
|
||||
}
|
||||
|
||||
function generateSingleListOfCommands() {
|
||||
const allCommands = [];
|
||||
const oldShowCommandLine = showCommandLine;
|
||||
showCommandLine = () => {};
|
||||
commands.list.forEach((c) => addChildCommands(allCommands, c));
|
||||
showCommandLine = oldShowCommandLine;
|
||||
return {
|
||||
title: "All Commands",
|
||||
list: allCommands,
|
||||
};
|
||||
}
|
||||
|
||||
function isSingleListCommandLineActive() {
|
||||
return $("#commandLine").hasClass("allCommands");
|
||||
}
|
||||
|
||||
function useSingleListCommandLine(show = true) {
|
||||
let allCommands = generateSingleListOfCommands();
|
||||
if (config.singleListCommandLine == "manual")
|
||||
currentCommands.push(allCommands);
|
||||
else if (config.singleListCommandLine == "on")
|
||||
currentCommands = [allCommands];
|
||||
|
||||
if (config.singleListCommandLine != "off")
|
||||
$("#commandLine").addClass("allCommands");
|
||||
if (show) showCommandLine();
|
||||
}
|
||||
|
||||
function restoreOldCommandLine(show = true) {
|
||||
if (isSingleListCommandLineActive()) {
|
||||
$("#commandLine").removeClass("allCommands");
|
||||
currentCommands = currentCommands.filter((l) => l.title != "All Commands");
|
||||
if (currentCommands.length < 1) currentCommands = [commands];
|
||||
}
|
||||
if (show) showCommandLine();
|
||||
}
|
||||
let currentCommands = [commands];
|
||||
|
||||
let commands = {
|
||||
title: "",
|
||||
|
@ -1717,6 +1638,87 @@ let commandsFonts = {
|
|||
list: [],
|
||||
};
|
||||
|
||||
function canBailOut() {
|
||||
return (
|
||||
(config.mode === "custom" &&
|
||||
CustomText.isWordRandom &&
|
||||
CustomText.word >= 5000) ||
|
||||
(config.mode === "custom" &&
|
||||
!CustomText.isWordRandom &&
|
||||
!CustomText.isTimeRandom &&
|
||||
CustomText.text.length >= 5000) ||
|
||||
(config.mode === "custom" &&
|
||||
CustomText.isTimeRandom &&
|
||||
CustomText.time >= 3600) ||
|
||||
(config.mode === "words" && config.words >= 5000) ||
|
||||
config.words === 0 ||
|
||||
(config.mode === "time" && (config.time >= 3600 || config.time === 0)) ||
|
||||
config.mode == "zen"
|
||||
);
|
||||
}
|
||||
|
||||
function addChildCommands(
|
||||
unifiedCommands,
|
||||
commandItem,
|
||||
parentCommandDisplay = ""
|
||||
) {
|
||||
let commandItemDisplay = commandItem.display.replace(/\s?\.\.\.$/g, "");
|
||||
if (parentCommandDisplay)
|
||||
commandItemDisplay = parentCommandDisplay + " > " + commandItemDisplay;
|
||||
if (commandItem.subgroup) {
|
||||
try {
|
||||
commandItem.exec();
|
||||
const currentCommandsIndex = currentCommands.length - 1;
|
||||
currentCommands[currentCommandsIndex].list.forEach((cmd) => {
|
||||
if (cmd.alias === undefined) cmd.alias = commandItem.alias;
|
||||
addChildCommands(unifiedCommands, cmd, commandItemDisplay);
|
||||
});
|
||||
currentCommands.pop();
|
||||
} catch (e) {}
|
||||
} else {
|
||||
let tempCommandItem = { ...commandItem };
|
||||
if (parentCommandDisplay) tempCommandItem.display = commandItemDisplay;
|
||||
unifiedCommands.push(tempCommandItem);
|
||||
}
|
||||
}
|
||||
|
||||
function generateSingleListOfCommands() {
|
||||
const allCommands = [];
|
||||
const oldShowCommandLine = showCommandLine;
|
||||
showCommandLine = () => {};
|
||||
commands.list.forEach((c) => addChildCommands(allCommands, c));
|
||||
showCommandLine = oldShowCommandLine;
|
||||
return {
|
||||
title: "All Commands",
|
||||
list: allCommands,
|
||||
};
|
||||
}
|
||||
|
||||
function isSingleListCommandLineActive() {
|
||||
return $("#commandLine").hasClass("allCommands");
|
||||
}
|
||||
|
||||
function useSingleListCommandLine(show = true) {
|
||||
let allCommands = generateSingleListOfCommands();
|
||||
if (config.singleListCommandLine == "manual")
|
||||
currentCommands.push(allCommands);
|
||||
else if (config.singleListCommandLine == "on")
|
||||
currentCommands = [allCommands];
|
||||
|
||||
if (config.singleListCommandLine != "off")
|
||||
$("#commandLine").addClass("allCommands");
|
||||
if (show) showCommandLine();
|
||||
}
|
||||
|
||||
function restoreOldCommandLine(show = true) {
|
||||
if (isSingleListCommandLineActive()) {
|
||||
$("#commandLine").removeClass("allCommands");
|
||||
currentCommands = currentCommands.filter((l) => l.title != "All Commands");
|
||||
if (currentCommands.length < 1) currentCommands = [commands];
|
||||
}
|
||||
if (show) showCommandLine();
|
||||
}
|
||||
|
||||
Misc.getFontsList().then((fonts) => {
|
||||
fonts.forEach((font) => {
|
||||
commandsFonts.list.push({
|
||||
|
@ -2106,8 +2108,6 @@ $(document).keydown((e) => {
|
|||
}
|
||||
});
|
||||
|
||||
let currentCommands = [commands];
|
||||
|
||||
function triggerCommand(command) {
|
||||
let subgroup = false;
|
||||
let input = false;
|
||||
|
|
|
@ -3349,18 +3349,6 @@ function hideLiveAcc() {
|
|||
);
|
||||
}
|
||||
|
||||
function accountIconLoading(truefalse) {
|
||||
if (truefalse) {
|
||||
$("#top #menu .account .icon").html(
|
||||
'<i class="fas fa-fw fa-spin fa-circle-notch"></i>'
|
||||
);
|
||||
$("#top #menu .account").css("opacity", 1).css("pointer-events", "none");
|
||||
} else {
|
||||
$("#top #menu .account .icon").html('<i class="fas fa-fw fa-user"></i>');
|
||||
$("#top #menu .account").css("opacity", 1).css("pointer-events", "auto");
|
||||
}
|
||||
}
|
||||
|
||||
function toggleResultWordsDisplay() {
|
||||
if (resultVisible) {
|
||||
if ($("#resultWordsHistory").stop(true, true).hasClass("hidden")) {
|
||||
|
|
Loading…
Reference in a new issue