mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
== -> === in a few more files
This commit is contained in:
parent
1e4b93e41c
commit
71793d55be
|
@ -188,7 +188,7 @@ export function setInvalid(): void {
|
|||
export function calculateTestSeconds(now?: number): number {
|
||||
if (now === undefined) {
|
||||
const endAfkSeconds = (end - TestInput.lastKeypress) / 1000;
|
||||
if ((Config.mode == "zen" || TestInput.bailout) && endAfkSeconds < 7) {
|
||||
if ((Config.mode === "zen" || TestInput.bailout) && endAfkSeconds < 7) {
|
||||
return (TestInput.lastKeypress - start) / 1000;
|
||||
} else {
|
||||
return (end - start) / 1000;
|
||||
|
@ -213,11 +213,11 @@ export function calculateWpmAndRaw(): MonkeyTypes.WordsPerMinuteAndRaw {
|
|||
for (let i = 0; i < TestInput.input.history.length; i++) {
|
||||
const word: string = !containsKorean
|
||||
? //english
|
||||
Config.mode == "zen"
|
||||
Config.mode === "zen"
|
||||
? (TestInput.input.getHistory(i) as string)
|
||||
: TestWords.words.get(i)
|
||||
: //korean
|
||||
Config.mode == "zen"
|
||||
Config.mode === "zen"
|
||||
? Hangul.disassemble(TestInput.input.getHistory(i) as string).join("")
|
||||
: Hangul.disassemble(TestWords.words.get(i)).join("");
|
||||
|
||||
|
@ -242,7 +242,7 @@ export function calculateWpmAndRaw(): MonkeyTypes.WordsPerMinuteAndRaw {
|
|||
}
|
||||
if (currTestInput !== "") {
|
||||
const word =
|
||||
Config.mode == "zen"
|
||||
Config.mode === "zen"
|
||||
? currTestInput
|
||||
: !containsKorean
|
||||
? TestWords.words.getCurrent()
|
||||
|
@ -269,7 +269,7 @@ export function calculateWpmAndRaw(): MonkeyTypes.WordsPerMinuteAndRaw {
|
|||
chars += toAdd.correct;
|
||||
chars += toAdd.incorrect;
|
||||
chars += toAdd.missed;
|
||||
if (toAdd.incorrect == 0) {
|
||||
if (toAdd.incorrect === 0) {
|
||||
//word is correct so far, add chars
|
||||
correctWordChars += toAdd.correct;
|
||||
}
|
||||
|
@ -334,13 +334,13 @@ export function calculateBurst(): number {
|
|||
wordLength = !containsKorean
|
||||
? TestInput.input.current.length
|
||||
: Hangul.disassemble(TestInput.input.current).length;
|
||||
if (wordLength == 0) {
|
||||
if (wordLength === 0) {
|
||||
wordLength = !containsKorean
|
||||
? TestInput.input.getHistoryLast()?.length ?? 0
|
||||
: Hangul.disassemble(TestInput.input.getHistoryLast() as string)
|
||||
?.length ?? 0;
|
||||
}
|
||||
if (wordLength == 0) return 0;
|
||||
if (wordLength === 0) return 0;
|
||||
const speed = Misc.roundTo2((wordLength * (60 / timeToWrite)) / 5);
|
||||
return Math.round(speed);
|
||||
}
|
||||
|
@ -373,11 +373,11 @@ function countChars(): CharCount {
|
|||
const containsKorean = TestInput.input.getKoreanStatus();
|
||||
const word: string = !containsKorean
|
||||
? //english
|
||||
Config.mode == "zen"
|
||||
Config.mode === "zen"
|
||||
? (TestInput.input.getHistory(i) as string)
|
||||
: TestWords.words.get(i)
|
||||
: //korean
|
||||
Config.mode == "zen"
|
||||
Config.mode === "zen"
|
||||
? Hangul.disassemble(TestInput.input.getHistory(i) as string).join("")
|
||||
: Hangul.disassemble(TestWords.words.get(i)).join("");
|
||||
|
||||
|
@ -389,7 +389,7 @@ function countChars(): CharCount {
|
|||
? (TestInput.input.getHistory(i) as string)
|
||||
: Hangul.disassemble(TestInput.input.getHistory(i) as string).join("");
|
||||
|
||||
if (historyWord == word) {
|
||||
if (historyWord === word) {
|
||||
//the word is correct
|
||||
correctWordChars += word.length;
|
||||
correctChars += word.length;
|
||||
|
@ -404,7 +404,7 @@ function countChars(): CharCount {
|
|||
for (let c = 0; c < historyWord.length; c++) {
|
||||
if (c < word.length) {
|
||||
//on char that still has a word list pair
|
||||
if (historyWord[c] == word[c]) {
|
||||
if (historyWord[c] === word[c]) {
|
||||
correctChars++;
|
||||
} else {
|
||||
incorrectChars++;
|
||||
|
@ -424,7 +424,7 @@ function countChars(): CharCount {
|
|||
for (let c = 0; c < word.length; c++) {
|
||||
if (c < historyWord.length) {
|
||||
//on char that still has a word list pair
|
||||
if (historyWord[c] == word[c]) {
|
||||
if (historyWord[c] === word[c]) {
|
||||
toAdd.correct++;
|
||||
} else {
|
||||
toAdd.incorrect++;
|
||||
|
@ -436,7 +436,7 @@ function countChars(): CharCount {
|
|||
}
|
||||
correctChars += toAdd.correct;
|
||||
incorrectChars += toAdd.incorrect;
|
||||
if (i === TestInput.input.history.length - 1 && Config.mode == "time") {
|
||||
if (i === TestInput.input.history.length - 1 && Config.mode === "time") {
|
||||
//last word - check if it was all correct - add to correct word chars
|
||||
if (toAdd.incorrect === 0) correctWordChars += toAdd.correct;
|
||||
} else {
|
||||
|
@ -458,7 +458,7 @@ function countChars(): CharCount {
|
|||
correctWordChars: correctWordChars,
|
||||
allCorrectChars: correctChars,
|
||||
incorrectChars:
|
||||
Config.mode == "zen" ? TestInput.accuracy.incorrect : incorrectChars,
|
||||
Config.mode === "zen" ? TestInput.accuracy.incorrect : incorrectChars,
|
||||
extraChars: extraChars,
|
||||
missedChars: missedChars,
|
||||
correctSpaces: correctspaces,
|
||||
|
@ -471,7 +471,7 @@ export function calculateStats(): Stats {
|
|||
console.log("date based time", (end2 - start2) / 1000);
|
||||
console.log("performance.now based time", testSeconds);
|
||||
}
|
||||
if (Config.mode != "custom") {
|
||||
if (Config.mode !== "custom") {
|
||||
testSeconds = Misc.roundTo2(testSeconds);
|
||||
if (wpmCalcDebug) {
|
||||
console.log("mode is not custom - wounding");
|
||||
|
|
|
@ -147,7 +147,7 @@ function checkIfFailed(
|
|||
function checkIfTimeIsUp(): void {
|
||||
if (timerDebug) console.time("times up check");
|
||||
if (
|
||||
Config.mode == "time" ||
|
||||
Config.mode === "time" ||
|
||||
(Config.mode === "custom" && CustomText.isTimeRandom)
|
||||
) {
|
||||
if (
|
||||
|
|
|
@ -108,10 +108,10 @@ export function focusWords(): void {
|
|||
|
||||
export function updateActiveElement(backspace?: boolean): void {
|
||||
const active = document.querySelector("#words .active");
|
||||
if (Config.mode == "zen" && backspace) {
|
||||
if (Config.mode === "zen" && backspace) {
|
||||
active?.remove();
|
||||
} else if (active !== null) {
|
||||
if (Config.highlightMode == "word") {
|
||||
if (Config.highlightMode === "word") {
|
||||
active.querySelectorAll("letter").forEach((e) => {
|
||||
e.classList.remove("correct");
|
||||
});
|
||||
|
@ -125,7 +125,7 @@ export function updateActiveElement(backspace?: boolean): void {
|
|||
activeWord.classList.remove("error");
|
||||
activeWordTop = (<HTMLElement>document.querySelector("#words .active"))
|
||||
.offsetTop;
|
||||
if (Config.highlightMode == "word") {
|
||||
if (Config.highlightMode === "word") {
|
||||
activeWord.querySelectorAll("letter").forEach((e) => {
|
||||
e.classList.add("correct");
|
||||
});
|
||||
|
@ -200,8 +200,8 @@ export function updateWordsHeight(): void {
|
|||
);
|
||||
if (
|
||||
Config.showAllLines &&
|
||||
Config.mode != "time" &&
|
||||
!(CustomText.isWordRandom && CustomText.word == 0) &&
|
||||
Config.mode !== "time" &&
|
||||
!(CustomText.isWordRandom && CustomText.word === 0) &&
|
||||
!CustomText.isTimeRandom
|
||||
) {
|
||||
$("#words")
|
||||
|
@ -457,10 +457,10 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
(f) => f.functions?.getWordHtml
|
||||
);
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const charCorrect = currentWord[i] == input[i];
|
||||
const charCorrect = currentWord[i] === input[i];
|
||||
|
||||
let correctClass = "correct";
|
||||
if (Config.highlightMode == "off") {
|
||||
if (Config.highlightMode === "off") {
|
||||
correctClass = "";
|
||||
}
|
||||
|
||||
|
@ -469,7 +469,7 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
let nlChar = "";
|
||||
if (funbox?.functions?.getWordHtml) {
|
||||
const cl = funbox.functions.getWordHtml(currentLetter);
|
||||
if (cl != "") {
|
||||
if (cl !== "") {
|
||||
currentLetter = cl;
|
||||
}
|
||||
} else if (currentLetter === "\t") {
|
||||
|
@ -482,7 +482,7 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
|
||||
if (charCorrect) {
|
||||
ret += `<letter class="${
|
||||
Config.highlightMode == "word"
|
||||
Config.highlightMode === "word"
|
||||
? wordHighlightClassString
|
||||
: correctClass
|
||||
} ${tabChar}${nlChar}">${currentLetter}</letter>`;
|
||||
|
@ -493,12 +493,12 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
!(containsKorean && !correctSoFar)
|
||||
) {
|
||||
ret += `<letter class="${
|
||||
Config.highlightMode == "word" ? wordHighlightClassString : ""
|
||||
Config.highlightMode === "word" ? wordHighlightClassString : ""
|
||||
} dead">${currentLetter}</letter>`;
|
||||
} else if (!showError) {
|
||||
if (currentLetter !== undefined) {
|
||||
ret += `<letter class="${
|
||||
Config.highlightMode == "word"
|
||||
Config.highlightMode === "word"
|
||||
? wordHighlightClassString
|
||||
: correctClass
|
||||
} ${tabChar}${nlChar}">${currentLetter}</letter>`;
|
||||
|
@ -506,11 +506,11 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
} else if (currentLetter === undefined) {
|
||||
if (!Config.hideExtraLetters) {
|
||||
let letter = input[i];
|
||||
if (letter == " " || letter == "\t" || letter == "\n") {
|
||||
if (/\s/.test(letter)) {
|
||||
letter = "_";
|
||||
}
|
||||
ret += `<letter class="${
|
||||
Config.highlightMode == "word"
|
||||
Config.highlightMode === "word"
|
||||
? wordHighlightClassString
|
||||
: "incorrect"
|
||||
} extra ${tabChar}${nlChar}">${letter}</letter>`;
|
||||
|
@ -518,12 +518,12 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
} else {
|
||||
ret +=
|
||||
`<letter class="${
|
||||
Config.highlightMode == "word"
|
||||
Config.highlightMode === "word"
|
||||
? wordHighlightClassString
|
||||
: "incorrect"
|
||||
} ${tabChar}${nlChar}">` +
|
||||
(Config.indicateTypos === "replace"
|
||||
? input[i] == " "
|
||||
? input[i] === " "
|
||||
? "_"
|
||||
: input[i]
|
||||
: currentLetter) +
|
||||
|
@ -542,7 +542,7 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
} else {
|
||||
ret +=
|
||||
`<letter class="${
|
||||
Config.highlightMode == "word" ? wordHighlightClassString : ""
|
||||
Config.highlightMode === "word" ? wordHighlightClassString : ""
|
||||
}">` +
|
||||
currentWord[i] +
|
||||
"</letter>";
|
||||
|
@ -552,7 +552,7 @@ export function updateWordElement(showError = !Config.blindMode): void {
|
|||
if (Config.highlightMode === "letter" && Config.hideExtraLetters) {
|
||||
if (input.length > currentWord.length && !Config.blindMode) {
|
||||
wordAtIndex.classList.add("error");
|
||||
} else if (input.length == currentWord.length) {
|
||||
} else if (input.length === currentWord.length) {
|
||||
wordAtIndex.classList.remove("error");
|
||||
}
|
||||
}
|
||||
|
@ -765,11 +765,11 @@ async function loadWordsHistory(): Promise<boolean> {
|
|||
incorrect: 0,
|
||||
missed: 0,
|
||||
};
|
||||
const length = Config.mode == "zen" ? input.length : word.length;
|
||||
const length = Config.mode === "zen" ? input.length : word.length;
|
||||
for (let c = 0; c < length; c++) {
|
||||
if (c < input.length) {
|
||||
//on char that still has a word list pair
|
||||
if (Config.mode == "zen" || input[c] == word[c]) {
|
||||
if (Config.mode === "zen" || input[c] === word[c]) {
|
||||
wordstats.correct++;
|
||||
} else {
|
||||
wordstats.incorrect++;
|
||||
|
@ -780,14 +780,14 @@ async function loadWordsHistory(): Promise<boolean> {
|
|||
}
|
||||
}
|
||||
if (wordstats.incorrect !== 0 || Config.mode !== "time") {
|
||||
if (Config.mode != "zen" && input !== word) {
|
||||
if (Config.mode !== "zen" && input !== word) {
|
||||
wordEl = `<div class='word error' burst="${
|
||||
TestInput.burstHistory[i]
|
||||
}" input="${input.replace(/"/g, """).replace(/ /g, "_")}">`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Config.mode != "zen" && input !== word) {
|
||||
if (Config.mode !== "zen" && input !== word) {
|
||||
wordEl = `<div class='word error' burst="${
|
||||
TestInput.burstHistory[i]
|
||||
}" input="${input.replace(/"/g, """).replace(/ /g, "_")}">`;
|
||||
|
@ -795,7 +795,7 @@ async function loadWordsHistory(): Promise<boolean> {
|
|||
}
|
||||
|
||||
let loop;
|
||||
if (Config.mode == "zen" || input.length > word.length) {
|
||||
if (Config.mode === "zen" || input.length > word.length) {
|
||||
//input is longer - extra characters possible (loop over input)
|
||||
loop = input.length;
|
||||
} else {
|
||||
|
@ -822,8 +822,8 @@ async function loadWordsHistory(): Promise<boolean> {
|
|||
) {
|
||||
extraCorrected = "extraCorrected";
|
||||
}
|
||||
if (Config.mode == "zen" || word[c] !== undefined) {
|
||||
if (Config.mode == "zen" || input[c] === word[c]) {
|
||||
if (Config.mode === "zen" || word[c] !== undefined) {
|
||||
if (Config.mode === "zen" || input[c] === word[c]) {
|
||||
if (correctedChar === input[c] || correctedChar === undefined) {
|
||||
wordEl += `<letter class="correct ${extraCorrected}">${input[c]}</letter>`;
|
||||
} else {
|
||||
|
@ -1013,7 +1013,7 @@ $("#saveScreenshotButton").on("keypress", (e) => {
|
|||
$(".pageTest #copyWordsListButton").on("click", async () => {
|
||||
try {
|
||||
let words;
|
||||
if (Config.mode == "zen") {
|
||||
if (Config.mode === "zen") {
|
||||
words = TestInput.input.history.join(" ");
|
||||
} else {
|
||||
words = (<string[]>TestWords.words.get())
|
||||
|
@ -1043,7 +1043,7 @@ $(".pageTest #resultWordsHistory").on("mouseenter", ".words .word", (e) => {
|
|||
if (resultVisible) {
|
||||
const input = $(e.currentTarget).attr("input");
|
||||
const burst = parseInt(<string>$(e.currentTarget).attr("burst"));
|
||||
if (input != undefined) {
|
||||
if (input !== undefined) {
|
||||
$(e.currentTarget).append(
|
||||
`<div class="wordInputAfter">
|
||||
<div class="text">
|
||||
|
|
|
@ -9,8 +9,8 @@ import * as TestState from "./test-state";
|
|||
import * as ConfigEvent from "../observables/config-event";
|
||||
|
||||
export function show(): void {
|
||||
const op = Config.showTimerProgress ? Config.timerOpacity : 0;
|
||||
if (Config.mode != "zen" && Config.timerStyle === "bar") {
|
||||
const op = Config.showTimerProgress ? parseInt(Config.timerOpacity) : 0;
|
||||
if (Config.mode !== "zen" && Config.timerStyle === "bar") {
|
||||
$("#timerWrapper").stop(true, true).removeClass("hidden").animate(
|
||||
{
|
||||
opacity: op,
|
||||
|
@ -28,7 +28,7 @@ export function show(): void {
|
|||
},
|
||||
125
|
||||
);
|
||||
} else if (Config.mode == "zen" || Config.timerStyle === "mini") {
|
||||
} else if (Config.mode === "zen" || Config.timerStyle === "mini") {
|
||||
if (op > 0) {
|
||||
$("#miniTimerAndLiveWpm .time")
|
||||
.stop(true, true)
|
||||
|
@ -186,7 +186,7 @@ export function update(): void {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (Config.mode == "zen") {
|
||||
} else if (Config.mode === "zen") {
|
||||
if (Config.timerStyle === "text") {
|
||||
if (timerNumberElement !== null) {
|
||||
timerNumberElement.innerHTML =
|
||||
|
|
|
@ -56,7 +56,7 @@ function score(word: string): number {
|
|||
numChars++;
|
||||
}
|
||||
}
|
||||
return numChars == 0 ? 0.0 : total / numChars;
|
||||
return numChars === 0 ? 0.0 : total / numChars;
|
||||
}
|
||||
|
||||
export function getWord(wordset: Wordset): string {
|
||||
|
@ -65,7 +65,7 @@ export function getWord(wordset: Wordset): string {
|
|||
for (let i = 0; i < wordSamples; i++) {
|
||||
const newWord = wordset.randomWord("normal");
|
||||
const newScore = score(newWord);
|
||||
if (i == 0 || highScore === undefined || newScore > highScore) {
|
||||
if (i === 0 || highScore === undefined || newScore > highScore) {
|
||||
randomWord = newWord;
|
||||
highScore = newScore;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue