diff --git a/src/js/account/result-filters.js b/src/js/account/result-filters.js index 485ea2789..9c9f45907 100644 --- a/src/js/account/result-filters.js +++ b/src/js/account/result-filters.js @@ -398,10 +398,10 @@ $(".pageAccount .topFilters .button.currentConfigFilter").click((e) => { filters["language"][Config.language] = true; } - if (Funbox.active === "none") { + if (Config.funbox === "none") { filters.funbox.none = true; } else { - filters.funbox[Funbox.active] = true; + filters.funbox[Config.funbox] = true; } filters["tags"]["none"] = true; diff --git a/src/js/commandline-lists.js b/src/js/commandline-lists.js index a82a4ded3..5cfe23bff 100644 --- a/src/js/commandline-lists.js +++ b/src/js/commandline-lists.js @@ -627,7 +627,6 @@ let commandsPaceCaret = { ], }; - let commandsMinWpm = { title: "Change min wpm mode...", list: [ @@ -1816,7 +1815,7 @@ export let defaultCommands = { input: true, exec: (input) => { UpdateConfig.setCustomLayoutfluid(input); - if (Funbox.active === "layoutfluid") TestLogic.restart(); + if (Config.funbox === "layoutfluid") TestLogic.restart(); // UpdateConfig.setLayout( // Config.customLayoutfluid // ? Config.customLayoutfluid.split("_")[0] @@ -2019,7 +2018,7 @@ export let defaultCommands = { UpdateConfig.apply(JSON.parse(input)); UpdateConfig.saveToLocalStorage(); Settings.update(); - Notifications.add("Done",1); + Notifications.add("Done", 1); } catch (e) { Notifications.add( "An error occured while importing settings: " + e, @@ -2032,9 +2031,8 @@ export let defaultCommands = { id: "exportSettingsJSON", display: "Export settings JSON", input: true, - defaultValue:"", - exec: (input) => { - }, + defaultValue: "", + exec: (input) => {}, }, ], }; diff --git a/src/js/config.js b/src/js/config.js index 0fc1284f2..22deb0c72 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -74,6 +74,7 @@ let defaultConfig = { flipTestColors: false, capsLockBackspace: false, layout: "default", + funbox: "none", confidenceMode: "off", indicateTypos: false, timerStyle: "mini", @@ -209,7 +210,7 @@ export function togglePunctuation() { export function setMode(mode, nosave) { if (TestUI.testRestarting) return; - if (mode !== "words" && Funbox.active === "memory") { + if (mode !== "words" && config.funbox === "memory") { Notifications.add("Memory funbox can only be used with words mode.", 0); return; } @@ -237,11 +238,11 @@ export function setMode(mode, nosave) { $("#top .config .quoteLength").addClass("hidden"); } else if (config.mode == "custom") { if ( - Funbox.active === "58008" || - Funbox.active === "gibberish" || - Funbox.active === "ascii" + config.funbox === "58008" || + config.funbox === "gibberish" || + config.funbox === "ascii" ) { - Funbox.setAcitve("none"); + Funbox.setActive("none"); TestUI.updateModesNotice(); } $("#top .config .wordCount").addClass("hidden"); @@ -327,6 +328,13 @@ export function setFavThemes(themes, nosave) { } } +export function setFunbox(funbox, nosave) { + config.funbox = funbox ? funbox : "none"; + if (!nosave) { + saveToLocalStorage(); + } +} + //blind mode export function toggleBlindMode() { let blind = !config.blindMode; @@ -845,10 +853,10 @@ export function toggleLiveAcc() { export function setHighlightMode(mode, nosave) { if ( mode === "word" && - (Funbox.active === "nospace" || - Funbox.active === "read_ahead" || - Funbox.active === "read_ahead_easy" || - Funbox.active === "read_ahead_hard") + (config.funbox === "nospace" || + config.funbox === "read_ahead" || + config.funbox === "read_ahead_easy" || + config.funbox === "read_ahead_hard") ) { Notifications.add("Can't use word highlight with this funbox", 0); return; @@ -858,9 +866,9 @@ export function setHighlightMode(mode, nosave) { } config.highlightMode = mode; // if(TestLogic.active){ - try{ - if (!nosave) TestUI.updateWordElement(config.blindMode); - }catch{} + try { + if (!nosave) TestUI.updateWordElement(config.blindMode); + } catch {} // } if (!nosave) saveToLocalStorage(); } @@ -1533,6 +1541,7 @@ export function apply(configObj) { setPlaySoundOnClick(configObj.playSoundOnClick, true); setStopOnError(configObj.stopOnError, true); setFavThemes(configObj.favThemes, true); + setFunbox(configObj.funbox, true); setRandomTheme(configObj.randomTheme, true); setShowAllLines(configObj.showAllLines, true); setSwapEscAndTab(configObj.swapEscAndTab, true); diff --git a/src/js/input-controller.js b/src/js/input-controller.js index 1ce801213..e66cbd0dc 100644 --- a/src/js/input-controller.js +++ b/src/js/input-controller.js @@ -121,7 +121,7 @@ function handleBackspace(event) { } else { TestLogic.input.setCurrent(TestLogic.input.popHistory()); TestLogic.corrected.setCurrent(TestLogic.corrected.popHistory()); - if (Funbox.active === "nospace") { + if (Config.funbox === "nospace") { TestLogic.input.setCurrent( TestLogic.input.current.substring( 0, @@ -194,7 +194,7 @@ function handleSpace(event, isEnter) { if (!TestLogic.active) return; if (TestLogic.input.current === "") return; // let nextWord = wordsList[TestLogic.words.currentIndex + 1]; - // if ((isEnter && nextWord !== "\n") && (isEnter && Funbox.active !== "58008")) return; + // if ((isEnter && nextWord !== "\n") && (isEnter && Config.funbox !== "58008")) return; // if (!isEnter && nextWord === "\n") return; event.preventDefault(); @@ -204,7 +204,7 @@ function handleSpace(event, isEnter) { } let currentWord = TestLogic.words.getCurrent(); - if (Funbox.active === "layoutfluid" && Config.mode !== "time") { + if (Config.funbox === "layoutfluid" && Config.mode !== "time") { // here I need to check if Config.customLayoutFluid exists because of my scuffed solution of returning whenever value is undefined in the setCustomLayoutfluid function const layouts = Config.customLayoutfluid ? Config.customLayoutfluid.split("#") @@ -246,14 +246,14 @@ function handleSpace(event, isEnter) { TestStats.pushKeypressWord(TestLogic.words.currentIndex); // currentKeypress.count++; // currentKeypress.words.push(TestLogic.words.currentIndex); - if (Funbox.active !== "nospace") { + if (Config.funbox !== "nospace") { Sound.playClick(Config.playSoundOnClick); } Replay.addReplayEvent("submitCorrectWord"); } else { //incorrect word PaceCaret.handleSpace(false, currentWord); - if (Funbox.active !== "nospace") { + if (Config.funbox !== "nospace") { if (!Config.playSoundOnError || Config.blindMode) { Sound.playClick(Config.playSoundOnClick); } else { @@ -697,7 +697,7 @@ function handleAlpha(event) { //simulate space press in nospace funbox if ( - (Funbox.active === "nospace" && + (Config.funbox === "nospace" && TestLogic.input.current.length === TestLogic.words.getCurrent().length) || (event.key === "\n" && thisCharCorrect) ) { @@ -814,7 +814,7 @@ $(document).keydown(function (event) { handleBackspace(event); } - if (event.key === "Enter" && Funbox.active === "58008" && wordsFocused) { + if (event.key === "Enter" && Config.funbox === "58008" && wordsFocused) { event.key = " "; } diff --git a/src/js/route-controller.js b/src/js/route-controller.js index 49beeb03d..d30f4fb40 100644 --- a/src/js/route-controller.js +++ b/src/js/route-controller.js @@ -1,5 +1,6 @@ import * as Funbox from "./funbox"; import * as UI from "./ui"; +import Config from "./config"; let mappedRoutes = { "/": "pageTest", @@ -19,7 +20,7 @@ export function handleInitialPageClasses(pathname) { (function (history) { var pushState = history.pushState; history.pushState = function (state) { - if (Funbox.active === "memory" && state !== "/") { + if (Config.funbox === "memory" && state !== "/") { Funbox.resetMemoryTimer(); } return pushState.apply(history, arguments); diff --git a/src/js/settings.js b/src/js/settings.js index a3c03a8a2..b3c696319 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -448,7 +448,7 @@ export function updateDiscordSection() { function setActiveFunboxButton() { $(`.pageSettings .section.funbox .button`).removeClass("active"); $( - `.pageSettings .section.funbox .button[funbox='${Funbox.funboxSaved}']` + `.pageSettings .section.funbox .button[funbox='${Config.funbox}']` ).addClass("active"); } diff --git a/src/js/test/funbox.js b/src/js/test/funbox.js index c6350b7ed..60addd553 100644 --- a/src/js/test/funbox.js +++ b/src/js/test/funbox.js @@ -6,9 +6,7 @@ import * as ManualRestart from "./manual-restart-tracker"; import Config, * as UpdateConfig from "./config"; import * as Settings from "./settings"; -export let active = "none"; -export let funboxSaved = "none"; -export let modeSaved = null; +let modeSaved = null; let memoryTimer = null; let memoryInterval = null; @@ -76,13 +74,13 @@ export function startMemoryTimer() { } export function reset() { - active = "none"; resetMemoryTimer(); } export function toggleScript(...params) { - if (active === "tts") { + if (Config.funbox === "tts") { var msg = new SpeechSynthesisUtterance(); + console.log("Speaking"); msg.text = params[0]; msg.lang = "en-US"; window.speechSynthesis.cancel(); @@ -90,9 +88,11 @@ export function toggleScript(...params) { } } -export async function activate(funbox, mode) { +export async function activate(funbox) { + let mode = modeSaved; + if (funbox === undefined || funbox === null) { - funbox = funboxSaved; + funbox = Config.funbox; } if (Misc.getCurrentLanguage().ligatures) { if (funbox == "choo_choo" || funbox == "earthquake") { @@ -124,10 +124,8 @@ export async function activate(funbox, mode) { ManualRestart.set(); if (mode === "style") { - if (funbox != undefined) { + if (funbox != undefined) $("#funBoxTheme").attr("href", `funbox/${funbox}.css`); - active = funbox; - } if (funbox === "simon_says") { rememberSetting( @@ -220,7 +218,6 @@ export async function activate(funbox, mode) { UpdateConfig.setHighlightMode("letter", true); TestLogic.restart(false, true); } - active = funbox; } // if (funbox !== "layoutfluid" || mode !== "script") { @@ -233,16 +230,8 @@ export async function activate(funbox, mode) { return true; } export function setFunbox(funbox, mode) { - if (TestLogic.active) { - Notifications.add( - "You can only change the funbox before starting a test.", - 0 - ); - return false; - } if (funbox === "none") loadMemory(); - funboxSaved = funbox; modeSaved = mode; - active = funbox; + UpdateConfig.setFunbox(funbox); return true; } diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index 2afc94886..01dc0b5dd 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -197,7 +197,7 @@ export function setRandomQuote(rq) { export function punctuateWord(previousWord, currentWord, index, maxindex) { let word = currentWord; - if (Funbox.funboxSaved === "58008") { + if (Config.funbox === "58008") { if (currentWord.length > 3) { if (Math.random() < 0.75) { let special = ["/", "*", "-", "+"][Math.floor(Math.random() * 4)]; @@ -336,7 +336,7 @@ export function startTest() { TimerProgress.update(TestTimer.time); TestTimer.clear(); - if (Funbox.active === "memory") { + if (Config.funbox === "memory") { Funbox.resetMemoryTimer(); $("#wordsWrapper").addClass("hidden"); } @@ -433,7 +433,7 @@ export async function init() { if (Config.mode === "words" && Config.words === 0) { wordsBound = 100; } - if (Funbox.funboxSaved === "plus_one") { + if (Config.funbox === "plus_one") { wordsBound = 2; } let wordset = language.words; @@ -462,7 +462,7 @@ export async function init() { } } - if (Funbox.funboxSaved === "rAnDoMcAsE") { + if (Config.funbox === "rAnDoMcAsE") { let randomcaseword = ""; for (let i = 0; i < randomWord.length; i++) { if (i % 2 != 0) { @@ -472,17 +472,17 @@ export async function init() { } } randomWord = randomcaseword; - } else if (Funbox.funboxSaved === "gibberish") { + } else if (Config.funbox === "gibberish") { randomWord = Misc.getGibberish(); - } else if (Funbox.funboxSaved === "58008") { + } else if (Config.funbox === "58008") { // UpdateConfig.setPunctuation(false, true); UpdateConfig.setNumbers(false, true); randomWord = Misc.getNumbers(7); - } else if (Funbox.funboxSaved === "specials") { + } else if (Config.funbox === "specials") { UpdateConfig.setPunctuation(false, true); UpdateConfig.setNumbers(false, true); randomWord = Misc.getSpecials(); - } else if (Funbox.funboxSaved === "ascii") { + } else if (Config.funbox === "ascii") { UpdateConfig.setPunctuation(false, true); UpdateConfig.setNumbers(false, true); randomWord = Misc.getASCII(); @@ -774,7 +774,7 @@ export function restart( document.querySelector("#liveWpm").innerHTML = "0"; document.querySelector("#liveAcc").innerHTML = "100%"; - if (Funbox.active === "memory") { + if (Config.funbox === "memory") { Funbox.startMemoryTimer(); if (Config.keymapMode === "next") { UpdateConfig.setKeymapMode("react"); @@ -792,15 +792,15 @@ export function restart( mode2 = randomQuote.id; } let fbtext = ""; - if (Funbox.active !== "none") { - fbtext = " " + Funbox.active; + if (Config.funbox !== "none") { + fbtext = " " + Config.funbox; } $(".pageTest #premidTestMode").text( `${Config.mode} ${mode2} ${Config.language}${fbtext}` ); $(".pageTest #premidSecondsLeft").text(Config.time); - if (Funbox.active === "layoutfluid") { + if (Config.funbox === "layoutfluid") { UpdateConfig.setLayout( Config.customLayoutfluid ? Config.customLayoutfluid.split("#")[0] @@ -874,7 +874,7 @@ export function calculateWpmAndRaw() { if (words.getCurrent() == input.current) { correctWordChars += input.current.length; } - if (Funbox.active === "nospace") { + if (Config.funbox === "nospace") { spaces = 0; } chars += input.current.length; @@ -889,7 +889,7 @@ export function calculateWpmAndRaw() { export function addWord() { let bound = 100; - if (Funbox.active === "plus_one") bound = 1; + if (Config.funbox === "plus_one") bound = 1; if ( words.length - input.history.length > bound || (Config.mode === "words" && @@ -942,7 +942,7 @@ export function addWord() { } } - if (Funbox.active === "rAnDoMcAsE") { + if (Config.funbox === "rAnDoMcAsE") { let randomcaseword = ""; for (let i = 0; i < randomWord.length; i++) { if (i % 2 != 0) { @@ -952,13 +952,13 @@ export function addWord() { } } randomWord = randomcaseword; - } else if (Funbox.active === "gibberish") { + } else if (Config.funbox === "gibberish") { randomWord = Misc.getGibberish(); - } else if (Funbox.active === "58008") { + } else if (Config.funbox === "58008") { randomWord = Misc.getNumbers(7); - } else if (Funbox.active === "specials") { + } else if (Config.funbox === "specials") { randomWord = Misc.getSpecials(); - } else if (Funbox.active === "ascii") { + } else if (Config.funbox === "ascii") { randomWord = Misc.getASCII(); } @@ -1379,7 +1379,7 @@ export function finish(difficultyFailed = false) { keyDuration: TestStats.keypressTimings.duration.array, consistency: consistency, keyConsistency: keyConsistency, - funbox: Funbox.funboxSaved, + funbox: Config.funbox, bailedOut: bailout, chartData: chartData, customText: cdata, @@ -1734,9 +1734,9 @@ export function finish(difficultyFailed = false) { } if ( Config.mode != "custom" && - Funbox.funboxSaved !== "gibberish" && - Funbox.funboxSaved !== "ascii" && - Funbox.funboxSaved !== "58008" + Config.funbox !== "gibberish" && + Config.funbox !== "ascii" && + Config.funbox !== "58008" ) { testType += "
" + lang; } @@ -1749,8 +1749,8 @@ export function finish(difficultyFailed = false) { if (Config.blindMode) { testType += "
blind"; } - if (Funbox.funboxSaved !== "none") { - testType += "
" + Funbox.funboxSaved.replace(/_/g, " "); + if (Config.funbox !== "none") { + testType += "
" + Config.funbox.replace(/_/g, " "); } if (Config.difficulty == "expert") { testType += "
expert"; @@ -1804,9 +1804,9 @@ export function finish(difficultyFailed = false) { $("#result .stats .source").addClass("hidden"); } - if (Funbox.funboxSaved !== "none") { - let content = Funbox.funboxSaved; - if (Funbox.funboxSaved === "layoutfluid") { + if (Config.funbox !== "none") { + let content = Config.funbox; + if (Config.funbox === "layoutfluid") { content += " " + Config.customLayoutfluid.replace(/#/g, " "); } ChartController.result.options.annotation.annotations.push({ diff --git a/src/js/test/test-stats.js b/src/js/test/test-stats.js index 26407e272..efe07a9b4 100644 --- a/src/js/test/test-stats.js +++ b/src/js/test/test-stats.js @@ -310,7 +310,7 @@ function countChars() { spaces++; } } - if (Funbox.active === "nospace") { + if (Config.funbox === "nospace") { spaces = 0; correctspaces = 0; } diff --git a/src/js/test/test-timer.js b/src/js/test/test-timer.js index 991fbebab..94b3a954d 100644 --- a/src/js/test/test-timer.js +++ b/src/js/test/test-timer.js @@ -40,7 +40,7 @@ export function start() { let acc = Misc.roundTo2(TestStats.calculateAccuracy()); - if (Funbox.active === "layoutfluid" && Config.mode === "time") { + if (Config.funbox === "layoutfluid" && Config.mode === "time") { const layouts = Config.customLayoutfluid ? Config.customLayoutfluid.split("#") : ["qwerty", "dvorak", "colemak"]; diff --git a/src/js/test/test-ui.js b/src/js/test/test-ui.js index ba22f5e10..1fc21f262 100644 --- a/src/js/test/test-ui.js +++ b/src/js/test/test-ui.js @@ -524,9 +524,9 @@ export function updateModesNotice() { ); } - if (Funbox.active !== "none") { + if (Config.funbox !== "none") { $(".pageTest #testModesNotice").append( - `
${Funbox.active.replace( + `
${Config.funbox.replace( /_/g, " " )}
` diff --git a/src/js/ui.js b/src/js/ui.js index 85b8bdae3..11dcb4c9e 100644 --- a/src/js/ui.js +++ b/src/js/ui.js @@ -136,7 +136,7 @@ export function changePage(page) { TestStats.resetIncomplete(); ManualRestart.set(); TestLogic.restart(); - Funbox.activate(Funbox.funboxSaved, Funbox.modeSaved); + Funbox.activate(Config.funbox); } else if (page == "about") { setPageTransition(true); TestLogic.restart(); @@ -145,7 +145,7 @@ export function changePage(page) { history.pushState("about", null, "about"); $(".page.pageAbout").addClass("active"); }); - Funbox.activate("none", null); + Funbox.activate("none"); TestConfig.hide(); SignOutButton.hide(); } else if (page == "settings") { @@ -156,7 +156,7 @@ export function changePage(page) { history.pushState("settings", null, "settings"); $(".page.pageSettings").addClass("active"); }); - Funbox.activate("none", null); + Funbox.activate("none"); Settings.update(); TestConfig.hide(); SignOutButton.hide(); @@ -182,7 +182,7 @@ export function changePage(page) { SignOutButton.show(); } ); - Funbox.activate("none", null); + Funbox.activate("none"); Account.update(); TestConfig.hide(); } @@ -197,7 +197,7 @@ export function changePage(page) { history.pushState("login", null, "login"); $(".page.pageLogin").addClass("active"); }); - Funbox.activate("none", null); + Funbox.activate("none"); TestConfig.hide(); SignOutButton.hide(); }