mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-11 16:16:05 +08:00
refactor: reduce indentation, update oxlint rule
This commit is contained in:
parent
5183caf91e
commit
e74ed0e4c1
2 changed files with 76 additions and 61 deletions
|
@ -1259,6 +1259,72 @@ export function setLigatures(isEnabled: boolean): void {
|
|||
}
|
||||
}
|
||||
|
||||
function buildWordLettersHTML(
|
||||
charCount: number,
|
||||
input: string,
|
||||
corrected: string,
|
||||
inputCharacters: string[],
|
||||
wordCharacters: string[],
|
||||
correctedCharacters: string[],
|
||||
containsKorean: boolean
|
||||
): string {
|
||||
let out = "";
|
||||
for (let c = 0; c < charCount; c++) {
|
||||
let correctedChar;
|
||||
try {
|
||||
correctedChar = !containsKorean
|
||||
? correctedCharacters[c]
|
||||
: Hangul.assemble(corrected.split(""))[c];
|
||||
} catch (e) {
|
||||
correctedChar = undefined;
|
||||
}
|
||||
let extraCorrected = "";
|
||||
const historyWord: string = !containsKorean
|
||||
? corrected
|
||||
: Hangul.assemble(corrected.split(""));
|
||||
if (
|
||||
c + 1 === charCount &&
|
||||
historyWord !== undefined &&
|
||||
historyWord.length > input.length
|
||||
) {
|
||||
extraCorrected = "extraCorrected";
|
||||
}
|
||||
if (Config.mode === "zen" || wordCharacters[c] !== undefined) {
|
||||
if (Config.mode === "zen" || inputCharacters[c] === wordCharacters[c]) {
|
||||
if (
|
||||
correctedChar === inputCharacters[c] ||
|
||||
correctedChar === undefined
|
||||
) {
|
||||
out += `<letter class="correct ${extraCorrected}">${inputCharacters[c]}</letter>`;
|
||||
} else {
|
||||
out +=
|
||||
`<letter class="corrected ${extraCorrected}">` +
|
||||
inputCharacters[c] +
|
||||
"</letter>";
|
||||
}
|
||||
} else {
|
||||
if (inputCharacters[c] === TestInput.input.current) {
|
||||
out +=
|
||||
`<letter class='correct ${extraCorrected}'>` +
|
||||
wordCharacters[c] +
|
||||
"</letter>";
|
||||
} else if (inputCharacters[c] === undefined) {
|
||||
out += "<letter>" + wordCharacters[c] + "</letter>";
|
||||
} else {
|
||||
out +=
|
||||
`<letter class="incorrect ${extraCorrected}">` +
|
||||
wordCharacters[c] +
|
||||
"</letter>";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out +=
|
||||
'<letter class="incorrect extra">' + inputCharacters[c] + "</letter>";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
async function loadWordsHistory(): Promise<boolean> {
|
||||
$("#resultWordsHistory .words").empty();
|
||||
let wordsHTML = "";
|
||||
|
@ -1312,64 +1378,15 @@ async function loadWordsHistory(): Promise<boolean> {
|
|||
|
||||
if (corrected === undefined) throw new Error("empty corrected word");
|
||||
|
||||
for (let c = 0; c < loop; c++) {
|
||||
let correctedChar;
|
||||
try {
|
||||
correctedChar = !containsKorean
|
||||
? correctedCharacters[c]
|
||||
: Hangul.assemble(corrected.split(""))[c];
|
||||
} catch (e) {
|
||||
correctedChar = undefined;
|
||||
}
|
||||
let extraCorrected = "";
|
||||
const historyWord: string = !containsKorean
|
||||
? corrected
|
||||
: Hangul.assemble(corrected.split(""));
|
||||
if (
|
||||
c + 1 === loop &&
|
||||
historyWord !== undefined &&
|
||||
historyWord.length > input.length
|
||||
) {
|
||||
extraCorrected = "extraCorrected";
|
||||
}
|
||||
if (Config.mode === "zen" || wordCharacters[c] !== undefined) {
|
||||
if (
|
||||
Config.mode === "zen" ||
|
||||
inputCharacters[c] === wordCharacters[c]
|
||||
) {
|
||||
if (
|
||||
correctedChar === inputCharacters[c] ||
|
||||
correctedChar === undefined
|
||||
) {
|
||||
wordEl += `<letter class="correct ${extraCorrected}">${inputCharacters[c]}</letter>`;
|
||||
} else {
|
||||
wordEl +=
|
||||
`<letter class="corrected ${extraCorrected}">` +
|
||||
inputCharacters[c] +
|
||||
"</letter>";
|
||||
}
|
||||
} else {
|
||||
if (inputCharacters[c] === TestInput.input.current) {
|
||||
wordEl +=
|
||||
`<letter class='correct ${extraCorrected}'>` +
|
||||
wordCharacters[c] +
|
||||
"</letter>";
|
||||
} else if (inputCharacters[c] === undefined) {
|
||||
wordEl += "<letter>" + wordCharacters[c] + "</letter>";
|
||||
} else {
|
||||
wordEl +=
|
||||
`<letter class="incorrect ${extraCorrected}">` +
|
||||
wordCharacters[c] +
|
||||
"</letter>";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wordEl +=
|
||||
'<letter class="incorrect extra">' +
|
||||
inputCharacters[c] +
|
||||
"</letter>";
|
||||
}
|
||||
}
|
||||
wordEl += buildWordLettersHTML(
|
||||
loop,
|
||||
input,
|
||||
corrected,
|
||||
inputCharacters,
|
||||
wordCharacters,
|
||||
correctedCharacters,
|
||||
containsKorean
|
||||
);
|
||||
wordEl += "</div>";
|
||||
} catch (e) {
|
||||
try {
|
||||
|
|
|
@ -79,12 +79,10 @@
|
|||
"eqeqeq": "error",
|
||||
"ban-ts-comment": "error",
|
||||
"no-unassigned-vars": "error",
|
||||
|
||||
"todo-lowerthis": "off",
|
||||
"max-depth": [
|
||||
"error",
|
||||
{
|
||||
"max": 6
|
||||
"max": 5
|
||||
}
|
||||
],
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue