-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
168 lines (152 loc) · 3.72 KB
/
script.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
var p_word = document.getElementById("word");
var p_roma = document.getElementById("roma");
var checkTexts = [];
var json;
var word_data;
queryGistAsync("cbbbd01c63e4fb3db6da217dedf9db3f", function (gist) {
// gist.files[ファイル名].content にファイルの内容が入ってる
console.log(gist.files["typing-data"].content);
json = gist.files["typing-data"].content;
word_data = JSON.parse(json);
createText();
});
function createText() {
// var rnd = Math.floor(Math.random() * textLists.length);
var rnd = Math.floor(Math.random() * word_data.length);
p_roma.textContent = "";
p_word.textContent = word_data[rnd]["word"];
// checkTexts = textLists[rnd].split('').map(function (value) {
checkTexts = word_data[rnd]["roma"].split('').map(function (value) {
var span = document.createElement("span");
span.textContent = value;
p_roma.appendChild(span);
return span;
});
checkTexts[0].classList.add("input");
var key = checkTexts[0].textContent;
key = eucalyn2qwerty[key];
var div = document.getElementById(key);
if (div != null) {
div.classList.add("next-key");
}
}
document.addEventListener("keydown", keyDown);
document.addEventListener("keyup", keyUp);
function keyDown(e) {
var key = qwerty2eucalyn[e.key];
if (key == checkTexts[0].textContent) {
checkTexts[0].classList.add("done");
if (checkTexts[0].classList.contains("input")) {
checkTexts[0].classList.remove("input");
}
var key = checkTexts[0].textContent;
key = eucalyn2qwerty[key];
var div = document.getElementById(key);
if (div != null && div.classList.contains("next-key")) {
div.classList.remove("next-key");
}
checkTexts.shift();
if (!checkTexts.length) {
createText();
}
else {
checkTexts[0].classList.add("input");
var key = checkTexts[0].textContent;
key = eucalyn2qwerty[key];
var div = document.getElementById(key);
if (div != null) {
div.classList.add("next-key");
}
}
}
var key = e.key;
var div = document.getElementById(key);
if (div != null) {
div.classList.add("key-pressed");
}
}
function keyUp(e) {
var key = e.key;
var div = document.getElementById(key);
if (div != null) {
div.classList.remove("key-pressed");
}
}
function queryGistAsync(gid, callback) {
$.ajax({
type: "GET",
url: "https://api.github.com/gists/" + gid,
dataType: "jsonp",
success: function (json) {callback(json.data);}
});
}
var input_off = function () {
checkTexts[0].classList.remove("input");
}
var input_on = function () {
checkTexts[0].classList.add("input");
setTimeout(input_off, 500);
}
setInterval(input_on, 1000);
var qwerty2eucalyn = {
"q": "q",
"w": "w",
"e": ",",
"r": ".",
"t": ";",
"y": "m",
"u": "r",
"i": "d",
"o": "y",
"p": "p",
"a": "a",
"s": "o",
"d": "e",
"f": "i",
"g": "u",
"h": "g",
"j": "t",
"k": "k",
"l": "s",
";": "n",
"z": "z",
"x": "x",
"c": "c",
"v": "v",
"b": "f",
"n": "b",
"m": "h",
",": "j",
".": "l"
}
var eucalyn2qwerty = {
"q": "q",
"w": "w",
",": "e",
".": "r",
";": "t",
"m": "y",
"r": "u",
"d": "i",
"y": "o",
"p": "p",
"a": "a",
"o": "s",
"e": "d",
"i": "f",
"u": "g",
"g": "h",
"t": "j",
"k": "k",
"s": "l",
"n": ";",
"z": "z",
"x": "x",
"c": "c",
"v": "v",
"f": "b",
"b": "n",
"h": "m",
"j": ",",
"l": "."
}