let defaultConfig = { theme: "serika_dark", customTheme: false, customThemeColors: [ "#323437", "#e2b714", "#e2b714", "#646669", "#d1d0c5", "#ca4754", "#7e2a33", "#ca4754", "#7e2a33", ], showKeyTips: true, showLiveWpm: false, showTimerBar: true, smoothCaret: true, quickTab: false, punctuation: false, words: 50, time: 60, mode: "time", language: "english", fontSize: 1, freedomMode: false, resultFilters: ["all"], difficulty: "normal", blindMode: false, quickEnd: false, caretStyle: "default", flipTestColors: false, layout: "default", showDiscordDot: true, maxConfidence: false, timerStyle: "bar", colorfulMode: true, randomTheme: false, timerColor: "black", timerOpacity: "0.25", stopOnError: false, showAllLines: false, }; let cookieConfig = null; let config = { ...defaultConfig, }; //cookies function saveConfigToCookie() { // showNotification('saving to cookie',1000); if (config.freedomMode === null) config.freedomMode = false; let d = new Date(); d.setFullYear(d.getFullYear() + 1); $.cookie("config", null); $.cookie("config", JSON.stringify(config), { expires: d, path: "/", }); restartCount = 0; saveConfigToDB(); } function saveConfigToDB() { if (firebase.auth().currentUser !== null) { // showNotification('saving to db',1000); accountIconLoading(true); saveConfig({ uid: firebase.auth().currentUser.uid, obj: config }).then( (d) => { accountIconLoading(false); if (d.data === 1) { // showNotification('config saved to db',1000); } else { showNotification("Error saving config to DB!", 4000); } } ); } } function saveActiveTagsToCookie() { let tags = []; try { dbSnapshot.tags.forEach((tag) => { if (tag.active === true) { tags.push(tag.id); } }); let d = new Date(); d.setFullYear(d.getFullYear() + 1); $.cookie("activeTags", null); $.cookie("activeTags", JSON.stringify(tags), { expires: d, path: "/", }); } catch (e) {} } function loadConfigFromCookie() { let newConfig = $.cookie("config"); if (newConfig !== undefined) { newConfig = JSON.parse(newConfig); applyConfig(newConfig); cookieConfig = newConfig; saveConfigToCookie(); } } function applyConfig(configObj) { if (configObj && configObj != null && configObj != "null") { setTheme(configObj.theme, true); setCustomTheme(configObj.customTheme, true); setCustomThemeColors(configObj.customThemeColors, true); setQuickTabMode(configObj.quickTab, true); setPunctuation(configObj.punctuation, true); setKeyTips(configObj.showKeyTips, true); changeTimeConfig(configObj.time, true); changeWordCount(configObj.words, true); changeMode(configObj.mode, true); changeLanguage(configObj.language, true); changeLayout(configObj.layout, true); changeFontSize(configObj.fontSize, true); setFreedomMode(configObj.freedomMode, true); setCaretStyle(configObj.caretStyle, true); setDifficulty(configObj.difficulty, true); setBlindMode(configObj.blindMode, true); setQuickEnd(configObj.quickEnd, true); setFlipTestColors(configObj.flipTestColors, true); setDiscordDot(configObj.hideDiscordDot, true); setColorfulMode(configObj.colorfulMode, true); setMaxConfidence(configObj.maxConfidence, true); setTimerStyle(configObj.timerStyle, true); setTimerColor(configObj.timerColor, true); setTimerOpacity(configObj.timerOpacity, true); if ( configObj.resultFilters == null || configObj.resultFilters == undefined ) { configObj.resultFilters = ["all"]; } config = configObj; } Object.keys(defaultConfig).forEach((configKey) => { if (config[configKey] == undefined) { config[configKey] = defaultConfig[configKey]; } }); } function loadActiveTagsFromCookie() { let newTags = $.cookie("activeTags"); if (newTags !== undefined) { newTags = JSON.parse(newTags); newTags.forEach((ntag) => { toggleTag(ntag, true); }); saveActiveTagsToCookie(); } } function showTestConfig() { $("#top .config").removeClass("hidden").css("opacity", 1); } function hideTestConfig() { $("#top .config").css("opacity", 0).addClass("hidden"); } //difficulty function setDifficulty(diff, nosave) { if ( (diff !== "normal" && diff !== "expert" && diff !== "master") || diff == undefined ) { diff = "normal"; } config.difficulty = diff; restartTest(); updateTestModesNotice(); if (!nosave) saveConfigToCookie(); } //blind mode function toggleDiscordDot() { dot = !config.showDiscordDot; if (dot == undefined) { dot = false; } config.showDiscordDot = dot; if (!dot) { $("#menu .discord").addClass("dotHidden"); } else { $("#menu .discord").removeClass("dotHidden"); } saveConfigToCookie(); } function setDiscordDot(dot, nosave) { if (dot == undefined) { dot = false; } config.showDiscordDot = dot; if (!dot) { $("#menu .discord").addClass("dotHidden"); } else { $("#menu .discord").removeClass("dotHidden"); } if (!nosave) saveConfigToCookie(); } //blind mode function toggleBlindMode() { blind = !config.blindMode; if (blind == undefined) { blind = false; } config.blindMode = blind; updateTestModesNotice(); saveConfigToCookie(); } function setBlindMode(blind, nosave) { if (blind == undefined) { blind = false; } config.blindMode = blind; updateTestModesNotice(); if (!nosave) saveConfigToCookie(); } //stoponerror function toggleStopOnError() { soe = !config.stopOnError; if (soe == undefined) { soe = false; } config.stopOnError = soe; saveConfigToCookie(); } function setStopOnError(soe, nosave) { if (soe == undefined) { soe = false; } config.stopOnError = soe; if (!nosave) saveConfigToCookie(); } //show all lines function toggleShowAllLines() { sal = !config.showAllLines; if (sal == undefined) { sal = false; } config.showAllLines = sal; restartTest(); saveConfigToCookie(); } function setShowAllLines(sal, nosave) { if (sal == undefined) { sal = false; } config.showAllLines = sal; restartTest(); if (!nosave) saveConfigToCookie(); } //quickend function toggleQuickEnd() { qe = !config.quickEnd; if (qe == undefined) { qe = false; } config.quickEnd = qe; saveConfigToCookie(); } function setQuickEnd(qe, nosave) { if (qe == undefined) { qe = false; } config.quickEnd = qe; if (!nosave) saveConfigToCookie(); } //flip colors function setFlipTestColors(flip, nosave) { if (flip == undefined) { flip = false; } config.flipTestColors = flip; flipTestColors(flip); if (!nosave) saveConfigToCookie(); } function toggleFlipTestColors() { config.flipTestColors = !config.flipTestColors; flipTestColors(config.flipTestColors); saveConfigToCookie(); } //extra color function setColorfulMode(extra, nosave) { if (extra == undefined) { extra = false; } config.colorfulMode = extra; applyColorfulMode(extra); if (!nosave) saveConfigToCookie(); } function toggleColorfulMode() { config.colorfulMode = !config.colorfulMode; applyColorfulMode(config.colorfulMode); saveConfigToCookie(); } function setCaretStyle(caretStyle, nosave) { if (caretStyle == null || caretStyle == undefined) { caretStyle = "default"; } config.caretStyle = caretStyle; $("#caret").removeClass("default"); $("#caret").removeClass("underline"); $("#caret").removeClass("outline"); $("#caret").removeClass("block"); if (caretStyle == "default") { $("#caret").addClass("default"); } else if (caretStyle == "block") { $("#caret").addClass("block"); } else if (caretStyle == "outline") { $("#caret").addClass("outline"); } else if (caretStyle == "underline") { $("#caret").addClass("underline"); } if (!nosave) saveConfigToCookie(); } function setTimerStyle(style, nosave) { if (style == null || style == undefined) { style = "bar"; } config.timerStyle = style; if (!nosave) saveConfigToCookie(); } function setTimerColor(color, nosave) { if (color == null || color == undefined) { color = "black"; } config.timerColor = color; changeTimerColor(color); if (!nosave) saveConfigToCookie(); } function setTimerOpacity(opacity, nosave) { if (opacity == null || opacity == undefined) { opacity = 0.25; } config.timerOpacity = opacity; if (!nosave) saveConfigToCookie(); } //key tips function setKeyTips(keyTips, nosave) { config.showKeyTips = keyTips; if (config.showKeyTips) { $("#bottom .keyTips").removeClass("hidden"); } else { $("#bottom .keyTips").addClass("hidden"); } if (!nosave) saveConfigToCookie(); } function toggleKeyTips() { config.showKeyTips = !config.showKeyTips; if (config.showKeyTips) { $("#bottom .keyTips").removeClass("hidden"); } else { $("#bottom .keyTips").addClass("hidden"); } saveConfigToCookie(); } //mode function changeTimeConfig(time, nosave) { time = parseInt(time); changeMode("time", nosave); config.time = time; $("#top .config .time .text-button").removeClass("active"); if (![15, 30, 60, 120].includes(time)) { time = "custom"; } $("#top .config .time .text-button[timeConfig='" + time + "']").addClass( "active" ); if (!nosave) saveConfigToCookie(); } function changeWordCount(wordCount, nosave) { wordCount = parseInt(wordCount); changeMode("words", nosave); config.words = wordCount; $("#top .config .wordCount .text-button").removeClass("active"); if (![10, 25, 50, 100, 200].includes(wordCount)) { wordCount = "custom"; } $( "#top .config .wordCount .text-button[wordCount='" + wordCount + "']" ).addClass("active"); if (!nosave) saveConfigToCookie(); } //caret function setSmoothCaret(mode, nosave) { config.smoothCaret = mode; if (!nosave) saveConfigToCookie(); } function toggleSmoothCaret() { config.smoothCaret = !config.smoothCaret; saveConfigToCookie(); } //quick tab function setQuickTabMode(mode, nosave) { config.quickTab = mode; if (!config.quickTab) { // $(".pageTest").append('