-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
167 lines (144 loc) · 5.05 KB
/
Copy pathscript.js
File metadata and controls
167 lines (144 loc) · 5.05 KB
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
if (window.matchMedia('(max-width: 768px)').matches){
while(true)
alert("Mobile alert: Cannot view this application in Mobiles")
}
let sentences = ['ten ate neite ate nee enet ite ate inet ent eate', 'Too ato too nOt enot one totA not anot tOO aNot', 'oat itain oat tain nate eate tea anne inant nean', 'itant eate anot eat nato inate eat anot tain eat', 'nee ene ate ite tent tiet ent ine ene ete ene ate'];
let totalWords=0;
$("div#keyboard-upper-container").hide();
$("#target").hide();
$(document).keydown(function(e){
if (e.shiftKey){
$("div#keyboard-upper-container").show();
$("div#keyboard-lower-container").hide();
}
}
);
$(document).keyup(function(e){
$("div#keyboard-upper-container").hide();
$("div#keyboard-lower-container").show();
$("#keys span ,div#32").css("background-color","inherit");
}
);
$(document).keypress(function(e){
for(i=0;i<$("span").length;i++){
if(e.which==$("span")[i].id){
$("span#"+$("span")[i].id).css("background-color","#f5b5d3f5");
}
else if(e.which=="32"){
$("div#32").css("background-color","#f5b5d3f5")
}
}
});
var x=0;
var y=0;
var totalwrong=0;
var start=null;
var space=false
$(".plays button").click(()=>{
game()
$("#target").show()
$(".content").hide()
$("#words").hide()
});
function game(){
totalWords=0;
for(i=0;i<sentences.length;i++){
totalWords+=sentences[i].split(" ").length
}
space=true
$("div#sentence").empty();
$("div#feedback").empty();
let markedSentence=sentences[x].split("")
markedSentence[0]=`<span id="highlight">${markedSentence[0]}</span>`
$("div#sentence").append(markedSentence.join(""));
$("div#target-letter").empty();
x=0;
y=0;
$("div#target-letter").append(`<kbd>${sentences[x][y]}</kbd>`);
}
function newSentence(x,start){
$("div#sentence").empty();
if(x<sentences.length){
let markedSentence=sentences[x].split("")
markedSentence[0]=`<span id="highlight">${markedSentence[0]}</span>`
$("div#sentence").append(markedSentence.join(""));
}
else{
$("div#target-letter").empty();
let min=(Date.now()-start)/60000;
let letters= (totalWords/min)-(2*totalwrong);
$("div#sentence").empty();
$("div#sentence").append("Ran out of Sentences! <br> Word count per minute: "+letters);
$("div#target-letter").empty();
$("div#target-letter").append("<button>Try again?</button>");
$("div#target-letter button").css({
"background-color":"#f5b5d3f5",
"color":"black",
"border-radius":"10px",
"padding":"10px",
"font-size":"15px",
"border":"none",
"font-family": "'archivoregular', sans-serif"
});
$("div#target-letter button").click(game);
}
$("div#feedback").empty();
}
$(document).keypress(function(e){
if(e.keyCode == 32 && space) {
e.preventDefault();
}
if(x<sentences.length){
if($("div#target-letter button").length==0){
if(start==null)
start = Date.now();
if(e.which==sentences[x][y].charCodeAt(0)){
$("div#feedback").append("✔");
$("div#sentence").text("")
let markedSentence=sentences[x].split("")
markedSentence[y+1]=`<span id="highlight">${markedSentence[y+1]}</span>`
$("div#sentence").append(markedSentence.join(""));
$("div#target-letter").empty();
if(y<sentences[x].length)
if(sentences[x][y+1]==' ')
$("div#target-letter").append("<kbd>space</kbd>");
else{
$("div#target-letter").append(`<kbd>${sentences[x][y+1]}</kbd>`);
}
y++;
}
else{
$("div#feedback").append("✘");
}
if(y==sentences[x].length){
let feedbackContent=$("div#feedback").text();
for(i=0;i<feedbackContent.length;i++){
if(feedbackContent[i]=="✘"){
totalwrong+=1;
}
}
newSentence(++x, start);
y=0;
if(x<sentences.length){
$("div#target-letter").text("");
$("div#target-letter").append(`<kbd>${sentences[x][y]}</kbd>`);
}
else{
totalwrong=0;
start=null;
x=0;
y=0;
}
}
}
}
});
$(".logo").click(()=>{
location.reload()
})
$("#current").click(()=>$("textarea").val(sentences.join(", ")))
$("#confirm").click(()=>{
sentences=$("textarea").val().split(", ")
$("textarea").val("")
start=null;
})