-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomrade.js
91 lines (85 loc) · 1.56 KB
/
comrade.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var dict = {
// "a": "б",
"b": "ь",
"c": "с",
// "d": "д",
"e": "з",
// "f": "г",
// "g": "g",
"h": "п",
"i": "!",
// "j": "ж",
"k": "к",
"l": "l",
"m": "пп",
"n": "п",
"o": "о",
"p": "р",
"q": "ч",
"r": "г",
// "s": "3",
"t": "т",
"u": "ц",
// "v": "v",
"w": "ш",
"x": "х",
"y": "у",
"z": "и",
// "A": "А",
// "B": "В",
// "C": "С",
"D": "Д",
"E": "З",
"F": "Г",
// "G": "Б",
// "H": "Н",
"I": "1",
// "J": "Г",
// "K": "К",
// "L": "L",
// "M": "М",
"N": "И",
"O": "Ф",
"P": "Р",
"Q": "О",
"R": "Я",
// "S": "S",
// "T": "Т",
"U": "Ц",
// "V": "V",
"W": "Ш",
"X": "Х",
"Y": "У",
// "Z": "Z"
}
var initTextPresent = true;
window.addEventListener("keypress", keyPressHandler, false);
window.addEventListener("keydown", keyDownHandler, false);
window.addEventListener("click", clickHandler, false);
function keyPressHandler(e) {
removeInitText();
let field = document.getElementById("field");
let key = String.fromCharCode(e.keyCode);
if (key in dict) {
key = dict[key];
}
field.value = field.value + key;
}
function keyDownHandler(e) {
removeInitText();
let field = document.getElementById("field");
if (e.keyCode == 8) {
let content = field.value.slice(0, -1);
field.value = content;
}
}
function clickHandler(e) {
removeInitText();
}
function removeInitText() {
let field = document.getElementById("field");
if (initTextPresent) {
field.value = '';
initTextPresent = false;
}
}