//Функция которая получает keypress
// event.type должен быть keypress
function getChar(event) {
if (event.which == null) { // IE
if (event.keyCode < 32) return null; // спец. символ
return String.fromCharCode(event.keyCode)
}
if (event.which != 0 && event.charCode != 0) { // все кроме IE
if (event.which < 32) return null; // спец. символ
return String.fromCharCode(event.which); // остальные
}
return null; // спец. символ
}
function isCyrillic(text) { //функция, которая проверяет на кириллицу
return /[а-я]/i.test(text);
}
function modalCloseWithEnter () { //закрытие модального окна по нажатию ентер
if (event.keyCode == 13 && event.type == "keydown") {
document.getElementById("wrap").style.display = "none";
document.getElementById("alertWindow").style.display = "none";
document.addEventListener("keypress", checkKeyEvent);
document.removeEventListener("keydown", modalCloseWithEnter);
}
}
function modalClose() { //Закрытие модального окна по клику на кнопку
document.getElementById("wrap").style.display = "none";
document.getElementById("alertWindow").style.display = "none";
document.addEventListener("keypress", checkKeyEvent);
}
var capsLockEnabled;
document.addEventListener('keydown', function(event) {
var caps = event.getModifierState && event.getModifierState('CapsLock');
capsLockEnabled = caps;
});
//Main function. Does everything you want
var counterLetters = 0;
var levelText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur posuere tellus et leo mollis, vel".toLowerCase();
text.innerHTML = levelText;
let mistakesCounter = 0; //Счетчик ошибок
mistakes.innerHTML = ("Кол-во ошибок: " + mistakesCounter);
function checkKeyEvent() {
var keyName = getChar(event);
if (isCyrillic(keyName)) { //вывод сообщения о не правильной раскладке
var modalWindowCaps = document.getElementById("alertWindowText");
modalWindowCaps.innerHTML = ("Неправильная раскладка!");
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.