import * as DB from "./db"; import Config from "./config"; export function showBackgroundLoader() { $("#backgroundLoader").stop(true, true).fadeIn(125); } export function hideBackgroundLoader() { $("#backgroundLoader").stop(true, true).fadeOut(125); } export function accountIconLoading(truefalse) { if (truefalse) { $("#top #menu .account .icon").html( '' ); $("#top #menu .account").css("opacity", 1).css("pointer-events", "none"); } else { $("#top #menu .account .icon").html(''); $("#top #menu .account").css("opacity", 1).css("pointer-events", "auto"); } } export function swapElements( el1, el2, totalDuration, callback = function () { return; } ) { if ( (el1.hasClass("hidden") && !el2.hasClass("hidden")) || (!el1.hasClass("hidden") && el2.hasClass("hidden")) ) { //one of them is hidden and the other is visible if (el1.hasClass("hidden")) { callback(); return false; } $(el1) .removeClass("hidden") .css("opacity", 1) .animate( { opacity: 0, }, totalDuration / 2, () => { $(el1).addClass("hidden"); $(el2) .removeClass("hidden") .css("opacity", 0) .animate( { opacity: 1, }, totalDuration / 2, () => { callback(); } ); } ); } else if (el1.hasClass("hidden") && el2.hasClass("hidden")) { //both are hidden, only fade in the second $(el2) .removeClass("hidden") .css("opacity", 0) .animate( { opacity: 1, }, totalDuration, () => { callback(); } ); } else { callback(); } } export function updateTestModesNotice( sameWordset, textHasTab, paceCaret, activeFunbox ) { let anim = false; if ($(".pageTest #testModesNotice").text() === "") anim = true; $(".pageTest #testModesNotice").empty(); if (sameWordset) { $(".pageTest #testModesNotice").append( `
repeated
` ); } if (textHasTab) { $(".pageTest #testModesNotice").append( `
shift + tab to restart
` ); } if (Config.mode === "zen") { $(".pageTest #testModesNotice").append( `
shift + enter to finish zen
` ); } // /^[0-9a-zA-Z_.-]+$/.test(name); if (/_\d+k$/g.test(Config.language) && Config.mode !== "quote") { $(".pageTest #testModesNotice").append( `
${Config.language.replace( /_/g, " " )}
` ); } if (Config.difficulty === "expert") { $(".pageTest #testModesNotice").append( `
expert
` ); } else if (Config.difficulty === "master") { $(".pageTest #testModesNotice").append( `
master
` ); } if (Config.blindMode) { $(".pageTest #testModesNotice").append( `
blind
` ); } if (Config.paceCaret !== "off") { let speed = ""; try { speed = ` (${Math.round(paceCaret.wpm)} wpm)`; } catch {} $(".pageTest #testModesNotice").append( `
${ Config.paceCaret === "average" ? "average" : Config.paceCaret === "pb" ? "pb" : "custom" } pace${speed}
` ); } if (Config.minWpm !== "off") { $(".pageTest #testModesNotice").append( `
min ${Config.minWpmCustomSpeed} wpm
` ); } if (Config.minAcc !== "off") { $(".pageTest #testModesNotice").append( `
min ${Config.minAccCustom}% acc
` ); } if (activeFunbox !== "none") { $(".pageTest #testModesNotice").append( `
${activeFunbox.replace( /_/g, " " )}
` ); } if (Config.confidenceMode === "on") { $(".pageTest #testModesNotice").append( `
confidence
` ); } if (Config.confidenceMode === "max") { $(".pageTest #testModesNotice").append( `
max confidence
` ); } if (Config.stopOnError != "off") { $(".pageTest #testModesNotice").append( `
stop on ${Config.stopOnError}
` ); } if (Config.layout !== "default") { $(".pageTest #testModesNotice").append( `
${Config.layout}
` ); } if (Config.oppositeShiftMode === "on") { $(".pageTest #testModesNotice").append( `
opposite shift
` ); } let tagsString = ""; try { DB.getSnapshot().tags.forEach((tag) => { if (tag.active === true) { tagsString += tag.name + ", "; } }); if (tagsString !== "") { $(".pageTest #testModesNotice").append( `
${tagsString.substring( 0, tagsString.length - 2 )}
` ); } } catch {} if (anim) { $(".pageTest #testModesNotice") .css("transition", "none") .css("opacity", 0) .animate( { opacity: 1, }, 125, () => { $(".pageTest #testModesNotice").css("transition", ".125s"); } ); } }