Skip to content

Commit 8593846

Browse files
authored
Merge branch 'master' into dracula
2 parents 91c5c6a + 955986c commit 8593846

24 files changed

Lines changed: 177 additions & 288 deletions

public/css/style.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ key {
645645
margin: 5px 5px;
646646
color: var(--sub-color);
647647
display: flex;
648-
transition: 0.25s;
648+
// transition: 0.25s;
649649
/* margin-bottom: 1px; */
650650
border-bottom: 2px solid transparent;
651651
}
@@ -663,7 +663,7 @@ key {
663663
}
664664

665665
.word.active {
666-
color: var(--active-word-color);
666+
color: var(--sub-color);
667667
}
668668

669669
.word letter {
@@ -795,11 +795,11 @@ key {
795795
width: min-content;
796796
width: -moz-min-content;
797797
}
798-
.themes{
798+
.themes, .languages{
799799
display: grid;
800800
grid-template-columns: 1fr 1fr 1fr 1fr;
801801
// gap: 1rem;
802-
.theme{
802+
.theme, .language{
803803
// padding: 1rem 2rem;
804804
text-align: center;
805805
color: var(--sub-color);

public/index.html

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Monkey Type</title>
88
<link rel="stylesheet" href="css/fa.css">
9-
<link rel="stylesheet" href="themes/dark.css" id="currentTheme">
109
<link rel="stylesheet" href="css/style.css">
10+
<link rel="stylesheet" href="themes/dark.css" id="currentTheme">
1111
<link rel="shortcut icon" href="favicon.png">
1212

1313
</head>
@@ -89,7 +89,7 @@
8989
<div class="group punctuationMode">
9090
<!-- <div class="title">time</div> -->
9191
<div class="buttons">
92-
<div class="button toggleButton active" tabindex="2">punctuation</div>
92+
<div class="button toggleButton" tabindex="2">punctuation</div>
9393
</div>
9494
</div>
9595
<div class="group mode">
@@ -193,11 +193,6 @@ <h1>credits</h1>
193193
<p><a href="https://www.reddit.com/r/MechanicalKeyboards/comments/gc6wx3/experimenting_with_a_completely_new_type_of/">everyone</a> who provided
194194
valuable feedback on the original reddit post for the prototype of this website</p>
195195
</div>
196-
<div class="section">
197-
<h1>support</h1>
198-
<p>If yo are feeling extra awesome and wish to support further development, you can do so <a href="https://www.paypal.me/jackbartnik">here</a>.
199-
200-
</div>
201196
</div>
202197
<div class="page pageSettings hidden">
203198
<div class="tip" style="grid-column: 1/3;">tip: You can also change all these settings quickly using the command line (<key>esc</key>)</div>
@@ -221,16 +216,14 @@ <h1>show key tips</h1>
221216
<div class="text">Shows the keybind tips at the bottom of the page.</div>
222217
<div class="buttons"><div class="button on" tabindex="0">show</div><div class="button off" tabindex="0">hide</div></div>
223218
</div>
219+
<div class="section" style="grid-column: 1/3;">
220+
<h1>languages</h1>
221+
<div class="languages">
222+
</div>
223+
</div>
224224
<div class="section" style="grid-column: 1/3;">
225225
<h1>theme</h1>
226226
<div class="themes">
227-
<div class="theme">light</div>
228-
<div class="theme active">dark</div>
229-
<div class="theme">light</div>
230-
<div class="theme">light</div>
231-
<div class="theme">light</div>
232-
<div class="theme">light</div>
233-
234227
</div>
235228
</div>
236229
</div>
@@ -335,12 +328,11 @@ <h1>theme</h1>
335328
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
336329
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
337330
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline@0.1.3/src/chartjs-plugin-trendline.min.js"></script>
338-
331+
<script src="js/words.js"></script>
339332
<script src="js/db.js"></script>
340333
<script src="js/commandline.js"></script>
341334
<script src="js/settings.js"></script>
342335
<script src="js/userconfig.js"></script>
343-
<script src="js/words.js"></script>
344336
<script src="js/script.js"></script>
345337
<script src="js/account.js"></script>
346338

public/js/account.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ var resultHistoryChart = new Chart($(".pageAccount #resultHistoryChart"), {
289289
}],
290290
yAxes: [{
291291
ticks: {
292-
fontFamily: "Roboto Mono"
292+
fontFamily: "Roboto Mono",
293+
beginAtZero: true
293294
},
294295
display: true,
295296
scaleLabel: {

public/js/commandline.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ let commands = {
5151
showCommandLine();
5252
}
5353
},
54+
{
55+
id: "changeLanguage",
56+
display: "Change language...",
57+
subgroup: true,
58+
exec: () => {
59+
currentCommands = commandsLanguages;
60+
showCommandLine();
61+
}
62+
},
5463
{
5564
id: "changeMode",
5665
display: "Change mode...",
@@ -237,7 +246,7 @@ let themesList;
237246

238247
$.getJSON("themes/list.json", function(data) {
239248
commandsThemes.list = [];
240-
themesList = data;
249+
themesList = data.sort();
241250
data.forEach(theme => {
242251
commandsThemes.list.push({
243252
id: "changeTheme" + capitalizeFirstLetter(theme),
@@ -263,6 +272,31 @@ let commandsThemes = {
263272
]
264273
};
265274

275+
let commandsLanguages = {
276+
title: "Change language...",
277+
list: [
278+
{
279+
id: "couldnotload",
280+
display: "Could not load the languages list :("
281+
}
282+
]
283+
};
284+
285+
if (Object.keys(words).length > 0) {
286+
commandsLanguages.list = [];
287+
Object.keys(words).forEach(language => {
288+
commandsLanguages.list.push({
289+
id: "changeLanguage" + capitalizeFirstLetter(language),
290+
display: language.replace('_', ' '),
291+
exec: () => {
292+
changeLanguage(language);
293+
restartTest();
294+
saveConfigToCookie();
295+
}
296+
})
297+
})
298+
}
299+
266300
$("#commandLine input").keyup((e) => {
267301
if (e.keyCode == 38 || e.keyCode == 40) return;
268302
updateSuggestedCommands();

public/js/script.js

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,28 @@ function initWords() {
7878
inputHistory = [];
7979
currentInput = "";
8080

81+
let language = words[config.language];
82+
83+
if (language == undefined || language == []) {
84+
config.language = "english";
85+
language = words[config.language];
86+
}
87+
8188
if (config.mode == "time" || config.mode == "words") {
8289

8390
let wordsBound = config.mode == "time" ? 50 : config.words;
84-
let randomWord = words[Math.floor(Math.random() * words.length)];
85-
wordsList.push(randomWord);
91+
let randomWord = language[Math.floor(Math.random() * language.length)];
92+
while (randomWord.indexOf(' ') > -1) {
93+
randomWord = language[Math.floor(Math.random() * language.length)];
94+
}
95+
wordsList.push(randomWord.toLowerCase());
8696
for (let i = 1; i < wordsBound; i++) {
87-
randomWord = words[Math.floor(Math.random() * words.length)];
97+
randomWord = language[Math.floor(Math.random() * language.length)];
8898
previousWord = wordsList[i - 1];
89-
while (randomWord == previousWord && (!config.punctuation && "I")) {
90-
randomWord = words[Math.floor(Math.random() * words.length)];
99+
while (randomWord == previousWord || (!config.punctuation && randomWord == "I") || randomWord.indexOf(' ') > -1) {
100+
randomWord = language[Math.floor(Math.random() * language.length)];
91101
}
92-
wordsList.push(randomWord);
102+
wordsList.push(randomWord.toLowerCase());
93103
}
94104

95105
} else if (config.mode == "custom") {
@@ -98,7 +108,7 @@ function initWords() {
98108
wordsList.push(w[i]);
99109
}
100110
}
101-
if (config.punctuation) {
111+
if (config.punctuation && config.mode != "custom") {
102112
wordsList = buildSentences(wordsList);
103113
}
104114
showWords();
@@ -108,13 +118,20 @@ function buildSentences() {
108118
let returnList = [];
109119
$.each(wordsList, (index, word) => {
110120
let previousWord = returnList[index - 1];
111-
if (index == 0 || getLastChar(previousWord) == ".") {
121+
if (index == 0 || getLastChar(previousWord) == "." || getLastChar(previousWord) == "?" || getLastChar(previousWord) == "!") {
112122
//always capitalise the first word or if there was a dot
113123
word = capitalizeFirstLetter(word);
114124
} else if (
115-
//10% chance to add a dot or if its a last word
125+
//10% chance to end a sentence
116126
(Math.random() < 0.1 && getLastChar(previousWord) != "." && index != wordsList.length - 2) || index == wordsList.length - 1) {
117-
word += ".";
127+
let rand = Math.random();
128+
if (rand <= 0.8) {
129+
word += ".";
130+
} else if (rand > .8 && rand < .9){
131+
word += "?";
132+
} else {
133+
word += "!";
134+
}
118135
} else if (Math.random() < 0.01 &&
119136
getLastChar(previousWord) != "," &&
120137
getLastChar(previousWord) != ".") {
@@ -144,7 +161,11 @@ function buildSentences() {
144161
}
145162

146163
function addWord() {
147-
let randomWord = words[Math.floor(Math.random() * words.length)];
164+
let language = words[config.language]
165+
let randomWord = language[Math.floor(Math.random() * language.length)];
166+
while (randomWord.indexOf(' ') > -1) {
167+
randomWord = language[Math.floor(Math.random() * language.length)];
168+
}
148169
wordsList.push(randomWord);
149170
let w = "<div class='word'>";
150171
for (let c = 0; c < randomWord.length; c++) {
@@ -378,7 +399,7 @@ function calculateStats() {
378399
let testNow = Date.now();
379400
let testSeconds = (testNow - testStart) / 1000;
380401
let wpm = Math.round((chars.correctWordChars * (60 / testSeconds)) / 5);
381-
let acc = Math.round((accuracyStats.correct / (accuracyStats.correct + accuracyStats.incorrect)) * 100);
402+
let acc = Math.floor((accuracyStats.correct / (accuracyStats.correct + accuracyStats.incorrect)) * 100);
382403
return { wpm: wpm, acc: acc, correctChars: chars.allCorrectChars, incorrectChars: chars.incorrectChars + chars.extraChars + chars.missedChars };
383404
}
384405

@@ -416,7 +437,8 @@ function showResult() {
416437
mode: config.mode,
417438
mode2: mode2,
418439
punctuation: config.punctuation,
419-
timestamp: Date.now()
440+
timestamp: Date.now(),
441+
language: config.language
420442
};
421443
if (stats.wpm > 0 && stats.wpm < 250 && stats.acc > 50 && stats.acc <= 100) {
422444
if (firebase.auth().currentUser != null) {
@@ -445,15 +467,17 @@ function showResult() {
445467

446468

447469
let infoText = "";
448-
infoText = config.mode;
449470

471+
472+
infoText += config.mode;
450473
if (config.mode == "time") {
451474
infoText += " " + config.time
452475
} else if (config.mode == "words") {
453476
infoText += " " + config.words
454477
}
478+
infoText += "<br>" + config.language.replace('_', ' ') ;
455479
if (config.punctuation) {
456-
infoText += " with punctuation"
480+
infoText += "<br>with punctuation"
457481
}
458482

459483
$("#result .stats .info .bottom").html(infoText);
@@ -829,6 +853,7 @@ $(document).keypress(function(event) {
829853
if (!$("#wordsInput").is(":focus")) return;
830854
if (event["keyCode"] == 13) return;
831855
if (event["keyCode"] == 32) return;
856+
if (event["keyCode"] == 27) return;
832857
//start the test
833858
if (currentInput == "" && inputHistory.length == 0) {
834859
if (firebase.auth().currentUser != null) {
@@ -1030,7 +1055,8 @@ let wpmOverTimeChart = new Chart(ctx, {
10301055
labelString: 'Words per Minute'
10311056
},
10321057
ticks: {
1033-
fontFamily: 'Roboto Mono'
1058+
fontFamily: 'Roboto Mono',
1059+
beginAtZero: true
10341060
}
10351061
}]
10361062
}

public/js/settings.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ function updateSettingsPage(){
22

33
let themesEl = $(".pageSettings .section .themes").empty();
44
themesList.forEach(theme => {
5-
if (config.theme == 'theme') {
6-
themesEl.append(`<div class="theme active" theme='${theme}'>${theme.replace('_', ' ')}</div>`);
7-
} else {
8-
themesEl.append(`<div class="theme" theme='${theme}'>${theme.replace('_', ' ')}</div>`);
9-
}
5+
themesEl.append(`<div class="theme" theme='${theme}'>${theme.replace('_', ' ')}</div>`);
106
})
117

12-
8+
let langEl = $(".pageSettings .section .languages").empty();
9+
Object.keys(words).forEach(language => {
10+
langEl.append(`<div class="language" language='${language}'>${language.replace('_', ' ')}</div>`);
11+
})
1312

1413
setSettingsButton('smoothCaret', config.smoothCaret);
1514
setSettingsButton('quickTab', config.quickTab);
1615
setSettingsButton('liveWpm', config.showLiveWpm);
1716
setSettingsButton('keyTips', config.showKeyTips);
1817

18+
setActiveThemeButton();
19+
setActiveLanguageButton();
20+
1921
if (config.showKeyTips) {
2022
$(".pageSettings .tip").removeClass('hidden');
2123
} else {
@@ -25,6 +27,16 @@ function updateSettingsPage(){
2527

2628
}
2729

30+
function setActiveThemeButton() {
31+
$(`.pageSettings .section .themes .theme`).removeClass('active');
32+
$(`.pageSettings .section .themes .theme[theme=${config.theme}]`).addClass('active');
33+
}
34+
35+
function setActiveLanguageButton() {
36+
$(`.pageSettings .section .languages .language`).removeClass('active');
37+
$(`.pageSettings .section .languages .language[language=${config.language}]`).addClass('active');
38+
}
39+
2840
function setSettingsButton(buttonSection,tf) {
2941
if (tf) {
3042
$(".pageSettings .section."+buttonSection+" .buttons .button.on").addClass('active');
@@ -94,6 +106,7 @@ $(".pageSettings .section.keyTips .buttons .button.off").click(e => {
94106
}
95107
})
96108

109+
//themes
97110
$(document).on("mouseover",".pageSettings .section .themes .theme", (e) => {
98111
let theme = $(e.currentTarget).attr('theme');
99112
previewTheme(theme);
@@ -102,8 +115,17 @@ $(document).on("mouseover",".pageSettings .section .themes .theme", (e) => {
102115
$(document).on("click",".pageSettings .section .themes .theme", (e) => {
103116
let theme = $(e.currentTarget).attr('theme');
104117
setTheme(theme);
118+
setActiveThemeButton();
105119
})
106120

107121
$(document).on("mouseleave",".pageSettings .section .themes", (e) => {
108122
setTheme(config.theme);
123+
})
124+
125+
//languages
126+
$(document).on("click",".pageSettings .section .languages .language", (e) => {
127+
let language = $(e.currentTarget).attr('language');
128+
changeLanguage(language);
129+
restartTest();
130+
setActiveLanguageButton();
109131
})

0 commit comments

Comments
 (0)