Skip to content

Commit

Permalink
codestyle: some more minor codestyle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ShindouMihou committed Nov 26, 2022
1 parent d1d9de7 commit 52f93a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/lib/word.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export function reduce(content: string): string {
}

return newContents
}

export function diff(a: string, b: string): number {
return a.length > b.length ? a.length - b.length : b.length - a.length;
}
27 changes: 6 additions & 21 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Icon } from '@steeze-ui/svelte-icon'
import { Eye, EyeSlash, ArrowPath, SpeakerWave } from '@steeze-ui/heroicons'
import terminal from '$lib/logging'
import { reduce, hide } from '$lib/word'
import { reduce, hide, diff } from '$lib/word'
let dataset: string[] = []
Expand Down Expand Up @@ -47,13 +47,7 @@
},
15 * 1000
)
let fasterOfflineTimer = setInterval(() => {
if (!navigator.onLine && !offline) {
setOffline()
}
}, 2 * 1000)
let fasterOfflineTimer = setInterval(() => { if (!navigator.onLine && !offline) { setOffline() } }, 2 * 1000)
onDestroy(() => { clearInterval(offlineTimer); clearInterval(fasterOfflineTimer); });
onMount(async () => {
Expand Down Expand Up @@ -148,8 +142,8 @@
if (data != null) {
definition = data.at(0).meanings[0].definitions[0].definition
} else {
definition = "No definition found.";
throw { error: "No definition found, this exception is intentional." }
definition = 'No definition found.';
throw { error: 'No definition found, this exception is intentional.' }
}
})
}
Expand All @@ -161,7 +155,7 @@
speech.text = word
if (definition) {
speech.text = speech.text + ". " + definition + " " + word;
speech.text = speech.text + '. ' + definition + ' ' + word;
}
window.speechSynthesis.speak(speech); terminal.event({ ev: 'pl_au', text: speech.text })
Expand All @@ -178,26 +172,18 @@
document.getElementById('container')?.classList.add('animate-pulse');
try {
// Reset time statistics.
start = -1;
end = -1;
// Reset input.
input = '';
lastInput = '';
hintShown = alwaysShowHint;
// Find a new word and get the definition of it.
let n = random()
if (!offline) {
await define(n);
}
word = n;
// Reset the input field to its original state.
const inputField = document.getElementById('input')
disabled = false;
Expand All @@ -206,7 +192,6 @@
inputField.classList.remove('text-green-500', 'text-red-500')
//@ts-ignore
inputField.value = '';
// Focus on the input field.
inputField.focus()
}
Expand Down Expand Up @@ -247,7 +232,7 @@
start = Date.now(); terminal.event({ ev: 'tme', s: start });
}
let difference = input.length > lastInput.length ? input.length - lastInput.length : lastInput.length - input.length;
let difference = diff(input, lastInput)
if (difference >= 2 && input != '') {
event.preventDefault(); input = lastInput; autoSuggestedDetected = true; terminal.event({ ev: 'ac', diff: difference });
return
Expand Down

0 comments on commit 52f93a2

Please # to comment.