mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-02 11:37:44 +08:00
moved a function to a module, and added temporary variables to make converting other files to modules easier
This commit is contained in:
parent
fd7236246e
commit
d853c38b60
6 changed files with 279 additions and 168 deletions
|
@ -1541,7 +1541,13 @@ function updateCommandsTagsList() {
|
|||
DB.getSnapshot().tags.forEach((tag) => {
|
||||
tag.active = false;
|
||||
});
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
saveActiveTagsToCookie();
|
||||
},
|
||||
});
|
||||
|
@ -1561,7 +1567,13 @@ function updateCommandsTagsList() {
|
|||
sticky: true,
|
||||
exec: () => {
|
||||
toggleTag(tag.id);
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
let txt = tag.name;
|
||||
|
||||
if (tag.active === true) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as DB from "./db";
|
||||
|
||||
export function showBackgroundLoader() {
|
||||
$("#backgroundLoader").stop(true, true).fadeIn(125);
|
||||
}
|
||||
|
@ -77,3 +79,160 @@ export function swapElements(
|
|||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
export function updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
) {
|
||||
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");
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
hideBackgroundLoader,
|
||||
swapElements,
|
||||
accountIconLoading,
|
||||
updateTestModesNotice,
|
||||
} from "./dom-util";
|
||||
import * as Misc from "./misc";
|
||||
import * as CloudFunctions from "./cloud-functions";
|
||||
|
|
183
src/js/script.js
183
src/js/script.js
|
@ -215,7 +215,13 @@ async function activateFunbox(funbox, mode) {
|
|||
settingsGroups.layout.updateButton();
|
||||
}
|
||||
}
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3014,7 +3020,13 @@ function restartTest(withSameWordset = false, nosave = false, event) {
|
|||
clearTimeout(timer);
|
||||
if ($("#commandLineWrapper").hasClass("hidden")) focusWords();
|
||||
ChartController.result.update();
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
pageTransition = false;
|
||||
// console.log(TestStats.incompleteSeconds);
|
||||
// console.log(TestStats.restartCount);
|
||||
|
@ -3140,7 +3152,13 @@ function setMode(mode, nosave) {
|
|||
activeFunBox === "ascii"
|
||||
) {
|
||||
activeFunBox = "none";
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
}
|
||||
$("#top .config .wordCount").addClass("hidden");
|
||||
$("#top .config .time").addClass("hidden");
|
||||
|
@ -3567,157 +3585,6 @@ function hideEditTags() {
|
|||
}
|
||||
}
|
||||
|
||||
function updateTestModesNotice() {
|
||||
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");
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$("#tagsWrapper").click((e) => {
|
||||
if ($(e.target).attr("id") === "tagsWrapper") {
|
||||
hideEditTags();
|
||||
|
@ -4121,7 +3988,13 @@ async function initPaceCaret() {
|
|||
timeout: null,
|
||||
};
|
||||
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
}
|
||||
|
||||
function movePaceCaret(expectedStepEnd) {
|
||||
|
|
|
@ -755,7 +755,13 @@ function toggleTag(tagid, nosave = false) {
|
|||
}
|
||||
}
|
||||
});
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (!nosave) saveActiveTagsToCookie();
|
||||
}
|
||||
|
||||
|
|
|
@ -227,7 +227,13 @@ function setDifficulty(diff, nosave) {
|
|||
}
|
||||
config.difficulty = diff;
|
||||
if (!nosave) restartTest(false, nosave);
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
@ -247,7 +253,13 @@ function toggleBlindMode() {
|
|||
blind = false;
|
||||
}
|
||||
config.blindMode = blind;
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
@ -256,7 +268,13 @@ function setBlindMode(blind, nosave) {
|
|||
blind = false;
|
||||
}
|
||||
config.blindMode = blind;
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
@ -324,7 +342,13 @@ function setStopOnError(soe, nosave) {
|
|||
if (config.stopOnError !== "off") {
|
||||
config.confidenceMode = "off";
|
||||
}
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
@ -401,7 +425,13 @@ function setPaceCaret(val, nosave) {
|
|||
// val = "off";
|
||||
// }
|
||||
config.paceCaret = val;
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
initPaceCaret(nosave);
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
@ -420,7 +450,13 @@ function setMinWpm(minwpm, nosave) {
|
|||
minwpm = "off";
|
||||
}
|
||||
config.minWpm = minwpm;
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
@ -438,7 +474,13 @@ function setMinAcc(min, nosave) {
|
|||
min = "off";
|
||||
}
|
||||
config.minAcc = min;
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
@ -1040,7 +1082,13 @@ function setConfidenceMode(cm, nosave) {
|
|||
config.stopOnError = "off";
|
||||
}
|
||||
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
@ -1298,7 +1346,13 @@ function setLayout(layout, nosave) {
|
|||
layout = "qwerty";
|
||||
}
|
||||
config.layout = layout;
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
if (config.keymapLayout === "overrideSync") {
|
||||
refreshKeymapKeys(config.keymapLayout);
|
||||
}
|
||||
|
@ -1742,5 +1796,11 @@ function applyConfig(configObj) {
|
|||
$("#nitropay_ad_about").remove();
|
||||
}
|
||||
}
|
||||
updateTestModesNotice();
|
||||
updateTestModesNotice(
|
||||
sameWordset,
|
||||
textHasTab,
|
||||
paceCaret,
|
||||
activeFunBox,
|
||||
config
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue