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
|
document.addEventListener('DOMContentLoaded', () => {
let btn = document.querySelector('.modalButton');
btn.click();
});
let counter = 0;
function message(msg, color){
messageBox = document.querySelector(".infoTxt");
messageBox.innerHTML = msg;
messageBox.style.color = color;
}
// Grid event added
function clickEventAdder(){
for (let node of document.querySelectorAll("td")) {
node.addEventListener("click", () => {
if (!node.classList.contains("selected"))
node.classList.add("selected");
let curNode = node;
for (let node of document.querySelectorAll("td")) {
if (node != curNode && node.classList.contains("selected"))
node.classList.remove("selected");
}
// Bring cursor to input
document.querySelector("input").focus();
document.querySelector("input").select();
});
} // outerFor
} // FuncEnd
clickEventAdder();
function getInputValue() {
// Selecting the input element and get its value
let inputVal = document.getElementById("inputId").value;
if (inputVal == "")
message("Palun vali täht.", "red");
else
kontrolliVastus(inputVal.toLowerCase());
}
let koodid = {"a": 25,
"b": 24,
"c": 23,
"d": 22,
"e": 21,
"f": 20,
"g": 19,
"h": 18,
"i": 17,
"j": 16,
"k": 15,
"l": 14,
"m": 13,
"n": 12,
"o": 11,
"p": 10,
"r": 9,
"s": 8,
"t": 7,
"u": 6,
"v": 5,
"õ": 4,
"ä": 3,
"ö": 2,
"ü": 1,
};
function kontrolliVastus(vastus){
let toCheck = document.querySelector(".selected");
if (toCheck.classList.contains("done"))
message("Juba Õige!", "lime");
else if (toCheck.innerHTML == "")
message("Siin on tühik.", "lime");
else if (koodid[vastus] == toCheck.innerHTML){
message("Õige!", "lime");
toCheck.innerHTML = vastus.toUpperCase();
toCheck.classList.add("done");
counter += 1;
if (counter >= 90) {
moveOnEnable();
message("Tubli, kõik valmis<br/>Kogu Sõnum: TORNI RÜNNATI 4.30. VALVAME SIDEKESKUST 22. KORRUSEL. ELEKTER, RAADIOSIDE OLEMAS. LIFTID ÜLEVAL. OLUKORD KRIITILINE.", "lime");
for (let node of document.querySelectorAll("td")) {
if (node.classList.contains("selected"))
node.classList.remove("selected");
}
}
}
else
message("Proovi uuesti.", "red");
}
function enterSubmit(){
document.getElementById('inputId')
.addEventListener('keyup', event => {
if (event.code === 'Enter')
{
event.preventDefault();
getInputValue();
}
});
}
enterSubmit()
// If Done
function moveOnEnable(){
const btn = document.querySelector(".moveOn");
btn.disabled = false;
btn.onclick = () => location.href = "#";
// Proovi btn
const subButton = document.querySelector(".subBtn");
subButton.disabled = true;
}
|