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/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..a2859184b 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); @@ -1135,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(); } @@ -1192,26 +1238,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 +1278,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 +1337,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 +1597,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/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/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/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/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 29ef78b5f..4a0570912 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/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/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..7ab152dc4 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; @@ -12,7 +12,6 @@ export function stopAnimation() { } } -//TODO remove config when module export function startAnimation() { if (caretAnimating === false) { if (Config.smoothCaret) { @@ -28,16 +27,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() { if ($("#wordsWrapper").hasClass("hidden")) return; if ($("#caret").hasClass("off")) { @@ -128,3 +117,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..94036e40e 100644 --- a/src/js/test/keymap.js +++ b/src/js/test/keymap.js @@ -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 e3cf1eecd..5c8e18cc7 100644 --- a/src/js/test/live-acc.js +++ b/src/js/test/live-acc.js @@ -1,4 +1,5 @@ -import Config, * as UpdateConfig from "./config"; +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 07b6591c2..b7cf8054f 100644 --- a/src/js/test/live-wpm.js +++ b/src/js/test/live-wpm.js @@ -1,4 +1,5 @@ -import Config, * as UpdateConfig from "./config"; +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/pace-caret.js b/src/js/test/pace-caret.js index 28224840f..6994c92ca 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() { @@ -139,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; @@ -202,28 +219,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 +245,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..08eed76ef 100644 --- a/src/js/test/timer-progress.js +++ b/src/js/test/timer-progress.js @@ -1,7 +1,8 @@ -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"; +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) diff --git a/src/js/theme-controller.js b/src/js/theme-controller.js index b555b9828..a4ba84304 100644 --- a/src/js/theme-controller.js +++ b/src/js/theme-controller.js @@ -2,24 +2,12 @@ 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; 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", @@ -32,92 +20,6 @@ export const colorVars = [ "--colorful-error-extra-color", ]; -export function apply(themeName) { - clearCustomTheme(); - - let name = "serika_dark"; - if (themeName !== "custom") { - name = themeName; - swapElements( - $('.pageSettings [tabContent="custom"]'), - $('.pageSettings [tabContent="preset"]'), - 250 - ); - } else { - //is custom - swapElements( - $('.pageSettings [tabContent="preset"]'), - $('.pageSettings [tabContent="custom"]'), - 250 - ); - } - - $(".keymap-key").attr("style", ""); - $("#currentTheme").attr("href", `themes/${name}.css`); - $(".current-theme").text(themeName.replace("_", " ")); - - if (themeName === "custom") { - colorVars.forEach((e, index) => { - document.documentElement.style.setProperty(e, customColors[index]); - }); - } - - try { - firebase.analytics().logEvent("changedTheme", { - theme: themeName, - }); - } catch (e) { - console.log("Analytics unavailable"); - } - setTimeout(() => { - $(".keymap-key").attr("style", ""); - ChartController.updateAllChartColors(); - updateFavicon(32, 14); - $("#metaThemeColor").attr("content", ThemeColors.main); - }, 500); -} - -export function preview(themeName) { - isPreviewingTheme = true; - apply(themeName); -} - -export function set(themeName) { - currentTheme = themeName; - apply(themeName); -} - -export function clearPreview() { - if (isPreviewingTheme) { - isPreviewingTheme = false; - apply(currentTheme); - } -} - -export function setCustomColors(colors) { - customColors = colors; -} - -//TODO remove config once config is a module -export function randomiseTheme() { - var randomList; - Misc.getThemesList().then((themes) => { - randomList = themes.map((t) => { - return t.name; - }); - - if (Config.randomTheme === "fav" && Config.favThemes.length > 0) - randomList = Config.favThemes; - randomTheme = randomList[Math.floor(Math.random() * randomList.length)]; - preview(randomTheme); - Notifications.add(randomTheme.replace(/_/g, " "), 0); - }); -} - -export function clearRandom() { - randomTheme = null; -} - function updateFavicon(size, curveSize) { let maincolor, bgcolor; @@ -158,3 +60,86 @@ function clearCustomTheme() { document.documentElement.style.setProperty(e, ""); }); } + +export function apply(themeName) { + clearCustomTheme(); + + let name = "serika_dark"; + if (themeName !== "custom") { + name = themeName; + swapElements( + $('.pageSettings [tabContent="custom"]'), + $('.pageSettings [tabContent="preset"]'), + 250 + ); + } else { + //is custom + swapElements( + $('.pageSettings [tabContent="preset"]'), + $('.pageSettings [tabContent="custom"]'), + 250 + ); + } + + $(".keymap-key").attr("style", ""); + $("#currentTheme").attr("href", `themes/${name}.css`); + $(".current-theme").text(themeName.replace("_", " ")); + + if (themeName === "custom") { + colorVars.forEach((e, index) => { + document.documentElement.style.setProperty( + e, + Config.customThemeColors[index] + ); + }); + } + + try { + firebase.analytics().logEvent("changedTheme", { + theme: themeName, + }); + } catch (e) { + console.log("Analytics unavailable"); + } + setTimeout(() => { + $(".keymap-key").attr("style", ""); + ChartController.updateAllChartColors(); + updateFavicon(32, 14); + $("#metaThemeColor").attr("content", ThemeColors.main); + }, 500); +} + +export function preview(themeName) { + isPreviewingTheme = true; + apply(themeName); +} + +export function set(themeName) { + apply(themeName); +} + +export function clearPreview() { + if (isPreviewingTheme) { + isPreviewingTheme = false; + apply(Config.theme); + } +} + +export function randomiseTheme() { + var randomList; + Misc.getThemesList().then((themes) => { + randomList = themes.map((t) => { + return t.name; + }); + + if (Config.randomTheme === "fav" && Config.favThemes.length > 0) + randomList = Config.favThemes; + randomTheme = randomList[Math.floor(Math.random() * randomList.length)]; + preview(randomTheme); + Notifications.add(randomTheme.replace(/_/g, " "), 0); + }); +} + +export function clearRandom() { + randomTheme = null; +} diff --git a/src/sass/style.scss b/src/sass/style.scss index beb3baaea..e5612617f 100644 --- a/src/sass/style.scss +++ b/src/sass/style.scss @@ -493,11 +493,6 @@ a:hover { gap: 1rem; width: 60vw; - .wordfilter{ - width: 33%; - justify-self:right; - } - textarea { background: var(--bg-color); padding: 1rem; @@ -511,8 +506,6 @@ a:hover { resize: vertical; height: 200px; color: var(--text-color); - overflow-x: hidden; - overflow-y: scroll; } .inputs { 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 @@ -