mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-09 15:15:58 +08:00
238 lines
6.4 KiB
JavaScript
238 lines
6.4 KiB
JavaScript
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(
|
|
'<i class="fas fa-fw fa-spin fa-circle-notch"></i>'
|
|
);
|
|
$("#top #menu .account").css("opacity", 1).css("pointer-events", "none");
|
|
} else {
|
|
$("#top #menu .account .icon").html('<i class="fas fa-fw fa-user"></i>');
|
|
$("#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(
|
|
`<div class="text-button" function="restartTest()" style="color:var(--error-color);"><i class="fas fa-sync-alt"></i>repeated</div>`
|
|
);
|
|
}
|
|
|
|
if (textHasTab) {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button"><i class="fas fa-long-arrow-alt-right"></i>shift + tab to restart</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.mode === "zen") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button"><i class="fas fa-poll"></i>shift + enter to finish zen </div>`
|
|
);
|
|
}
|
|
|
|
// /^[0-9a-zA-Z_.-]+$/.test(name);
|
|
|
|
if (/_\d+k$/g.test(Config.language) && Config.mode !== "quote") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsLanguages"><i class="fas fa-globe-americas"></i>${Config.language.replace(
|
|
/_/g,
|
|
" "
|
|
)}</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.difficulty === "expert") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsDifficulty"><i class="fas fa-star-half-alt"></i>expert</div>`
|
|
);
|
|
} else if (Config.difficulty === "master") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsDifficulty"><i class="fas fa-star"></i>master</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.blindMode) {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" function="toggleBlindMode()"><i class="fas fa-eye-slash"></i>blind</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.paceCaret !== "off") {
|
|
let speed = "";
|
|
try {
|
|
speed = ` (${Math.round(paceCaret.wpm)} wpm)`;
|
|
} catch {}
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsPaceCaret"><i class="fas fa-tachometer-alt"></i>${
|
|
Config.paceCaret === "average"
|
|
? "average"
|
|
: Config.paceCaret === "pb"
|
|
? "pb"
|
|
: "custom"
|
|
} pace${speed}</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.minWpm !== "off") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsMinWpm"><i class="fas fa-bomb"></i>min ${Config.minWpmCustomSpeed} wpm</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.minAcc !== "off") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsMinAcc"><i class="fas fa-bomb"></i>min ${Config.minAccCustom}% acc</div>`
|
|
);
|
|
}
|
|
|
|
if (activeFunbox !== "none") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsFunbox"><i class="fas fa-gamepad"></i>${activeFunbox.replace(
|
|
/_/g,
|
|
" "
|
|
)}</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.confidenceMode === "on") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsConfidenceMode"><i class="fas fa-backspace"></i>confidence</div>`
|
|
);
|
|
}
|
|
if (Config.confidenceMode === "max") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsConfidenceMode"><i class="fas fa-backspace"></i>max confidence</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.stopOnError != "off") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsStopOnError"><i class="fas fa-hand-paper"></i>stop on ${Config.stopOnError}</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.layout !== "default") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsLayouts"><i class="fas fa-keyboard"></i>${Config.layout}</div>`
|
|
);
|
|
}
|
|
|
|
if (Config.oppositeShiftMode === "on") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsOppositeShiftMode"><i class="fas fa-exchange-alt"></i>opposite shift</div>`
|
|
);
|
|
}
|
|
|
|
let tagsString = "";
|
|
try {
|
|
DB.getSnapshot().tags.forEach((tag) => {
|
|
if (tag.active === true) {
|
|
tagsString += tag.name + ", ";
|
|
}
|
|
});
|
|
|
|
if (tagsString !== "") {
|
|
$(".pageTest #testModesNotice").append(
|
|
`<div class="text-button" commands="commandsTags"><i class="fas fa-tag"></i>${tagsString.substring(
|
|
0,
|
|
tagsString.length - 2
|
|
)}</div>`
|
|
);
|
|
}
|
|
} catch {}
|
|
|
|
if (anim) {
|
|
$(".pageTest #testModesNotice")
|
|
.css("transition", "none")
|
|
.css("opacity", 0)
|
|
.animate(
|
|
{
|
|
opacity: 1,
|
|
},
|
|
125,
|
|
() => {
|
|
$(".pageTest #testModesNotice").css("transition", ".125s");
|
|
}
|
|
);
|
|
}
|
|
}
|