From ca018155ee0730ab75e6ea46c69be20c4c9d54f2 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 26 Mar 2021 00:23:32 +0000 Subject: [PATCH 1/6] reordered functions to fix some warnings, removed unused code --- src/js/chart-controller.js | 16 +- src/js/config.js | 366 +++++++++++++++---------------- src/js/dom-util.js | 3 +- src/js/leaderboards.js | 36 +-- src/js/quote-search-popup.js | 92 ++++---- src/js/sound.js | 2 +- src/js/tag-controller.js | 28 +-- src/js/test/caps-warning.js | 2 +- src/js/test/caret.js | 18 +- src/js/test/funbox.js | 52 ++--- src/js/test/keymap.js | 2 +- src/js/test/live-acc.js | 2 +- src/js/test/live-wpm.js | 2 +- src/js/test/pace-caret.js | 50 ++--- src/js/test/test-leaderboards.js | 110 +++++----- src/js/test/test-logic.js | 204 ++++++++--------- src/js/test/test-stats.js | 10 +- src/js/test/test-timer.js | 1 - src/js/test/test-ui.js | 54 ++--- src/js/test/timer-progress.js | 2 +- src/js/theme-controller.js | 84 +++---- 21 files changed, 567 insertions(+), 569 deletions(-) diff --git a/src/js/chart-controller.js b/src/js/chart-controller.js index 2b19bcc2f..d61846563 100644 --- a/src/js/chart-controller.js +++ b/src/js/chart-controller.js @@ -622,14 +622,6 @@ export let miniResult = new Chart($(".pageAccount #miniResultChart"), { }, }); -Chart.prototype.updateColors = function () { - updateColors(this); -}; - -export function setDefaultFontFamily(font) { - Chart.defaults.global.defaultFontFamily = font.replace(/_/g, " "); -} - export function updateColors(chart) { if (ThemeColors.main == "") { ThemeColors.update(); @@ -689,6 +681,14 @@ export function updateColors(chart) { chart.update(); } +Chart.prototype.updateColors = function () { + updateColors(this); +}; + +export function setDefaultFontFamily(font) { + Chart.defaults.global.defaultFontFamily = font.replace(/_/g, " "); +} + export function updateAllChartColors() { ThemeColors.update(); accountHistory.updateColors(); diff --git a/src/js/config.js b/src/js/config.js index 070eb8ff9..ce9494719 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -114,42 +114,15 @@ let defaultConfig = { oppositeShiftMode: "off", }; -let config = { - ...defaultConfig, -}; - -export function reset() { - config = { - ...defaultConfig, - }; - apply(); - saveToCookie(); -} - function isConfigKeyValid(name) { if (name === null || name === undefined || name === "") return false; if (name.length > 30) return false; return /^[0-9a-zA-Z_.\-#+]+$/.test(name); } -export function loadFromCookie() { - console.log("loading cookie config"); - // let newConfig = $.cookie("config"); - let newConfig = Misc.getCookie("config"); - if (newConfig !== undefined && newConfig !== "") { - try { - newConfig = JSON.parse(newConfig); - } catch (e) { - newConfig = {}; - } - apply(newConfig); - console.log("applying cookie config"); - cookieConfig = newConfig; - saveToCookie(true); - console.log("saving cookie config"); - } - TestLogic.restart(false, true); -} +let config = { + ...defaultConfig, +}; export async function saveToCookie(noDbCheck = false) { if (!dbConfigLoaded && !noDbCheck) { @@ -168,6 +141,134 @@ export async function saveToCookie(noDbCheck = false) { if (!noDbCheck) await DB.saveConfig(save); } +//numbers +export function setNumbers(numb, nosave) { + if (config.mode === "quote") { + numb = false; + } + config.numbers = numb; + if (!config.numbers) { + $("#top .config .numbersMode .text-button").removeClass("active"); + } else { + $("#top .config .numbersMode .text-button").addClass("active"); + } + if (!nosave) saveToCookie(); +} + +export function toggleNumbers() { + config.numbers = !config.numbers; + if (config.mode === "quote") { + config.numbers = false; + } + if (config.numbers) { + $("#top .config .numbersMode .text-button").addClass("active"); + } else { + $("#top .config .numbersMode .text-button").removeClass("active"); + } + saveToCookie(); +} + +//punctuation +export function setPunctuation(punc, nosave) { + if (config.mode === "quote") { + punc = false; + } + config.punctuation = punc; + if (!config.punctuation) { + $("#top .config .punctuationMode .text-button").removeClass("active"); + } else { + $("#top .config .punctuationMode .text-button").addClass("active"); + } + if (!nosave) saveToCookie(); +} + +export function togglePunctuation() { + config.punctuation = !config.punctuation; + if (config.mode === "quote") { + config.punctuation = false; + } + if (config.punctuation) { + $("#top .config .punctuationMode .text-button").addClass("active"); + } else { + $("#top .config .punctuationMode .text-button").removeClass("active"); + } + saveToCookie(); +} + +export function setMode(mode, nosave) { + if (TestUI.testRestarting) return; + if (mode !== "words" && Funbox.active === "memory") { + Notifications.add("Memory funbox can only be used with words mode.", 0); + return; + } + + config.mode = mode; + $("#top .config .mode .text-button").removeClass("active"); + $("#top .config .mode .text-button[mode='" + mode + "']").addClass("active"); + if (config.mode == "time") { + $("#top .config .wordCount").addClass("hidden"); + $("#top .config .time").removeClass("hidden"); + $("#top .config .customText").addClass("hidden"); + $("#top .config .punctuationMode").removeClass("disabled"); + $("#top .config .numbersMode").removeClass("disabled"); + $("#top .config .punctuationMode").removeClass("hidden"); + $("#top .config .numbersMode").removeClass("hidden"); + $("#top .config .quoteLength").addClass("hidden"); + } else if (config.mode == "words") { + $("#top .config .wordCount").removeClass("hidden"); + $("#top .config .time").addClass("hidden"); + $("#top .config .customText").addClass("hidden"); + $("#top .config .punctuationMode").removeClass("disabled"); + $("#top .config .numbersMode").removeClass("disabled"); + $("#top .config .punctuationMode").removeClass("hidden"); + $("#top .config .numbersMode").removeClass("hidden"); + $("#top .config .quoteLength").addClass("hidden"); + } else if (config.mode == "custom") { + if ( + Funbox.active === "58008" || + Funbox.active === "gibberish" || + Funbox.active === "ascii" + ) { + Funbox.setAcitve("none"); + TestUI.updateModesNotice(); + } + $("#top .config .wordCount").addClass("hidden"); + $("#top .config .time").addClass("hidden"); + $("#top .config .customText").removeClass("hidden"); + $("#top .config .punctuationMode").removeClass("disabled"); + $("#top .config .numbersMode").removeClass("disabled"); + $("#top .config .punctuationMode").removeClass("hidden"); + $("#top .config .numbersMode").removeClass("hidden"); + $("#top .config .quoteLength").addClass("hidden"); + setPunctuation(false, true); + setNumbers(false, true); + } else if (config.mode == "quote") { + setPunctuation(false, nosave); + setNumbers(false, nosave); + $("#top .config .wordCount").addClass("hidden"); + $("#top .config .time").addClass("hidden"); + $("#top .config .customText").addClass("hidden"); + $("#top .config .punctuationMode").addClass("disabled"); + $("#top .config .numbersMode").addClass("disabled"); + $("#top .config .punctuationMode").removeClass("hidden"); + $("#top .config .numbersMode").removeClass("hidden"); + $("#result .stats .source").removeClass("hidden"); + $("#top .config .quoteLength").removeClass("hidden"); + } else if (config.mode == "zen") { + $("#top .config .wordCount").addClass("hidden"); + $("#top .config .time").addClass("hidden"); + $("#top .config .customText").addClass("hidden"); + $("#top .config .punctuationMode").addClass("hidden"); + $("#top .config .numbersMode").addClass("hidden"); + $("#top .config .quoteLength").addClass("hidden"); + if (config.paceCaret != "off") { + Notifications.add(`Pace caret will not work with zen mode.`, 0); + } + // setPaceCaret("off", true); + } + if (!nosave) saveToCookie(); +} + export function setPlaySoundOnError(val, nosave) { if (val == undefined) { val = false; @@ -954,60 +1055,6 @@ export function toggleQuickTabMode() { console.log(config.quickTab); } -//numbers -export function setNumbers(numb, nosave) { - if (config.mode === "quote") { - numb = false; - } - config.numbers = numb; - if (!config.numbers) { - $("#top .config .numbersMode .text-button").removeClass("active"); - } else { - $("#top .config .numbersMode .text-button").addClass("active"); - } - if (!nosave) saveToCookie(); -} - -export function toggleNumbers() { - config.numbers = !config.numbers; - if (config.mode === "quote") { - config.numbers = false; - } - if (config.numbers) { - $("#top .config .numbersMode .text-button").addClass("active"); - } else { - $("#top .config .numbersMode .text-button").removeClass("active"); - } - saveToCookie(); -} - -//punctuation -export function setPunctuation(punc, nosave) { - if (config.mode === "quote") { - punc = false; - } - config.punctuation = punc; - if (!config.punctuation) { - $("#top .config .punctuationMode .text-button").removeClass("active"); - } else { - $("#top .config .punctuationMode .text-button").addClass("active"); - } - if (!nosave) saveToCookie(); -} - -export function togglePunctuation() { - config.punctuation = !config.punctuation; - if (config.mode === "quote") { - config.punctuation = false; - } - if (config.punctuation) { - $("#top .config .punctuationMode .text-button").addClass("active"); - } else { - $("#top .config .punctuationMode .text-button").removeClass("active"); - } - saveToCookie(); -} - export function previewFontFamily(font) { if (font == undefined) { font = "Roboto_Mono"; @@ -1098,6 +1145,11 @@ export function setIndicateTypos(it, nosave) { if (!nosave) saveToCookie(); } +export function setCustomTheme(boolean, nosave) { + if (boolean !== undefined) config.customTheme = boolean; + if (!nosave) saveToCookie(); +} + export function setTheme(name, nosave) { config.theme = name; setCustomTheme(false, true); @@ -1116,11 +1168,6 @@ export function setRandomTheme(val, nosave) { if (!nosave) saveToCookie(); } -export function setCustomTheme(boolean, nosave) { - if (boolean !== undefined) config.customTheme = boolean; - if (!nosave) saveToCookie(); -} - export function toggleCustomTheme(nosave) { if (config.customTheme) { setCustomTheme(false); @@ -1192,26 +1239,6 @@ export function toggleCapsLockBackspace() { setCapsLockBackspace(!config.capsLockBackspace, false); } -export function setLayout(layout, nosave) { - if (layout == null || layout == undefined) { - layout = "qwerty"; - } - config.layout = layout; - TestUI.updateModesNotice(); - if (config.keymapLayout === "overrideSync") { - Keymap.refreshKeys(config.keymapLayout, setKeymapLayout); - } - if (!nosave) saveToCookie(); -} - -export function setSavedLayout(layout, nosave) { - if (layout == null || layout == undefined) { - layout = "qwerty"; - } - config.savedLayout = layout; - setLayout(layout, nosave); -} - export function setKeymapMode(mode, nosave) { if (mode == null || mode == undefined) { mode = "off"; @@ -1252,6 +1279,26 @@ export function setKeymapLayout(layout, nosave) { if (!nosave) saveToCookie(); } +export function setLayout(layout, nosave) { + if (layout == null || layout == undefined) { + layout = "qwerty"; + } + config.layout = layout; + TestUI.updateModesNotice(); + if (config.keymapLayout === "overrideSync") { + Keymap.refreshKeys(config.keymapLayout, setKeymapLayout); + } + if (!nosave) saveToCookie(); +} + +export function setSavedLayout(layout, nosave) { + if (layout == null || layout == undefined) { + layout = "qwerty"; + } + config.savedLayout = layout; + setLayout(layout, nosave); +} + export function setFontSize(fontSize, nosave) { if (fontSize == null || fontSize == undefined) { fontSize = 1; @@ -1291,80 +1338,6 @@ export function setFontSize(fontSize, nosave) { if (!nosave) saveToCookie(); } -export function setMode(mode, nosave) { - if (TestUI.testRestarting) return; - if (mode !== "words" && Funbox.active === "memory") { - Notifications.add("Memory funbox can only be used with words mode.", 0); - return; - } - - config.mode = mode; - $("#top .config .mode .text-button").removeClass("active"); - $("#top .config .mode .text-button[mode='" + mode + "']").addClass("active"); - if (config.mode == "time") { - $("#top .config .wordCount").addClass("hidden"); - $("#top .config .time").removeClass("hidden"); - $("#top .config .customText").addClass("hidden"); - $("#top .config .punctuationMode").removeClass("disabled"); - $("#top .config .numbersMode").removeClass("disabled"); - $("#top .config .punctuationMode").removeClass("hidden"); - $("#top .config .numbersMode").removeClass("hidden"); - $("#top .config .quoteLength").addClass("hidden"); - } else if (config.mode == "words") { - $("#top .config .wordCount").removeClass("hidden"); - $("#top .config .time").addClass("hidden"); - $("#top .config .customText").addClass("hidden"); - $("#top .config .punctuationMode").removeClass("disabled"); - $("#top .config .numbersMode").removeClass("disabled"); - $("#top .config .punctuationMode").removeClass("hidden"); - $("#top .config .numbersMode").removeClass("hidden"); - $("#top .config .quoteLength").addClass("hidden"); - } else if (config.mode == "custom") { - if ( - Funbox.active === "58008" || - Funbox.active === "gibberish" || - Funbox.active === "ascii" - ) { - Funbox.setAcitve("none"); - TestUI.updateModesNotice(); - } - $("#top .config .wordCount").addClass("hidden"); - $("#top .config .time").addClass("hidden"); - $("#top .config .customText").removeClass("hidden"); - $("#top .config .punctuationMode").removeClass("disabled"); - $("#top .config .numbersMode").removeClass("disabled"); - $("#top .config .punctuationMode").removeClass("hidden"); - $("#top .config .numbersMode").removeClass("hidden"); - $("#top .config .quoteLength").addClass("hidden"); - setPunctuation(false, true); - setNumbers(false, true); - } else if (config.mode == "quote") { - setPunctuation(false, nosave); - setNumbers(false, nosave); - $("#top .config .wordCount").addClass("hidden"); - $("#top .config .time").addClass("hidden"); - $("#top .config .customText").addClass("hidden"); - $("#top .config .punctuationMode").addClass("disabled"); - $("#top .config .numbersMode").addClass("disabled"); - $("#top .config .punctuationMode").removeClass("hidden"); - $("#top .config .numbersMode").removeClass("hidden"); - $("#result .stats .source").removeClass("hidden"); - $("#top .config .quoteLength").removeClass("hidden"); - } else if (config.mode == "zen") { - $("#top .config .wordCount").addClass("hidden"); - $("#top .config .time").addClass("hidden"); - $("#top .config .customText").addClass("hidden"); - $("#top .config .punctuationMode").addClass("hidden"); - $("#top .config .numbersMode").addClass("hidden"); - $("#top .config .quoteLength").addClass("hidden"); - if (config.paceCaret != "off") { - Notifications.add(`Pace caret will not work with zen mode.`, 0); - } - // setPaceCaret("off", true); - } - if (!nosave) saveToCookie(); -} - export function apply(configObj) { if (configObj == null || configObj == undefined) { Notifications.add("Could not apply config", -1, 3); @@ -1625,4 +1598,31 @@ export function apply(configObj) { TestUI.updateModesNotice(); } +export function reset() { + config = { + ...defaultConfig, + }; + apply(); + saveToCookie(); +} + +export function loadFromCookie() { + console.log("loading cookie config"); + // let newConfig = $.cookie("config"); + let newConfig = Misc.getCookie("config"); + if (newConfig !== undefined && newConfig !== "") { + try { + newConfig = JSON.parse(newConfig); + } catch (e) { + newConfig = {}; + } + apply(newConfig); + console.log("applying cookie config"); + cookieConfig = newConfig; + saveToCookie(true); + console.log("saving cookie config"); + } + TestLogic.restart(false, true); +} + export default config; diff --git a/src/js/dom-util.js b/src/js/dom-util.js index c9e273e1e..4b4776dbf 100644 --- a/src/js/dom-util.js +++ b/src/js/dom-util.js @@ -1,5 +1,4 @@ -import * as DB from "./db"; -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; export function showBackgroundLoader() { $("#backgroundLoader").stop(true, true).fadeIn(125); diff --git a/src/js/leaderboards.js b/src/js/leaderboards.js index 5678df2c5..d63a2ada9 100644 --- a/src/js/leaderboards.js +++ b/src/js/leaderboards.js @@ -4,24 +4,6 @@ import * as Notifications from "./notification-center"; let currentLeaderboard = "time_15"; -export function show() { - if ($("#leaderboardsWrapper").hasClass("hidden")) { - $("#leaderboardsWrapper") - .stop(true, true) - .css("opacity", 0) - .removeClass("hidden") - .animate( - { - opacity: 1, - }, - 125, - () => { - update(); - } - ); - } -} - export function hide() { $("#leaderboardsWrapper") .stop(true, true) @@ -268,6 +250,24 @@ function update() { }); } +export function show() { + if ($("#leaderboardsWrapper").hasClass("hidden")) { + $("#leaderboardsWrapper") + .stop(true, true) + .css("opacity", 0) + .removeClass("hidden") + .animate( + { + opacity: 1, + }, + 125, + () => { + update(); + } + ); + } +} + $("#leaderboardsWrapper").click((e) => { if ($(e.target).attr("id") === "leaderboardsWrapper") { hide(); diff --git a/src/js/quote-search-popup.js b/src/js/quote-search-popup.js index 856896630..d0fff2fc6 100644 --- a/src/js/quote-search-popup.js +++ b/src/js/quote-search-popup.js @@ -1,56 +1,11 @@ import * as Misc from "./misc"; import * as Notifications from "./notification-center"; -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import * as ManualRestart from "./manual-restart-tracker"; import * as TestLogic from "./test-logic"; export let selectedId = 1; -export async function show() { - if ($("#quoteSearchPopupWrapper").hasClass("hidden")) { - $("#quoteSearchPopup input").val(""); - $("#quoteSearchPopupWrapper") - .stop(true, true) - .css("opacity", 0) - .removeClass("hidden") - .animate({ opacity: 1 }, 100, (e) => { - $("#quoteSearchPopup input").focus().select(); - updateResults(""); - }); - } -} - -export function hide() { - if (!$("#quoteSearchPopupWrapper").hasClass("hidden")) { - $("#quoteSearchPopupWrapper") - .stop(true, true) - .css("opacity", 1) - .animate( - { - opacity: 0, - }, - 100, - (e) => { - $("#quoteSearchPopupWrapper").addClass("hidden"); - } - ); - } -} - -function apply(val) { - if (isNaN(val)) { - val = document.getElementById("searchBox").value; - } - if (val !== null && !isNaN(val) && val >= 0) { - selectedId = val; - ManualRestart.set(); - TestLogic.restart(); - } else { - Notifications.add("Quote ID must be at least 1", 0); - } - hide(); -} - async function updateResults(searchText) { let quotes = await Misc.getQuotes(Config.language); let reg = new RegExp(searchText, "i"); @@ -114,6 +69,51 @@ async function updateResults(searchText) { } } +export async function show() { + if ($("#quoteSearchPopupWrapper").hasClass("hidden")) { + $("#quoteSearchPopup input").val(""); + $("#quoteSearchPopupWrapper") + .stop(true, true) + .css("opacity", 0) + .removeClass("hidden") + .animate({ opacity: 1 }, 100, (e) => { + $("#quoteSearchPopup input").focus().select(); + updateResults(""); + }); + } +} + +export function hide() { + if (!$("#quoteSearchPopupWrapper").hasClass("hidden")) { + $("#quoteSearchPopupWrapper") + .stop(true, true) + .css("opacity", 1) + .animate( + { + opacity: 0, + }, + 100, + (e) => { + $("#quoteSearchPopupWrapper").addClass("hidden"); + } + ); + } +} + +function apply(val) { + if (isNaN(val)) { + val = document.getElementById("searchBox").value; + } + if (val !== null && !isNaN(val) && val >= 0) { + selectedId = val; + ManualRestart.set(); + TestLogic.restart(); + } else { + Notifications.add("Quote ID must be at least 1", 0); + } + hide(); +} + $("#quoteSearchPopup .searchBox").keydown((e) => { setTimeout(() => { let searchText = document.getElementById("searchBox").value; diff --git a/src/js/sound.js b/src/js/sound.js index 8e717a6b5..eb587ae41 100644 --- a/src/js/sound.js +++ b/src/js/sound.js @@ -1,4 +1,4 @@ -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; let errorSound = new Audio("../sound/error.wav"); let clickSounds = null; diff --git a/src/js/tag-controller.js b/src/js/tag-controller.js index 6e6621e98..d0375b1ba 100644 --- a/src/js/tag-controller.js +++ b/src/js/tag-controller.js @@ -2,20 +2,6 @@ import * as DB from "./db"; import * as TestUI from "./test-ui"; import * as Misc from "./misc"; -export function toggle(tagid, nosave = false) { - DB.getSnapshot().tags.forEach((tag) => { - if (tag.id === tagid) { - if (tag.active === undefined) { - tag.active = true; - } else { - tag.active = !tag.active; - } - } - }); - TestUI.updateModesNotice(); - if (!nosave) saveActiveToCookie(); -} - export function saveActiveToCookie() { let tags = []; @@ -36,6 +22,20 @@ export function saveActiveToCookie() { } catch (e) {} } +export function toggle(tagid, nosave = false) { + DB.getSnapshot().tags.forEach((tag) => { + if (tag.id === tagid) { + if (tag.active === undefined) { + tag.active = true; + } else { + tag.active = !tag.active; + } + } + }); + TestUI.updateModesNotice(); + if (!nosave) saveActiveToCookie(); +} + export function loadActiveFromCookie() { // let newTags = $.cookie("activeTags"); let newTags = Misc.getCookie("activeTags"); diff --git a/src/js/test/caps-warning.js b/src/js/test/caps-warning.js index e1f6b973a..39e097570 100644 --- a/src/js/test/caps-warning.js +++ b/src/js/test/caps-warning.js @@ -1,4 +1,4 @@ -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; function show() { if ($("#capsWarning").hasClass("hidden")) { diff --git a/src/js/test/caret.js b/src/js/test/caret.js index dc848ac3a..3f523cd20 100644 --- a/src/js/test/caret.js +++ b/src/js/test/caret.js @@ -1,5 +1,5 @@ import * as Misc from "./misc"; -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import * as TestLogic from "./test-logic"; export let caretAnimating = true; @@ -28,14 +28,6 @@ export function hide() { $("#caret").addClass("hidden"); } -export function show() { - if ($("#result").hasClass("hidden")) { - updatePosition(); - $("#caret").removeClass("hidden"); - startAnimation(); - } -} - //TODO remove this after test logic is a module //TODO remove config when module export function updatePosition() { @@ -128,3 +120,11 @@ export function updatePosition() { console.log("could not move caret: " + e.message); } } + +export function show() { + if ($("#result").hasClass("hidden")) { + updatePosition(); + $("#caret").removeClass("hidden"); + startAnimation(); + } +} diff --git a/src/js/test/funbox.js b/src/js/test/funbox.js index 10a676ea1..6733371a7 100644 --- a/src/js/test/funbox.js +++ b/src/js/test/funbox.js @@ -9,32 +9,6 @@ export let active = "none"; let memoryTimer = null; let memoryInterval = null; -export function reset() { - active = "none"; - resetMemoryTimer(); -} - -export function startMemoryTimer() { - resetMemoryTimer(); - memoryTimer = Math.round(Math.pow(TestLogic.words.length, 1.2)); - updateMemoryTimer(memoryTimer); - showMemoryTimer(); - memoryInterval = setInterval(() => { - memoryTimer -= 1; - memoryTimer == 0 ? hideMemoryTimer() : updateMemoryTimer(memoryTimer); - if (memoryTimer <= 0) { - resetMemoryTimer(); - $("#wordsWrapper").addClass("hidden"); - } - }, 1000); -} - -export function resetMemoryTimer() { - memoryInterval = clearInterval(memoryInterval); - memoryTimer = null; - hideMemoryTimer(); -} - function showMemoryTimer() { $("#typingTest #memoryTimer").stop(true, true).animate( { @@ -53,12 +27,38 @@ function hideMemoryTimer() { ); } +export function resetMemoryTimer() { + memoryInterval = clearInterval(memoryInterval); + memoryTimer = null; + hideMemoryTimer(); +} + function updateMemoryTimer(sec) { $("#typingTest #memoryTimer").text( `Timer left to memorise all words: ${sec}s` ); } +export function startMemoryTimer() { + resetMemoryTimer(); + memoryTimer = Math.round(Math.pow(TestLogic.words.length, 1.2)); + updateMemoryTimer(memoryTimer); + showMemoryTimer(); + memoryInterval = setInterval(() => { + memoryTimer -= 1; + memoryTimer == 0 ? hideMemoryTimer() : updateMemoryTimer(memoryTimer); + if (memoryTimer <= 0) { + resetMemoryTimer(); + $("#wordsWrapper").addClass("hidden"); + } + }, 1000); +} + +export function reset() { + active = "none"; + resetMemoryTimer(); +} + export function toggleScript(...params) { if (active === "tts") { var msg = new SpeechSynthesisUtterance(); diff --git a/src/js/test/keymap.js b/src/js/test/keymap.js index 8988e8f64..98146f49e 100644 --- a/src/js/test/keymap.js +++ b/src/js/test/keymap.js @@ -1,4 +1,4 @@ -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import * as ThemeColors from "./theme-colors"; import layouts from "./layouts"; diff --git a/src/js/test/live-acc.js b/src/js/test/live-acc.js index e3cf1eecd..23c144bf4 100644 --- a/src/js/test/live-acc.js +++ b/src/js/test/live-acc.js @@ -1,4 +1,4 @@ -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; export function update(acc) { let number = Math.floor(acc); diff --git a/src/js/test/live-wpm.js b/src/js/test/live-wpm.js index 07b6591c2..2cedad0cc 100644 --- a/src/js/test/live-wpm.js +++ b/src/js/test/live-wpm.js @@ -1,4 +1,4 @@ -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; export function update(wpm, raw) { // if (!TestLogic.active || !Config.showLiveWpm) { diff --git a/src/js/test/pace-caret.js b/src/js/test/pace-caret.js index 28224840f..7b0422e7f 100644 --- a/src/js/test/pace-caret.js +++ b/src/js/test/pace-caret.js @@ -1,12 +1,30 @@ import * as TestLogic from "./test-logic"; import * as TestUI from "./test-ui"; -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import * as DB from "./db"; export let settings = null; -export function start() { - update(performance.now() + settings.spc * 1000); +function resetCaretPosition() { + if (Config.paceCaret === "off") return; + if (!$("#paceCaret").hasClass("hidden")) { + $("#paceCaret").addClass("hidden"); + } + if (Config.mode === "zen") return; + + let caret = $("#paceCaret"); + let firstLetter = document + .querySelector("#words .word") + .querySelector("letter"); + + caret.stop(true, true).animate( + { + top: firstLetter.offsetTop - $(firstLetter).height() / 4, + left: firstLetter.offsetLeft, + }, + 0, + "linear" + ); } export async function init() { @@ -202,28 +220,6 @@ export function update(expectedStepEnd) { } } -function resetCaretPosition() { - if (Config.paceCaret === "off") return; - if (!$("#paceCaret").hasClass("hidden")) { - $("#paceCaret").addClass("hidden"); - } - if (Config.mode === "zen") return; - - let caret = $("#paceCaret"); - let firstLetter = document - .querySelector("#words .word") - .querySelector("letter"); - - caret.stop(true, true).animate( - { - top: firstLetter.offsetTop - $(firstLetter).height() / 4, - left: firstLetter.offsetLeft, - }, - 0, - "linear" - ); -} - export function reset() { settings = null; if (settings !== null) clearTimeout(settings.timeout); @@ -250,3 +246,7 @@ export function handleSpace(correct, currentWord) { } } } + +export function start() { + update(performance.now() + settings.spc * 1000); +} diff --git a/src/js/test/test-leaderboards.js b/src/js/test/test-leaderboards.js index 5b69c8c75..7cabd39d6 100644 --- a/src/js/test/test-leaderboards.js +++ b/src/js/test/test-leaderboards.js @@ -1,65 +1,11 @@ import * as CloudFunctions from "./cloud-functions"; import * as DB from "./db"; import * as Notifications from "./notification-center"; -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import * as Misc from "./misc"; let textTimeouts = []; -export function check(completedEvent) { - try { - if ( - completedEvent.funbox === "none" && - completedEvent.language === "english" && - completedEvent.mode === "time" && - ["15", "60"].includes(String(completedEvent.mode2)) - ) { - $("#result .stats .leaderboards").removeClass("hidden"); - $("#result .stats .leaderboards .bottom").html( - `checking ` - ); - textTimeouts.push( - setTimeout(() => { - $("#result .stats .leaderboards .bottom").html( - `still checking ` - ); - }, 5000) - ); - textTimeouts.push( - setTimeout(() => { - $("#result .stats .leaderboards .bottom").html( - `leaderboard seems
to be very busy ` - ); - }, 10000) - ); - let lbRes = completedEvent; - delete lbRes.keySpacing; - delete lbRes.keyDuration; - delete lbRes.chartData; - CloudFunctions.checkLeaderboards({ - uid: completedEvent.uid, - lbMemory: DB.getSnapshot().lbMemory, - emailVerified: DB.getSnapshot().emailVerified, - name: DB.getSnapshot().name, - banned: DB.getSnapshot().banned, - verified: DB.getSnapshot().verified, - discordId: DB.getSnapshot().discordId, - result: lbRes, - }) - .then((data) => { - Misc.clearTimeouts(textTimeouts); - show(data.data, completedEvent.mode2); - }) - .catch((e) => { - $("#result .stats .leaderboards").addClass("hidden"); - Notifications.add(e, -1); - }); - } - } catch (e) { - Notifications.add(`Error while checking leaderboards: ${e}`, -1); - } -} - export function show(data, mode2) { let string = ""; if (data.needsToVerifyEmail === true) { @@ -183,3 +129,57 @@ export function show(data, mode2) { $("#result .stats .leaderboards").removeClass("hidden"); $("#result .stats .leaderboards .bottom").html(string); } + +export function check(completedEvent) { + try { + if ( + completedEvent.funbox === "none" && + completedEvent.language === "english" && + completedEvent.mode === "time" && + ["15", "60"].includes(String(completedEvent.mode2)) + ) { + $("#result .stats .leaderboards").removeClass("hidden"); + $("#result .stats .leaderboards .bottom").html( + `checking ` + ); + textTimeouts.push( + setTimeout(() => { + $("#result .stats .leaderboards .bottom").html( + `still checking ` + ); + }, 5000) + ); + textTimeouts.push( + setTimeout(() => { + $("#result .stats .leaderboards .bottom").html( + `leaderboard seems
to be very busy ` + ); + }, 10000) + ); + let lbRes = completedEvent; + delete lbRes.keySpacing; + delete lbRes.keyDuration; + delete lbRes.chartData; + CloudFunctions.checkLeaderboards({ + uid: completedEvent.uid, + lbMemory: DB.getSnapshot().lbMemory, + emailVerified: DB.getSnapshot().emailVerified, + name: DB.getSnapshot().name, + banned: DB.getSnapshot().banned, + verified: DB.getSnapshot().verified, + discordId: DB.getSnapshot().discordId, + result: lbRes, + }) + .then((data) => { + Misc.clearTimeouts(textTimeouts); + show(data.data, completedEvent.mode2); + }) + .catch((e) => { + $("#result .stats .leaderboards").addClass("hidden"); + Notifications.add(e, -1); + }); + } + } catch (e) { + Notifications.add(`Error while checking leaderboards: ${e}`, -1); + } +} diff --git a/src/js/test/test-logic.js b/src/js/test/test-logic.js index ec9d8bf9c..73f3dc7f2 100644 --- a/src/js/test/test-logic.js +++ b/src/js/test/test-logic.js @@ -188,6 +188,108 @@ export function setRandomQuote(rq) { randomQuote = rq; } +export function punctuateWord(previousWord, currentWord, index, maxindex) { + let word = currentWord; + + if ( + (index == 0 || + Misc.getLastChar(previousWord) == "." || + Misc.getLastChar(previousWord) == "?" || + Misc.getLastChar(previousWord) == "!") && + UpdateConfig.language.split("_")[0] != "code" + ) { + //always capitalise the first word or if there was a dot unless using a code alphabet + word = Misc.capitalizeFirstLetter(word); + } else if ( + (Math.random() < 0.1 && + Misc.getLastChar(previousWord) != "." && + Misc.getLastChar(previousWord) != "," && + index != maxindex - 2) || + index == maxindex - 1 + ) { + let rand = Math.random(); + if (rand <= 0.8) { + word += "."; + } else if (rand > 0.8 && rand < 0.9) { + if (Config.language.split("_")[0] == "french") { + word = "?"; + } else { + word += "?"; + } + } else { + if (Config.language.split("_")[0] == "french") { + word = "!"; + } else { + word += "!"; + } + } + } else if ( + Math.random() < 0.01 && + Misc.getLastChar(previousWord) != "," && + Misc.getLastChar(previousWord) != "." && + UpdateConfig.language.split("_")[0] !== "russian" + ) { + word = `"${word}"`; + } else if ( + Math.random() < 0.011 && + Misc.getLastChar(previousWord) != "," && + Misc.getLastChar(previousWord) != "." && + UpdateConfig.language.split("_")[0] !== "russian" + ) { + word = `'${word}'`; + } else if ( + Math.random() < 0.012 && + Misc.getLastChar(previousWord) != "," && + Misc.getLastChar(previousWord) != "." + ) { + if (Config.language.split("_")[0] == "code") { + let r = Math.random(); + if (r < 0.25) { + word = `(${word})`; + } else if (r < 0.5) { + word = `{${word}}`; + } else if (r < 0.75) { + word = `[${word}]`; + } else { + word = `<${word}>`; + } + } else { + word = `(${word})`; + } + } else if (Math.random() < 0.013) { + if (Config.language.split("_")[0] == "french") { + word = ":"; + } else { + word += ":"; + } + } else if ( + Math.random() < 0.014 && + Misc.getLastChar(previousWord) != "," && + Misc.getLastChar(previousWord) != "." && + previousWord != "-" + ) { + word = "-"; + } else if ( + Math.random() < 0.015 && + Misc.getLastChar(previousWord) != "," && + Misc.getLastChar(previousWord) != "." && + Misc.getLastChar(previousWord) != ";" + ) { + if (Config.language.split("_")[0] == "french") { + word = ";"; + } else { + word += ";"; + } + } else if (Math.random() < 0.2 && Misc.getLastChar(previousWord) != ",") { + word += ","; + } else if (Math.random() < 0.25 && Config.language.split("_")[0] == "code") { + let specials = ["{", "}", "[", "]", "(", ")", ";", "=", "%", "/"]; + + word = specials[Math.floor(Math.random() * 10)]; + } + return word; +} + export async function init() { setActive(false); words.reset(); @@ -566,108 +668,6 @@ export function addWord() { $("#words").append(w); } -export function punctuateWord(previousWord, currentWord, index, maxindex) { - let word = currentWord; - - if ( - (index == 0 || - Misc.getLastChar(previousWord) == "." || - Misc.getLastChar(previousWord) == "?" || - Misc.getLastChar(previousWord) == "!") && - UpdateConfig.language.split("_")[0] != "code" - ) { - //always capitalise the first word or if there was a dot unless using a code alphabet - word = Misc.capitalizeFirstLetter(word); - } else if ( - (Math.random() < 0.1 && - Misc.getLastChar(previousWord) != "." && - Misc.getLastChar(previousWord) != "," && - index != maxindex - 2) || - index == maxindex - 1 - ) { - let rand = Math.random(); - if (rand <= 0.8) { - word += "."; - } else if (rand > 0.8 && rand < 0.9) { - if (Config.language.split("_")[0] == "french") { - word = "?"; - } else { - word += "?"; - } - } else { - if (Config.language.split("_")[0] == "french") { - word = "!"; - } else { - word += "!"; - } - } - } else if ( - Math.random() < 0.01 && - Misc.getLastChar(previousWord) != "," && - Misc.getLastChar(previousWord) != "." && - UpdateConfig.language.split("_")[0] !== "russian" - ) { - word = `"${word}"`; - } else if ( - Math.random() < 0.011 && - Misc.getLastChar(previousWord) != "," && - Misc.getLastChar(previousWord) != "." && - UpdateConfig.language.split("_")[0] !== "russian" - ) { - word = `'${word}'`; - } else if ( - Math.random() < 0.012 && - Misc.getLastChar(previousWord) != "," && - Misc.getLastChar(previousWord) != "." - ) { - if (Config.language.split("_")[0] == "code") { - let r = Math.random(); - if (r < 0.25) { - word = `(${word})`; - } else if (r < 0.5) { - word = `{${word}}`; - } else if (r < 0.75) { - word = `[${word}]`; - } else { - word = `<${word}>`; - } - } else { - word = `(${word})`; - } - } else if (Math.random() < 0.013) { - if (Config.language.split("_")[0] == "french") { - word = ":"; - } else { - word += ":"; - } - } else if ( - Math.random() < 0.014 && - Misc.getLastChar(previousWord) != "," && - Misc.getLastChar(previousWord) != "." && - previousWord != "-" - ) { - word = "-"; - } else if ( - Math.random() < 0.015 && - Misc.getLastChar(previousWord) != "," && - Misc.getLastChar(previousWord) != "." && - Misc.getLastChar(previousWord) != ";" - ) { - if (Config.language.split("_")[0] == "french") { - word = ";"; - } else { - word += ";"; - } - } else if (Math.random() < 0.2 && Misc.getLastChar(previousWord) != ",") { - word += ","; - } else if (Math.random() < 0.25 && Config.language.split("_")[0] == "code") { - let specials = ["{", "}", "[", "]", "(", ")", ";", "=", "%", "/"]; - - word = specials[Math.floor(Math.random() * 10)]; - } - return word; -} - export function restart(withSameWordset = false, nosave = false, event) { if (TestUI.testRestarting || TestUI.resultCalculating) { try { diff --git a/src/js/test/test-stats.js b/src/js/test/test-stats.js index 311cc913e..dc0ac2127 100644 --- a/src/js/test/test-stats.js +++ b/src/js/test/test-stats.js @@ -1,5 +1,5 @@ import * as TestLogic from "./test-logic"; -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import * as Funbox from "./funbox"; import * as Misc from "./misc"; import * as TestStats from "./test-stats"; @@ -182,6 +182,10 @@ export function pushKeypressSpacing(val) { keypressTimings.spacing.array.push(val); } +export function setKeypressSpacing(val) { + keypressTimings.spacing.current = val; +} + export function recordKeypressSpacing() { let now = performance.now(); let diff = Math.abs(keypressTimings.spacing.current - now); @@ -191,10 +195,6 @@ export function recordKeypressSpacing() { setKeypressSpacing(now); } -export function setKeypressSpacing(val) { - keypressTimings.spacing.current = val; -} - export function resetKeypressTimings() { keypressTimings = { spacing: { diff --git a/src/js/test/test-timer.js b/src/js/test/test-timer.js index 1c4111f52..03eaebd49 100644 --- a/src/js/test/test-timer.js +++ b/src/js/test/test-timer.js @@ -10,7 +10,6 @@ import * as Funbox from "./funbox"; import * as TestLogic from "./test-logic"; import * as Caret from "./caret"; import * as Keymap from "./keymap"; -import * as TestUI from "./test-ui"; export let time = 0; let timer = null; diff --git a/src/js/test/test-ui.js b/src/js/test/test-ui.js index 8b25115cb..088929dec 100644 --- a/src/js/test/test-ui.js +++ b/src/js/test/test-ui.js @@ -42,6 +42,33 @@ export function reset() { currentWordElementIndex = 0; } +export function updateActiveElement(backspace) { + let active = document.querySelector("#words .active"); + if (Config.mode == "zen" && backspace) { + active.remove(); + } else if (active !== null) { + if (Config.highlightMode == "word") { + active.querySelectorAll("letter").forEach((e) => { + e.classList.remove("correct"); + }); + } + active.classList.remove("active"); + } + try { + let activeWord = document.querySelectorAll("#words .word")[ + currentWordElementIndex + ]; + activeWord.classList.add("active"); + activeWord.classList.remove("error"); + activeWordTop = document.querySelector("#words .active").offsetTop; + if (Config.highlightMode == "word") { + activeWord.querySelectorAll("letter").forEach((e) => { + e.classList.add("correct"); + }); + } + } catch (e) {} +} + export function showWords() { $("#words").empty(); @@ -122,33 +149,6 @@ export function showWords() { Caret.updatePosition(); } -export function updateActiveElement(backspace) { - let active = document.querySelector("#words .active"); - if (Config.mode == "zen" && backspace) { - active.remove(); - } else if (active !== null) { - if (Config.highlightMode == "word") { - active.querySelectorAll("letter").forEach((e) => { - e.classList.remove("correct"); - }); - } - active.classList.remove("active"); - } - try { - let activeWord = document.querySelectorAll("#words .word")[ - currentWordElementIndex - ]; - activeWord.classList.add("active"); - activeWord.classList.remove("error"); - activeWordTop = document.querySelector("#words .active").offsetTop; - if (Config.highlightMode == "word") { - activeWord.querySelectorAll("letter").forEach((e) => { - e.classList.add("correct"); - }); - } - } catch (e) {} -} - export function flipColors(tf) { if (tf) { $("#words").addClass("flipped"); diff --git a/src/js/test/timer-progress.js b/src/js/test/timer-progress.js index 48d723925..11b2f0872 100644 --- a/src/js/test/timer-progress.js +++ b/src/js/test/timer-progress.js @@ -1,4 +1,4 @@ -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import * as CustomText from "./custom-text"; import * as Misc from "./misc"; import * as TestLogic from "./test-logic"; diff --git a/src/js/theme-controller.js b/src/js/theme-controller.js index b555b9828..551fdfb38 100644 --- a/src/js/theme-controller.js +++ b/src/js/theme-controller.js @@ -2,7 +2,7 @@ import * as ThemeColors from "./theme-colors"; import * as ChartController from "./chart-controller"; import * as Misc from "./misc"; import * as Notifications from "./notification-center"; -import Config, * as UpdateConfig from "./config"; +import Config from "./config"; import { swapElements } from "./dom-util"; let isPreviewingTheme = false; @@ -32,6 +32,47 @@ export const colorVars = [ "--colorful-error-extra-color", ]; +function updateFavicon(size, curveSize) { + let maincolor, bgcolor; + + bgcolor = ThemeColors.bg; + maincolor = ThemeColors.main; + + if (bgcolor == maincolor) { + bgcolor = "#111"; + maincolor = "#eee"; + } + + var canvas = document.createElement("canvas"); + canvas.width = size; + canvas.height = size; + let ctx = canvas.getContext("2d"); + ctx.beginPath(); + ctx.moveTo(0, curveSize); + //top left + ctx.quadraticCurveTo(0, 0, curveSize, 0); + ctx.lineTo(size - curveSize, 0); + //top right + ctx.quadraticCurveTo(size, 0, size, curveSize); + ctx.lineTo(size, size - curveSize); + ctx.quadraticCurveTo(size, size, size - curveSize, size); + ctx.lineTo(curveSize, size); + ctx.quadraticCurveTo(0, size, 0, size - curveSize); + ctx.fillStyle = bgcolor; + ctx.fill(); + ctx.font = "900 " + (size / 2) * 1.2 + "px Roboto Mono"; + ctx.textAlign = "center"; + ctx.fillStyle = maincolor; + ctx.fillText("mt", size / 2 + size / 32, (size / 3) * 2.1); + $("#favicon").attr("href", canvas.toDataURL("image/png")); +} + +function clearCustomTheme() { + colorVars.forEach((e) => { + document.documentElement.style.setProperty(e, ""); + }); +} + export function apply(themeName) { clearCustomTheme(); @@ -117,44 +158,3 @@ export function randomiseTheme() { export function clearRandom() { randomTheme = null; } - -function updateFavicon(size, curveSize) { - let maincolor, bgcolor; - - bgcolor = ThemeColors.bg; - maincolor = ThemeColors.main; - - if (bgcolor == maincolor) { - bgcolor = "#111"; - maincolor = "#eee"; - } - - var canvas = document.createElement("canvas"); - canvas.width = size; - canvas.height = size; - let ctx = canvas.getContext("2d"); - ctx.beginPath(); - ctx.moveTo(0, curveSize); - //top left - ctx.quadraticCurveTo(0, 0, curveSize, 0); - ctx.lineTo(size - curveSize, 0); - //top right - ctx.quadraticCurveTo(size, 0, size, curveSize); - ctx.lineTo(size, size - curveSize); - ctx.quadraticCurveTo(size, size, size - curveSize, size); - ctx.lineTo(curveSize, size); - ctx.quadraticCurveTo(0, size, 0, size - curveSize); - ctx.fillStyle = bgcolor; - ctx.fill(); - ctx.font = "900 " + (size / 2) * 1.2 + "px Roboto Mono"; - ctx.textAlign = "center"; - ctx.fillStyle = maincolor; - ctx.fillText("mt", size / 2 + size / 32, (size / 3) * 2.1); - $("#favicon").attr("href", canvas.toDataURL("image/png")); -} - -function clearCustomTheme() { - colorVars.forEach((e) => { - document.documentElement.style.setProperty(e, ""); - }); -} From d0f8ea3d82795e1e66f002ed5e53cc2e1fe7e2f9 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 26 Mar 2021 00:27:01 +0000 Subject: [PATCH 2/6] removed unnecessary code --- src/js/config.js | 1 - src/js/theme-controller.js | 27 ++++++--------------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/js/config.js b/src/js/config.js index ce9494719..a2859184b 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -1182,7 +1182,6 @@ export function toggleCustomTheme(nosave) { export function setCustomThemeColors(colors, nosave) { if (colors !== undefined) { config.customThemeColors = colors; - ThemeController.setCustomColors(colors); // ThemeController.set("custom"); // applyCustomThemeColors(); } diff --git a/src/js/theme-controller.js b/src/js/theme-controller.js index 551fdfb38..a4ba84304 100644 --- a/src/js/theme-controller.js +++ b/src/js/theme-controller.js @@ -7,19 +7,7 @@ import { swapElements } from "./dom-util"; let isPreviewingTheme = false; let randomTheme = null; -//TODO remove current theme and customcolors once config is a module -let currentTheme = "serika_dark"; -let customColors = [ - "#323437", - "#e2b714", - "#e2b714", - "#646669", - "#d1d0c5", - "#ca4754", - "#7e2a33", - "#ca4754", - "#7e2a33", -]; + export const colorVars = [ "--bg-color", "--main-color", @@ -99,7 +87,10 @@ export function apply(themeName) { if (themeName === "custom") { colorVars.forEach((e, index) => { - document.documentElement.style.setProperty(e, customColors[index]); + document.documentElement.style.setProperty( + e, + Config.customThemeColors[index] + ); }); } @@ -124,22 +115,16 @@ export function preview(themeName) { } export function set(themeName) { - currentTheme = themeName; apply(themeName); } export function clearPreview() { if (isPreviewingTheme) { isPreviewingTheme = false; - apply(currentTheme); + apply(Config.theme); } } -export function setCustomColors(colors) { - customColors = colors; -} - -//TODO remove config once config is a module export function randomiseTheme() { var randomList; Misc.getThemesList().then((themes) => { From aec4959d5b6ad2e7c3de84159d4d9903ea2de1bf Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 26 Mar 2021 00:31:03 +0000 Subject: [PATCH 3/6] fixed some todo's --- src/js/test/caret.js | 3 --- src/js/test/keymap.js | 7 +++---- src/js/test/live-acc.js | 3 ++- src/js/test/live-wpm.js | 3 ++- src/js/test/timer-progress.js | 5 +++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/js/test/caret.js b/src/js/test/caret.js index 3f523cd20..7ab152dc4 100644 --- a/src/js/test/caret.js +++ b/src/js/test/caret.js @@ -12,7 +12,6 @@ export function stopAnimation() { } } -//TODO remove config when module export function startAnimation() { if (caretAnimating === false) { if (Config.smoothCaret) { @@ -28,8 +27,6 @@ export function hide() { $("#caret").addClass("hidden"); } -//TODO remove this after test logic is a module -//TODO remove config when module export function updatePosition() { if ($("#wordsWrapper").hasClass("hidden")) return; if ($("#caret").hasClass("off")) { diff --git a/src/js/test/keymap.js b/src/js/test/keymap.js index 98146f49e..94036e40e 100644 --- a/src/js/test/keymap.js +++ b/src/js/test/keymap.js @@ -1,4 +1,4 @@ -import Config from "./config"; +import Config, * as UpdateConfig from "./config"; import * as ThemeColors from "./theme-colors"; import layouts from "./layouts"; @@ -152,8 +152,7 @@ export function show() { $(".keymap").removeClass("hidden"); } -//TODO remove setkeymaplayout after userconfig is a module -export function refreshKeys(layout, setKeymapLayout) { +export function refreshKeys(layout) { try { let lts = layouts[layout]; //layout to show let layoutString = layout; @@ -240,6 +239,6 @@ export function refreshKeys(layout, setKeymapLayout) { console.log( "something went wrong when changing layout, resettings: " + e.message ); - setKeymapLayout("qwerty", true); + UpdateConfig.setKeymapLayout("qwerty", true); } } diff --git a/src/js/test/live-acc.js b/src/js/test/live-acc.js index 23c144bf4..5c8e18cc7 100644 --- a/src/js/test/live-acc.js +++ b/src/js/test/live-acc.js @@ -1,4 +1,5 @@ import Config from "./config"; +import * as TestLogic from "./test-logic"; export function update(acc) { let number = Math.floor(acc); @@ -11,7 +12,7 @@ export function update(acc) { export function show() { if (!Config.showLiveAcc) return; - // if (!TestLogic.active) return; + if (!TestLogic.active) return; if (Config.timerStyle === "mini") { // $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity); if (!$("#miniTimerAndLiveWpm .acc").hasClass("hidden")) return; diff --git a/src/js/test/live-wpm.js b/src/js/test/live-wpm.js index 2cedad0cc..b7cf8054f 100644 --- a/src/js/test/live-wpm.js +++ b/src/js/test/live-wpm.js @@ -1,4 +1,5 @@ import Config from "./config"; +import * as TestLogic from "./test-logic"; export function update(wpm, raw) { // if (!TestLogic.active || !Config.showLiveWpm) { @@ -17,9 +18,9 @@ export function update(wpm, raw) { document.querySelector("#liveWpm").innerHTML = number; } -//TODO needs to check if test is active export function show() { if (!Config.showLiveWpm) return; + if (!TestLogic.active) return; if (Config.timerStyle === "mini") { // $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity); if (!$("#miniTimerAndLiveWpm .wpm").hasClass("hidden")) return; diff --git a/src/js/test/timer-progress.js b/src/js/test/timer-progress.js index 11b2f0872..08eed76ef 100644 --- a/src/js/test/timer-progress.js +++ b/src/js/test/timer-progress.js @@ -2,6 +2,7 @@ import Config from "./config"; import * as CustomText from "./custom-text"; import * as Misc from "./misc"; import * as TestLogic from "./test-logic"; +import * as TestTimer from "./test-timer"; export function show() { let op = Config.showTimerProgress ? Config.timerOpacity : 0; @@ -84,8 +85,8 @@ export function restart() { } } -//TODO remove the parameters once they are inside a module -export function update(time) { +export function update() { + let time = TestTimer.time; if ( Config.mode === "time" || (Config.mode === "custom" && CustomText.isTimeRandom) From 67fb123d8f1bad72a7b5cb35c1713307d28d95c1 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 26 Mar 2021 00:37:37 +0000 Subject: [PATCH 4/6] fixed warning --- src/js/test/pace-caret.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/js/test/pace-caret.js b/src/js/test/pace-caret.js index 7b0422e7f..6994c92ca 100644 --- a/src/js/test/pace-caret.js +++ b/src/js/test/pace-caret.js @@ -157,14 +157,13 @@ export function update(expectedStepEnd) { let newIndex = settings.currentWordIndex - (TestLogic.words.currentIndex - TestUI.currentWordElementIndex); + let word = document.querySelectorAll("#words .word")[newIndex]; if (settings.currentLetterIndex === -1) { - currentLetter = document - .querySelectorAll("#words .word") - [newIndex].querySelectorAll("letter")[0]; + currentLetter = word.querySelectorAll("letter")[0]; } else { - currentLetter = document - .querySelectorAll("#words .word") - [newIndex].querySelectorAll("letter")[settings.currentLetterIndex]; + currentLetter = word.querySelectorAll("letter")[ + settings.currentLetterIndex + ]; } newTop = currentLetter.offsetTop - $(currentLetter).height() / 5; newLeft; From 69b2242c96a4277b7db5cab8ce635c3c06ab608e Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 26 Mar 2021 01:48:51 +0000 Subject: [PATCH 5/6] Revert "Merge branch 'master' of https://github.com/smithster/monkeytype" This reverts commit 83cf30362dc08eb700a598e0c3ec42515f7743d2, reversing changes made to 67fb123d8f1bad72a7b5cb35c1713307d28d95c1. --- gulpfile.js | 1 - src/js/custom-text-popup.js | 7 +-- src/js/exports.js | 2 - src/js/global-dependencies.js | 1 - src/js/script.js | 3 +- src/js/word-filter.js | 81 ---------------------------------- src/sass/style.scss | 82 ----------------------------------- static/index.html | 24 ---------- 8 files changed, 2 insertions(+), 199 deletions(-) delete mode 100644 src/js/word-filter.js diff --git a/gulpfile.js b/gulpfile.js index 77431062b..fe048a49d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -104,7 +104,6 @@ const refactoredSrc = [ "./src/js/chart-controller.js", "./src/js/theme-controller.js", "./src/js/test/caret.js", - "./src/js/word-filter.js", "./src/js/custom-text-popup.js", "./src/js/manual-restart-tracker.js", "./src/js/config.js", diff --git a/src/js/custom-text-popup.js b/src/js/custom-text-popup.js index 0b4ea962c..02a89098f 100644 --- a/src/js/custom-text-popup.js +++ b/src/js/custom-text-popup.js @@ -2,7 +2,6 @@ import * as CustomText from "./custom-text"; import * as ManualRestart from "./manual-restart-tracker"; import * as Misc from "./misc"; import * as Notifications from "./notification-center"; -import * as WordFilter from "./word-filter"; import * as TestLogic from "./test-logic"; let wrapper = "#customTextPopupWrapper"; @@ -82,7 +81,7 @@ $(`${popup} .randomInputFields .time input`).keypress((e) => { $(`${popup} .randomInputFields .wordcount input`).val(""); }); -$("#customTextPopup .apply").click(() => { +$("#customTextPopup .button").click(() => { let text = $("#customTextPopup textarea").val(); text = text.trim(); // text = text.replace(/[\r]/gm, " "); @@ -155,7 +154,3 @@ $("#customTextPopup .apply").click(() => { TestLogic.restart(); hide(); }); - -$("#customTextPopup .wordfilter").click(() => { - WordFilter.showWordFilterPopup(); -}) \ No newline at end of file diff --git a/src/js/exports.js b/src/js/exports.js index 22286defe..c3dc504c0 100644 --- a/src/js/exports.js +++ b/src/js/exports.js @@ -10,5 +10,3 @@ global.snapshot = DB.getSnapshot; global.config = Config; // global.addnotif = Notifications.add; global.link = linkWithGoogle; - -global.wordFilter = WordFilter; \ No newline at end of file diff --git a/src/js/global-dependencies.js b/src/js/global-dependencies.js index 8a15db298..f0074f490 100644 --- a/src/js/global-dependencies.js +++ b/src/js/global-dependencies.js @@ -30,7 +30,6 @@ import * as OutOfFocus from "./out-of-focus"; import * as ChartController from "./chart-controller"; import * as ThemeController from "./theme-controller"; import * as Caret from "./caret"; -import * as WordFilter from "./word-filter"; import * as CustomTextPopup from "./custom-text-popup"; import * as ManualRestart from "./manual-restart-tracker"; import Config, * as UpdateConfig from "./config"; diff --git a/src/js/script.js b/src/js/script.js index 71761dce8..cae5fa375 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -813,8 +813,7 @@ $(document).keydown(function (event) { let modePopupVisible = !$("#customTextPopupWrapper").hasClass("hidden") || !$("#customMode2PopupWrapper").hasClass("hidden") || - !$("#quoteSearchPopupWrapper").hasClass("hidden") || - !$("#wordFilterPopupWrapper").hasClass("hidden"); + !$("#quoteSearchPopupWrapper").hasClass("hidden"); if ( pageTestActive && !commandLineVisible && diff --git a/src/js/word-filter.js b/src/js/word-filter.js deleted file mode 100644 index ced7eac18..000000000 --- a/src/js/word-filter.js +++ /dev/null @@ -1,81 +0,0 @@ -import { setCustomThemeColors } from "./config"; -import * as Misc from "./misc"; -import * as ThemeColors from "./theme-colors"; -//import * as config from "./userconfig"; - -export async function showWordFilterPopup(){ - - $("#wordFilterPopupWrapper").removeClass("hidden"); - $("#customTextPopupWrapper").addClass("hidden"); - let LanguageList = await Misc.getLanguageList(); - LanguageList.forEach(language => { - let prettyLang = language; - prettyLang = prettyLang.replace("_", " "); - $("#languageList").append(` - - `) - }) - $("#languageList").select2({ - minimumResultsForSearch: -1, - }); -} - -function hideWordFilterPopup(){ - $("#wordFilterPopupWrapper").addClass("hidden"); - $("#customTextPopupWrapper").removeClass("hidden"); -} - -async function applyWordFilterPopup(){ - let language = $("#languageList").val(); - let filteredWords = await filter(language); - let customText = ""; - filteredWords.forEach( word => { - customText += (word + " "); - }) - hideWordFilterPopup(); - $("#customTextPopup textarea").val(customText); -} - -$("#wordFilterPopupWrapper").mousedown((e) => { - if ($(e.target).attr("id") === "wordFilterPopupWrapper") { - hideWordFilterPopup(); - } -}); - -$("#wordFilterPopupWrapper .button").mousedown((e) => { - $("#wordFilterPopupWrapper .wfload").removeClass("hidden"); - $("#wordFilterPopupWrapper .button").addClass("hidden"); - setTimeout(() => { - applyWordFilterPopup(); - $("#wordFilterPopupWrapper .wfload").addClass("hidden"); - $("#wordFilterPopupWrapper .button").removeClass("hidden"); - }, 1) -}); - -async function filter(language){ - let filterin = $("#wordFilter").val(); - filterin = filterin.replace(/ /gi, "|"); - let regincl = new RegExp(filterin, "i"); - let filterout = $("#wordExclude").val(); - filterout = filterout.replace(/ /gi, "|"); - let regexcl = new RegExp(filterout, "i"); - let filteredWords = []; - let languageWordList = await Misc.getLanguage(language); - let maxLength = $("#wordMax").val(); - let minLength = $("#wordMin").val(); - if(maxLength == ""){ - maxLength = 999; - } - if(minLength == ""){ - minLength = 1; - } - for( let i = 0; i < languageWordList.words.length; i++){ - let word = languageWordList.words[i]; - let test1 = regincl.test(word); - let test2 = regexcl.test(word); - if((test1 && !test2 || test1 && filterout == "") && word.length <= maxLength && word.length >= minLength){ - filteredWords.push(word); - } - } - return filteredWords; -} \ No newline at end of file diff --git a/src/sass/style.scss b/src/sass/style.scss index 1109b2499..088e1958e 100644 --- a/src/sass/style.scss +++ b/src/sass/style.scss @@ -414,11 +414,6 @@ a:hover { gap: 1rem; width: 60vw; - .wordfilter{ - width: 33%; - justify-self:right; - } - textarea { background: var(--bg-color); padding: 1rem; @@ -432,8 +427,6 @@ a:hover { resize: vertical; height: 200px; color: var(--text-color); - overflow-x: hidden; - overflow-y: scroll; } .inputs { @@ -519,81 +512,6 @@ a:hover { } } -#wordFilterPopupWrapper{ - width: 100%; - height: 100%; - background: rgba(0, 0, 0, 0.75); - position: fixed; - left: 0; - top: 0; - z-index: 1000; - display: grid; - justify-content: center; - align-items: center; - padding: 5rem 0; - - #wordFilterPopup{ - background: var(--bg-color); - border-radius: var(--roundness); - padding: 2rem; - display: grid; - gap: 1rem; - width: 400px; - - .lengthgrid{ - display:grid; - grid-template-columns: 1fr 1fr; - grid-template-rows: 1fr 1fr; - gap: 0.2rem; - } - - .wordLength{ - width: 10rem; - } - - #languageList{ - background: rgba(0, 0, 0, 0.1); - height: fit-content; - padding: 5px; - border-radius: 5px; - color: var(--text-color); - font: var(--font); - border: none; - - - option{ - background: var(--bg-color); - } - } - #languageList:focus{ - height: fit-content; - padding: 5px; - border-radius: 5px; - color: var(--text-color); - font: var(--font); - border: none; - outline: none; - } - #languageList:active{ - height: fit-content; - padding: 5px; - border-radius: 5px; - color: var(--text-color); - font: var(--font); - border: none; - outline: none; - } - .wftip{ - color: var(--sub-color); - font-size: 0.8rem; - } - - .wfload{ - justify-self: center; - } - } -} - #simplePopupWrapper { width: 100%; height: 100%; diff --git a/static/index.html b/static/index.html index a4571c513..be7da9eb4 100644 --- a/static/index.html +++ b/static/index.html @@ -5,7 +5,6 @@ Monkeytype - @@ -103,7 +102,6 @@ - @@ -3777,6 +3754,5 @@ - From 083b37d0da7cabbcf1ea0b107efda4e98f89731d Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 26 Mar 2021 01:53:55 +0000 Subject: [PATCH 6/6] fixed error on changing theme --- src/js/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/settings.js b/src/js/settings.js index 4ee7911cc..5718cafed 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -834,7 +834,7 @@ $(document).on("click", ".pageSettings .section.themes .theme.button", (e) => { let theme = $(e.currentTarget).attr("theme"); if (!$(e.target).hasClass("favButton")) { UpdateConfig.setTheme(theme); - UpdateConfig.setActiveThemeButton(); + setActiveThemeButton(); refreshThemeButtons(); } });