From d8b7ac2b769bec57dfc9b7d36fcb0bcfb4232f53 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 12 Mar 2021 17:41:46 +0000 Subject: [PATCH] more refactoring --- src/js/account.js | 12 ++++ src/js/commandline.js | 164 +++++++++++++++++++++--------------------- src/js/script.js | 12 ---- 3 files changed, 94 insertions(+), 94 deletions(-) diff --git a/src/js/account.js b/src/js/account.js index d9fb08d23..25d4aca30 100644 --- a/src/js/account.js +++ b/src/js/account.js @@ -244,6 +244,18 @@ function signOut() { }); } +function accountIconLoading(truefalse) { + if (truefalse) { + $("#top #menu .account .icon").html( + '' + ); + $("#top #menu .account").css("opacity", 1).css("pointer-events", "none"); + } else { + $("#top #menu .account .icon").html(''); + $("#top #menu .account").css("opacity", 1).css("pointer-events", "auto"); + } +} + firebase.auth().onAuthStateChanged(function (user) { if (user) { // User is signed in. diff --git a/src/js/commandline.js b/src/js/commandline.js index 14d2ed8e2..6a1ba68be 100644 --- a/src/js/commandline.js +++ b/src/js/commandline.js @@ -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; diff --git a/src/js/script.js b/src/js/script.js index f88568c4e..2e77a8b33 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -3349,18 +3349,6 @@ function hideLiveAcc() { ); } -function accountIconLoading(truefalse) { - if (truefalse) { - $("#top #menu .account .icon").html( - '' - ); - $("#top #menu .account").css("opacity", 1).css("pointer-events", "none"); - } else { - $("#top #menu .account .icon").html(''); - $("#top #menu .account").css("opacity", 1).css("pointer-events", "auto"); - } -} - function toggleResultWordsDisplay() { if (resultVisible) { if ($("#resultWordsHistory").stop(true, true).hasClass("hidden")) {